|
2 | 2 | import logging
|
3 | 3 | import sys
|
4 | 4 |
|
| 5 | +if not sys.platform.startswith("win"): |
| 6 | + raise unittest.SkipTest("requires Windows") |
| 7 | +from msal.wam import ( # Import them after the platform check |
| 8 | + _signin_interactively, _acquire_token_silently, RedirectUriError) |
| 9 | + |
| 10 | + |
5 | 11 | logging.basicConfig(level=logging.DEBUG)
|
6 | 12 |
|
7 |
| -@unittest.skipUnless(sys.platform.startswith("win"), "requires Windows") |
8 | 13 | class TestWam(unittest.TestCase):
|
| 14 | + _authority = "https://login.microsoftonline.com/common" |
| 15 | + _scopes = ["https://graph.microsoft.com/.default"] |
| 16 | + |
9 | 17 | def test_interactive_then_silent(self):
|
10 |
| - from msal.wam import _signin_interactively, _acquire_token_silently # Lazy import |
11 | 18 | client_id = "26a7ee05-5602-4d76-a7ba-eae8b7b67941" # A pre-configured test app
|
12 |
| - authority = "https://login.microsoftonline.com/common" |
13 |
| - scopes = ["https://graph.microsoft.com/.default"] |
14 | 19 |
|
15 |
| - result = _signin_interactively(authority, client_id, scopes) |
| 20 | + result = _signin_interactively(self._authority, client_id, self._scopes) |
16 | 21 | self.assertIsNotNone(result.get("access_token"), result)
|
17 | 22 |
|
18 | 23 | account_id = result["_account_id"]
|
19 |
| - result = _acquire_token_silently(authority, client_id, account_id, scopes) |
| 24 | + result = _acquire_token_silently(self._authority, client_id, account_id, self._scopes) |
20 | 25 | self.assertIsNotNone(result.get("access_token"), result)
|
21 | 26 |
|
| 27 | + def test_unconfigured_app_should_raise_exception(self): |
| 28 | + client_id = "289a413d-284b-4303-9c79-94380abe5d22" # A test app without proper redirect_uri |
| 29 | + with self.assertRaises(RedirectUriError): |
| 30 | + _signin_interactively(self._authority, client_id, self._scopes) |
| 31 | + # Note: _acquire_token_silently() would raise same exception, |
| 32 | + # we skip its test here due to the lack of a valid account_id |
0 commit comments