Skip to content

Commit e602c09

Browse files
committed
Update ROPC broker tests
1 parent 12566ba commit e602c09

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

tests/broker-test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ def interactive_and_silent(scopes, auth_scheme, data, expected_token_type):
4646
)
4747
_assert(result, expected_token_type)
4848

49+
def test_broker_username_password(scopes, expected_token_type):
50+
pass
51+
print("Testing broker username password flows by using labs account: '[email protected]', please provide the password.")
52+
username = "[email protected]"
53+
password = input("Password:")
54+
result = pca.acquire_token_by_username_password(username, password, scopes)
55+
_assert(result, expected_token_type)
56+
assert(result.get("token_source") == "broker")
57+
print("Username password test succeeds.")
58+
4959
def _assert(result, expected_token_type):
5060
assert result.get("access_token"), f"We should obtain a token. Got {result} instead."
5161
assert result.get("token_source") == "broker", "Token should be obtained via broker"
@@ -64,3 +74,4 @@ def _assert(result, expected_token_type):
6474
expected_token_type="ssh-cert",
6575
)
6676

77+
test_broker_username_password(scopes=[SCOPE_ARM], expected_token_type="bearer")

tests/test_account_source.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,19 @@ def test_device_flow_and_its_silent_call_should_bypass_broker(self, _, mocked_br
4646
mocked_broker_ats.assert_not_called()
4747
self.assertEqual(result["token_source"], "identity_provider")
4848

49-
def test_ropc_flow_and_its_silent_call_should_bypass_broker(self, _, mocked_broker_ats):
49+
def test_ropc_flow_and_its_silent_call_should_invoke_broker(self, _, mocked_broker_ats):
5050
app = msal.PublicClientApplication("client_id", enable_broker_on_windows=True)
51-
with patch.object(app.authority, "user_realm_discovery", return_value={}):
51+
with patch("msal.broker._signin_silently", return_value=dict(TOKEN_RESPONSE, _account_id="placeholder")):
5252
result = app.acquire_token_by_username_password(
5353
"username", "placeholder", [SCOPE], post=_mock_post)
54-
self.assertEqual(result["token_source"], "identity_provider")
54+
self.assertEqual(result["token_source"], "broker")
5555

5656
account = app.get_accounts()[0]
57-
self.assertEqual(account["account_source"], "password")
57+
self.assertEqual(account["account_source"], "broker")
5858

5959
result = app.acquire_token_silent_with_error(
6060
[SCOPE], account, force_refresh=True, post=_mock_post)
61-
mocked_broker_ats.assert_not_called()
62-
self.assertEqual(result["token_source"], "identity_provider")
61+
self.assertEqual(result["token_source"], "broker")
6362

6463
def test_interactive_flow_and_its_silent_call_should_invoke_broker(self, _, mocked_broker_ats):
6564
app = msal.PublicClientApplication("client_id", enable_broker_on_windows=True)

0 commit comments

Comments
 (0)