Skip to content

Commit 094ce75

Browse files
committed
Refactor to reuse CIAM test cases for CIAM CUD
1 parent c6595d3 commit 094ce75

File tree

1 file changed

+42
-13
lines changed

1 file changed

+42
-13
lines changed

tests/test_e2e.py

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ def _build_app(cls,
172172
client_id,
173173
client_credential=None,
174174
authority="https://login.microsoftonline.com/common",
175+
oidc_authority=None,
175176
scopes=["https://graph.microsoft.com/.default"], # Microsoft Graph
176177
http_client=None,
177178
azure_region=None,
@@ -181,6 +182,7 @@ def _build_app(cls,
181182
client_id,
182183
client_credential=client_credential,
183184
authority=authority,
185+
oidc_authority=oidc_authority,
184186
azure_region=azure_region,
185187
http_client=http_client or MinimalHttpClient(),
186188
)
@@ -194,21 +196,24 @@ def _build_app(cls,
194196
return msal.PublicClientApplication(
195197
client_id,
196198
authority=authority,
199+
oidc_authority=oidc_authority,
197200
http_client=http_client or MinimalHttpClient(),
198201
enable_broker_on_windows=broker_available,
199202
enable_broker_on_mac=broker_available,
200203
)
201204

202205
def _test_username_password(self,
203206
authority=None, client_id=None, username=None, password=None, scope=None,
207+
oidc_authority=None,
204208
client_secret=None, # Since MSAL 1.11, confidential client has ROPC too
205209
azure_region=None,
206210
http_client=None,
207211
auth_scheme=None,
208212
**ignored):
209-
assert authority and client_id and username and password and scope
213+
assert client_id and username and password and scope and (
214+
authority or oidc_authority)
210215
self.app = self._build_app(
211-
client_id, authority=authority,
216+
client_id, authority=authority, oidc_authority=oidc_authority,
212217
http_client=http_client,
213218
azure_region=azure_region, # Regional endpoint does not support ROPC.
214219
# Here we just use it to test a regional app won't break ROPC.
@@ -229,9 +234,14 @@ def _test_username_password(self,
229234
os.getenv("TRAVIS"), # It is set when running on TravisCI or Github Actions
230235
"Although it is doable, we still choose to skip device flow to save time")
231236
def _test_device_flow(
232-
self, client_id=None, authority=None, scope=None, **ignored):
233-
assert client_id and authority and scope
234-
self.app = self._build_app(client_id, authority=authority)
237+
self,
238+
*,
239+
client_id=None, authority=None, oidc_authority=None, scope=None,
240+
**ignored
241+
):
242+
assert client_id and scope and (authority or oidc_authority)
243+
self.app = self._build_app(
244+
client_id, authority=authority, oidc_authority=oidc_authority)
235245
flow = self.app.initiate_device_flow(scopes=scope)
236246
assert "user_code" in flow, "DF does not seem to be provisioned: %s".format(
237247
json.dumps(flow, indent=4))
@@ -255,16 +265,18 @@ def _test_device_flow(
255265

256266
@unittest.skipIf(os.getenv("TRAVIS"), "Browser automation is not yet implemented")
257267
def _test_acquire_token_interactive(
258-
self, client_id=None, authority=None, scope=None, port=None,
268+
self, *, client_id=None, authority=None, scope=None, port=None,
269+
oidc_authority=None,
259270
username=None, lab_name=None,
260271
username_uri="", # Unnecessary if you provided username and lab_name
261272
data=None, # Needed by ssh-cert feature
262273
prompt=None,
263274
enable_msa_passthrough=None,
264275
auth_scheme=None,
265276
**ignored):
266-
assert client_id and authority and scope
267-
self.app = self._build_app(client_id, authority=authority)
277+
assert client_id and scope and (authority or oidc_authority)
278+
self.app = self._build_app(
279+
client_id, authority=authority, oidc_authority=oidc_authority)
268280
logger.info(_get_hint( # Useful when testing broker which shows no welcome_template
269281
username=username, lab_name=lab_name, username_uri=username_uri))
270282
result = self.app.acquire_token_interactive(
@@ -682,10 +694,13 @@ def _test_acquire_token_obo(self, config_pca, config_cca,
682694

683695
def _test_acquire_token_by_client_secret(
684696
self, client_id=None, client_secret=None, authority=None, scope=None,
697+
oidc_authority=None,
685698
**ignored):
686-
assert client_id and client_secret and authority and scope
699+
assert client_id and client_secret and scope and (
700+
authority or oidc_authority)
687701
self.app = msal.ConfidentialClientApplication(
688702
client_id, client_credential=client_secret, authority=authority,
703+
oidc_authority=oidc_authority,
689704
http_client=MinimalHttpClient())
690705
result = self.app.acquire_token_for_client(scope)
691706
self.assertIsNotNone(result.get("access_token"), "Got %s instead" % result)
@@ -1016,7 +1031,8 @@ def setUpClass(cls):
10161031

10171032
def test_ciam_acquire_token_interactive(self):
10181033
self._test_acquire_token_interactive(
1019-
authority=self.app_config["authority"],
1034+
authority=self.app_config.get("authority"),
1035+
oidc_authority=self.app_config.get("oidc_authority"),
10201036
client_id=self.app_config["appId"],
10211037
scope=self.app_config["scopes"],
10221038
username=self.user["username"],
@@ -1034,7 +1050,8 @@ def test_ciam_acquire_token_for_client(self):
10341050
self._test_acquire_token_by_client_secret(
10351051
client_id=self.app_config["appId"],
10361052
client_secret=self.get_lab_user_secret(secret_name),
1037-
authority=self.app_config["authority"],
1053+
authority=self.app_config.get("authority"),
1054+
oidc_authority=self.app_config.get("oidc_authority"),
10381055
scope=self.app_config["scopes"], # It shall ends with "/.default"
10391056
)
10401057

@@ -1047,7 +1064,8 @@ def test_ciam_acquire_token_by_ropc(self):
10471064
# and enabling "Allow public client flows".
10481065
# Otherwise it would hit AADSTS7000218.
10491066
self._test_username_password(
1050-
authority=self.app_config["authority"],
1067+
authority=self.app_config.get("authority"),
1068+
oidc_authority=self.app_config.get("oidc_authority"),
10511069
client_id=self.app_config["appId"],
10521070
username=self.user["username"],
10531071
password=self.get_lab_user_secret(self.user["lab_name"]),
@@ -1058,12 +1076,23 @@ def test_ciam_acquire_token_by_ropc(self):
10581076
AADSTS500208: The domain is not a valid login domain for the account type.""")
10591077
def test_ciam_device_flow(self):
10601078
self._test_device_flow(
1061-
authority=self.app_config["authority"],
1079+
authority=self.app_config.get("authority"),
1080+
oidc_authority=self.app_config.get("oidc_authority"),
10621081
client_id=self.app_config["appId"],
10631082
scope=self.app_config["scopes"],
10641083
)
10651084

10661085

1086+
class CiamCudTestCase(CiamTestCase):
1087+
@classmethod
1088+
def setUpClass(cls):
1089+
super(CiamCudTestCase, cls).setUpClass()
1090+
cls.app_config["authority"] = None
1091+
cls.app_config["oidc_authority"] = (
1092+
# Derived from https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/blob/4.63.0/tests/Microsoft.Identity.Test.Integration.netcore/HeadlessTests/CiamIntegrationTests.cs#L156
1093+
"https://login.msidlabsciam.com/fe362aec-5d43-45d1-b730-9755e60dc3b9/v2.0")
1094+
1095+
10671096
class WorldWideRegionalEndpointTestCase(LabBasedTestCase):
10681097
region = "westus"
10691098
timeout = 2 # Short timeout makes this test case responsive on non-VM

0 commit comments

Comments
 (0)