Skip to content

Commit 1415d0b

Browse files
committed
Adding test
1 parent f9827dd commit 1415d0b

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

tests/test_e2e.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ def _get_app_and_auth_code(
2525
client_id, client_secret, authority=authority, http_client=MinimalHttpClient())
2626
redirect_uri = "http://localhost:%d" % port
2727
ac = obtain_auth_code(port, auth_uri=app.get_authorization_request_url(
28-
scopes, redirect_uri=redirect_uri, **kwargs),
29-
text="Open this link to sign in. You may use incognito window")
28+
scopes, redirect_uri=redirect_uri, **kwargs),
29+
text="Open this link to sign in. You may use incognito window")
3030
assert ac is not None
3131
return (app, ac, redirect_uri)
3232

@@ -400,6 +400,27 @@ def _test_acquire_token_by_auth_code(
400400
error_description=result.get("error_description")))
401401
self.assertCacheWorksForUser(result, scope, username=None)
402402

403+
def _test_acquire_token_interactive(
404+
self, client_id=None, authority=None, scope=None,
405+
**ignored):
406+
assert client_id and authority and scope
407+
self.app = msal.ClientApplication(
408+
client_id, authority=authority, http_client=MinimalHttpClient())
409+
result = self.app.acquire_token_interactive(scope)
410+
logger.debug(
411+
"%s: cache = %s, id_token_claims = %s",
412+
self.id(),
413+
json.dumps(self.app.token_cache._cache, indent=4),
414+
json.dumps(result.get("id_token_claims"), indent=4),
415+
)
416+
self.assertIn(
417+
"access_token", result,
418+
"{error}: {error_description}".format(
419+
# Note: No interpolation here, cause error won't always present
420+
error=result.get("error"),
421+
error_description=result.get("error_description")))
422+
self.assertCacheWorksForUser(result, scope, username=None)
423+
403424
def _test_acquire_token_obo(self, config_pca, config_cca):
404425
# 1. An app obtains a token representing a user, for our mid-tier service
405426
pca = msal.PublicClientApplication(
@@ -558,6 +579,17 @@ def test_b2c_acquire_token_by_ropc(self):
558579
scope=config["defaultScopes"].split(','),
559580
)
560581

582+
@unittest.skipIf(os.getenv("TRAVIS"), "Browser automation is not yet implemented")
583+
def test_acquire_token_interactive(self):
584+
"""When prompted, you can manually login using this account:
585+
586+
# https://msidlab.com/api/user?usertype=cloud
587+
username = "..." # The upn from the link above
588+
password="***" # From https://aka.ms/GetLabUserSecret?Secret=msidlabXYZ
589+
"""
590+
config = self.get_lab_user(usertype="cloud")
591+
self._test_acquire_token_interactive(**config)
592+
561593

562594
class ArlingtonCloudTestCase(LabBasedTestCase):
563595
environment = "azureusgovernment"

0 commit comments

Comments
 (0)