Skip to content

Commit 6cae429

Browse files
committed
reenable tests
1 parent d79cba1 commit 6cae429

File tree

7 files changed

+9
-13
lines changed

7 files changed

+9
-13
lines changed

msal/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,11 @@ def _acquire_token_interactive(app, scopes=None, data=None):
150150

151151
def _acquire_token_by_username_password(app):
152152
"""
153-
[Deprecated] This API is deprecated and will be removed in a future release. Use a more secure flow instead.
153+
[Deprecated] This API is deprecated for PublicClientApplication(PCA) flows and will be removed in a future release. Use a more secure flow instead.
154154
Migration guide: https://aka.ms/msal-ropc-migration
155155
156156
acquire_token_by_username_password() - See constraints here: https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-authentication-flows#constraints-for-ropc
157157
"""
158-
warnings.warn("This API has been deprecated, please use a more secure flow. See https://aka.ms/msal-ropc-migration for migration guidance", DeprecationWarning)
159158
print_json(app.acquire_token_by_username_password(
160159
_input("username: "), getpass.getpass("password: "), scopes=_input_scopes()))
161160

@@ -328,6 +327,7 @@ def _main():
328327
_acquire_pop_token_interactive,
329328
] if isinstance(app, msal.PublicClientApplication) else []
330329
) + [
330+
_acquire_token_by_username_password,
331331
_remove_account,
332332
] + ([
333333
_acquire_token_for_client,

msal/application.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,7 +1816,7 @@ def acquire_token_by_username_password(
18161816
auth_scheme=None,
18171817
**kwargs):
18181818
"""
1819-
[Deprecated] This API is deprecated and will be removed in a future release. Use a more secure flow instead.
1819+
[Deprecated] This API is deprecated for PublicClientApplication(PCA) flows and will be removed in a future release. Use a more secure flow instead.
18201820
Migration guide: https://aka.ms/msal-ropc-migration
18211821
18221822
Gets a token for a given resource via user credentials.
@@ -1845,7 +1845,11 @@ def acquire_token_by_username_password(
18451845
- A successful response would contain "access_token" key,
18461846
- an error response would contain "error" and usually "error_description".
18471847
"""
1848-
warnings.warn("This API has been deprecated, please use a more secure flow. See https://aka.ms/msal-ropc-migration for migration guidance", DeprecationWarning)
1848+
is_confidential_app = self.client_credential or isinstance(
1849+
self, ConfidentialClientApplication)
1850+
if not is_confidential_app:
1851+
warnings.warn("This API has been deprecated for PCA flows, please use a more secure flow. " \
1852+
"See https://aka.ms/msal-ropc-migration for migration guidance", DeprecationWarning)
18491853
claims = _merge_claims_challenge_and_capabilities(
18501854
self._client_capabilities, claims_challenge)
18511855
if self._enable_broker and sys.platform in ("win32", "darwin"):

sample/username_password_sample.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ def acquire_and_use_token():
6767

6868
if not result:
6969
logging.info("No suitable token exists in cache. Let's get a new one from AAD.")
70-
logging.info("This flow has been deprecated")
7170
# See this page for constraints of Username Password Flow.
7271
# https://github.com/AzureAD/microsoft-authentication-library-for-python/wiki/Username-Password-Authentication
7372
result = global_app.acquire_token_by_username_password(

tests/broker-test.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
4. Run this test by `python broker-test.py` and make sure all the tests passed.
1616
1717
"""
18-
import unittest
1918
import msal
2019
import getpass
2120
import os
21+
import warnings
2222
try:
2323
from dotenv import load_dotenv # Use this only in local dev machine
2424
load_dotenv() # take environment variables from .env.
@@ -68,20 +68,17 @@ def interactive_and_silent(scopes, auth_scheme, data, expected_token_type):
6868
)
6969
_assert(result, expected_token_type)
7070

71-
@unittest.skip("ROPC API has been deprecated and thus these tests are no longer needed")
7271
def test_broker_username_password(scopes, expected_token_type):
7372
print("Testing broker username password flows by using accounts in local .env")
7473
username = os.getenv("BROKER_TEST_ACCOUNT") or input("Input test account for broker test: ")
7574
password = os.getenv("BROKER_TEST_ACCOUNT_PASSWORD") or getpass.getpass("Input test account's password: ")
7675
assert username and password, "You need to provide a test account and its password"
7776
result = pca.acquire_token_by_username_password(username, password, scopes)
7877
_assert(result, expected_token_type)
79-
assert result.get("token_source") == "broker"
8078
print("Username password test succeeds.")
8179

8280
def _assert(result, expected_token_type):
8381
assert result.get("access_token"), f"We should obtain a token. Got {result} instead."
84-
assert result.get("token_source") == "broker", "Token should be obtained via broker"
8582
assert result.get("token_type").lower() == expected_token_type.lower(), f"{expected_token_type} not found"
8683

8784
for i in range(2): # Mimic Azure CLI's issue report

tests/test_account_source.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ def test_device_flow_and_its_silent_call_should_bypass_broker(self, _, mocked_br
5252
mocked_broker_ats.assert_not_called()
5353
self.assertEqual(result["token_source"], "identity_provider")
5454

55-
@unittest.skip("ROPC API has been deprecated and thus these tests are no longer needed")
5655
def test_ropc_flow_and_its_silent_call_should_invoke_broker(self, _, mocked_broker_ats):
5756
with patch("msal.broker._signin_silently", return_value=dict(TOKEN_RESPONSE, _account_id="placeholder")):
5857
result = self.app.acquire_token_by_username_password(

tests/test_application.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,6 @@ def mock_post(url, headers=None, *args, **kwargs):
575575
self.assertEqual(result[self.app._TOKEN_SOURCE], self.app._TOKEN_SOURCE_IDP)
576576
self.assertEqual(at, result.get("access_token"))
577577

578-
@unittest.skip("ROPC API has been deprecated and thus these tests are no longer needed")
579578
def test_acquire_token_by_username_password(self):
580579
at = "this is an access token"
581580
def mock_post(url, headers=None, *args, **kwargs):
@@ -707,7 +706,6 @@ def test_organizations_authority_should_emit_warning(self):
707706

708707
@patch(_OIDC_DISCOVERY, new=_OIDC_DISCOVERY_MOCK)
709708
class TestRemoveTokensForClient(unittest.TestCase):
710-
@unittest.skip("ROPC API has been deprecated and thus these tests are no longer needed")
711709
def test_remove_tokens_for_client_should_remove_client_tokens_only(self):
712710
at_for_user = "AT for user"
713711
cca = msal.ConfidentialClientApplication(

tests/test_ccs.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ def test_acquire_token_silent(self):
6060
mocked_method.call_args[1].get("headers", {}).get('X-AnchorMailbox'),
6161
"CSS routing info should be derived from home_account_id")
6262

63-
@unittest.skip("ROPC API has been deprecated and thus these tests are no longer needed")
6463
def test_acquire_token_by_username_password(self):
6564
app = msal.ClientApplication("client_id")
6665
username = "[email protected]"

0 commit comments

Comments
 (0)