|
15 | 15 | from tests.utils import remove_os_env_temporarily, restore_os_env |
16 | 16 |
|
17 | 17 | valid_token = "xoxb-valid" |
| 18 | +valid_user_token = "xoxp-valid" |
18 | 19 |
|
19 | 20 |
|
20 | 21 | def authorize(enterprise_id, team_id, user_id, client: WebClient): |
21 | 22 | assert enterprise_id == "E111" |
22 | 23 | assert team_id == "T111" |
23 | | - assert user_id == "W111" |
| 24 | + assert user_id == "W99999" |
24 | 25 | auth_test = client.auth_test(token=valid_token) |
25 | 26 | return AuthorizeResult.from_auth_test_response( |
26 | 27 | auth_test_response=auth_test, bot_token=valid_token, |
27 | 28 | ) |
28 | 29 |
|
29 | 30 |
|
| 31 | +def user_authorize(enterprise_id, team_id, user_id, client: WebClient): |
| 32 | + assert enterprise_id == "E111" |
| 33 | + assert team_id == "T111" |
| 34 | + assert user_id == "W99999" |
| 35 | + auth_test = client.auth_test(token=valid_user_token) |
| 36 | + return AuthorizeResult.from_auth_test_response( |
| 37 | + auth_test_response=auth_test, user_token=valid_user_token, |
| 38 | + ) |
| 39 | + |
| 40 | + |
30 | 41 | def error_authorize(enterprise_id, team_id, user_id): |
31 | 42 | assert enterprise_id == "E111" |
32 | 43 | assert team_id == "T111" |
33 | | - assert user_id == "W111" |
| 44 | + assert user_id == "W99999" |
34 | 45 | return None |
35 | 46 |
|
36 | 47 |
|
@@ -94,11 +105,39 @@ def test_failure(self): |
94 | 105 | assert response.body == ":x: Please install this app into the workspace :bow:" |
95 | 106 | assert self.mock_received_requests.get("/auth.test") == None |
96 | 107 |
|
| 108 | + def test_bot_context_attributes(self): |
| 109 | + app = App( |
| 110 | + client=self.web_client, |
| 111 | + authorize=authorize, |
| 112 | + signing_secret=self.signing_secret, |
| 113 | + ) |
| 114 | + app.action("a")(assert_bot_context_attributes) |
| 115 | + |
| 116 | + request = self.build_valid_request() |
| 117 | + response = app.dispatch(request) |
| 118 | + assert response.status == 200 |
| 119 | + assert response.body == "" |
| 120 | + assert self.mock_received_requests["/auth.test"] == 1 |
| 121 | + |
| 122 | + def test_user_context_attributes(self): |
| 123 | + app = App( |
| 124 | + client=self.web_client, |
| 125 | + authorize=user_authorize, |
| 126 | + signing_secret=self.signing_secret, |
| 127 | + ) |
| 128 | + app.action("a")(assert_user_context_attributes) |
| 129 | + |
| 130 | + request = self.build_valid_request() |
| 131 | + response = app.dispatch(request) |
| 132 | + assert response.status == 200 |
| 133 | + assert response.body == "" |
| 134 | + assert self.mock_received_requests["/auth.test"] == 1 |
| 135 | + |
97 | 136 |
|
98 | 137 | body = { |
99 | 138 | "type": "block_actions", |
100 | 139 | "user": { |
101 | | - "id": "W111", |
| 140 | + "id": "W99999", |
102 | 141 | "username": "primary-owner", |
103 | 142 | "name": "primary-owner", |
104 | 143 | "team_id": "T111", |
@@ -141,3 +180,23 @@ def simple_listener(ack, body, payload, action): |
141 | 180 | assert payload == action |
142 | 181 | assert action["action_id"] == "a" |
143 | 182 | ack() |
| 183 | + |
| 184 | + |
| 185 | +def assert_bot_context_attributes(ack, context): |
| 186 | + assert context["bot_id"] == "BZYBOTHED" |
| 187 | + assert context["bot_user_id"] == "W23456789" |
| 188 | + assert context["bot_token"] == "xoxb-valid" |
| 189 | + assert context["token"] == "xoxb-valid" |
| 190 | + assert context["user_id"] == "W99999" |
| 191 | + assert context.get("user_token") is None |
| 192 | + ack() |
| 193 | + |
| 194 | + |
| 195 | +def assert_user_context_attributes(ack, context): |
| 196 | + assert context.get("bot_id") is None |
| 197 | + assert context.get("bot_user_id") is None |
| 198 | + assert context.get("bot_token") is None |
| 199 | + assert context["token"] == "xoxp-valid" |
| 200 | + assert context["user_id"] == "W99999" |
| 201 | + assert context["user_token"] == "xoxp-valid" |
| 202 | + ack() |
0 commit comments