|
1 | 1 | import unittest |
2 | 2 |
|
3 | | -from slack_sdk.oauth import AuthorizeUrlGenerator |
| 3 | +from slack_sdk.oauth import AuthorizeUrlGenerator, OpenIDConnectAuthorizeUrlGenerator |
4 | 4 |
|
5 | 5 |
|
6 | 6 | class TestGenerator(unittest.TestCase): |
@@ -28,5 +28,45 @@ def test_base_url(self): |
28 | 28 | authorization_url="https://www.example.com/authorize", |
29 | 29 | ) |
30 | 30 | url = generator.generate("state-value") |
31 | | - expected = "https://www.example.com/authorize?state=state-value&client_id=111.222&scope=chat:write,commands&user_scope=search:read" |
| 31 | + expected = ( |
| 32 | + "https://www.example.com/authorize" |
| 33 | + "?state=state-value" |
| 34 | + "&client_id=111.222" |
| 35 | + "&scope=chat:write,commands" |
| 36 | + "&user_scope=search:read" |
| 37 | + ) |
| 38 | + self.assertEqual(expected, url) |
| 39 | + |
| 40 | + def test_team(self): |
| 41 | + generator = AuthorizeUrlGenerator( |
| 42 | + client_id="111.222", |
| 43 | + scopes=["chat:write", "commands"], |
| 44 | + user_scopes=["search:read"], |
| 45 | + ) |
| 46 | + url = generator.generate(state="state-value", team="T12345") |
| 47 | + expected = ( |
| 48 | + "https://slack.com/oauth/v2/authorize" |
| 49 | + "?state=state-value" |
| 50 | + "&client_id=111.222" |
| 51 | + "&scope=chat:write,commands&user_scope=search:read" |
| 52 | + "&team=T12345" |
| 53 | + ) |
| 54 | + self.assertEqual(expected, url) |
| 55 | + |
| 56 | + def test_openid_connect(self): |
| 57 | + generator = OpenIDConnectAuthorizeUrlGenerator( |
| 58 | + client_id="111.222", |
| 59 | + redirect_uri="https://www.example.com/oidc/callback", |
| 60 | + scopes=["openid"], |
| 61 | + ) |
| 62 | + url = generator.generate(state="state-value", nonce="nnn", team="T12345") |
| 63 | + expected = ( |
| 64 | + "https://slack.com/openid/connect/authorize" |
| 65 | + "?response_type=code&state=state-value" |
| 66 | + "&client_id=111.222" |
| 67 | + "&scope=openid" |
| 68 | + "&redirect_uri=https://www.example.com/oidc/callback" |
| 69 | + "&team=T12345" |
| 70 | + "&nonce=nnn" |
| 71 | + ) |
32 | 72 | self.assertEqual(expected, url) |
0 commit comments