Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
PR review changes
  • Loading branch information
abhidnya13 committed Apr 7, 2020
commit f29954b39da4ddd34b73f2fe5843e4c12939fc69
37 changes: 20 additions & 17 deletions tests/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def _test_username_password(self,
username=username if ".b2clogin.com" not in authority else None,
)

def _test_device_code(
def _test_device_flow(
self, client_id=None, authority=None, scope=None, **ignored):
assert client_id and authority and scope
self.app = msal.PublicClientApplication(
Expand Down Expand Up @@ -270,7 +270,7 @@ def setUpClass(cls):
cls.config = json.load(f)

def test_device_flow(self):
self._test_device_code(**self.config)
self._test_device_flow(**self.config)


def get_lab_app(
Expand Down Expand Up @@ -327,7 +327,7 @@ def tearDownClass(cls):
cls.session.close()

@classmethod
def get_lab_app_object(cls, **query): # https://msidlab.com/swagger/index.html
def get_lab_app_object(cls, **query): # https://msidlab.com/swagger/index.html
url = "https://msidlab.com/api/app"
resp = cls.session.get(url, params=query)
return resp.json()[0]
Expand All @@ -349,10 +349,10 @@ def get_lab_user(cls, **query): # https://docs.msidlab.com/labapi/userapi.html
_env = query.get("azureenvironment", "").lower()
authority_base = {
"azureusgovernment": "https://login.microsoftonline.us/"
}.get(_env, "https://login.microsoftonline.com/")
}.get(_env, "https://login.microsoftonline.com/")
scope = {
"azureusgovernment": ["https://graph.microsoft.us/.default"],
}.get(_env, ["https://graph.microsoft.com/.default"])
}.get(_env, ["https://graph.microsoft.com/.default"])
return { # Mapping lab API response to our simplified configuration format
"authority": authority_base + result["tenantID"],
"client_id": result["appId"],
Expand All @@ -366,7 +366,7 @@ def _test_acquire_token_by_auth_code(
**ignored):
assert client_id and authority and port and scope
(self.app, ac, redirect_uri) = _get_app_and_auth_code(
client_id, authority, port, scope)
client_id, authority=authority, port=port, scopes=scope)
result = self.app.acquire_token_by_authorization_code(
ac, scope, redirect_uri=redirect_uri)
logger.debug(
Expand Down Expand Up @@ -516,17 +516,20 @@ def test_b2c_acquire_token_by_auth_code(self):
# This won't work https://msidlab.com/api/user?usertype=b2c
password="***" # From https://aka.ms/GetLabUserSecret?Secret=msidlabb2c
"""
config = {"authority": self._build_b2c_authority("B2C_1_SignInPolicy"),
"client_id": "b876a048-55a5-4fc5-9403-f5d90cb1c852",
"scope": ["https://msidlabb2c.onmicrosoft.com/msaapp/user_impersonation"], "port": 3843}
self._test_acquire_token_by_auth_code(**config)
self._test_acquire_token_by_auth_code(
authority=self._build_b2c_authority("B2C_1_SignInPolicy"),
client_id="b876a048-55a5-4fc5-9403-f5d90cb1c852", port=3843,
scope=["https://msidlabb2c.onmicrosoft.com/msaapp/user_impersonation"]
)

def test_b2c_acquire_token_by_ropc(self):
config = {"authority": self._build_b2c_authority("B2C_1_ROPC_Auth"),
"client_id": "e3b9ad76-9763-4827-b088-80c7a7888f79",
"username": "[email protected]", "password": self.get_lab_user_secret("msidlabb2c"),
"scope": ["https://msidlabb2c.onmicrosoft.com/msidlabb2capi/read"]}
self._test_username_password(**config)
self._test_username_password(
authority=self._build_b2c_authority("B2C_1_ROPC_Auth"),
client_id="e3b9ad76-9763-4827-b088-80c7a7888f79",
username="[email protected]",
password=self.get_lab_user_secret("msidlabb2c"),
scope=["https://msidlabb2c.onmicrosoft.com/msidlabb2capi/read"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
scope=["https://msidlabb2c.onmicrosoft.com/msidlabb2capi/read"]
scope=["https://msidlabb2c.onmicrosoft.com/msidlabb2capi/read"],

Reasoning: PEP 8 on Trailing commas


PS: It is not necessarily that I paid attention to this kind of details. It is the github PR review UI highlighting the different lines in red-and-green in order to grab reviewer's attention. So, a universal hint for a PR author is to conduct a self-review on github PR UI to see whether each of those red-and-green snippets is intended and/or necessary.

)


class ArlingtonCloudTestCase(LabBasedTestCase):
Expand Down Expand Up @@ -556,10 +559,10 @@ def test_arlington_acquire_token_obo(self):

self._test_acquire_token_obo(config_pca, config_cca)

def test_arlington_acquire_token_device_code(self):
def test_arlington_acquire_token_device_flow(self):
config = self.get_lab_user(usertype="cloud", azureenvironment=self.environment, publicClient="yes")
config["scope"] = ["user.read"]
self._test_device_code(**config)
self._test_device_flow(**config)


if __name__ == "__main__":
Expand Down