def test_permission_denied(self): user2 = self.create_user(is_superuser=False) user2_identity = Identity.objects.create( external_id="slack_id2", idp=self.idp, user=user2, status=IdentityStatus.VALID, scopes=[], ) status_action = {"name": "status", "value": "ignored", "type": "button"} resp = self.post_webhook( action_data=[status_action], slack_user={"id": user2_identity.external_id} ) self.group1 = Group.objects.get(id=self.group1.id) associate_url = build_unlinking_url( self.integration.id, self.org.id, "slack_id2", "C065W1189", self.response_url ) assert resp.status_code == 200, resp.content assert resp.data["response_type"] == "ephemeral" assert not resp.data["replace_original"] assert resp.data["text"] == UNLINK_IDENTITY_MESSAGE.format( associate_url=associate_url, user_email=user2.email, org_name=self.org.name )
def test_handle_submission_fail(self, client_put): status_action = {"name": "resolve_dialog", "value": "resolve_dialog"} # Expect request to open dialog on slack responses.add( method=responses.POST, url="https://slack.com/api/dialog.open", body='{"ok": true}', status=200, content_type="application/json", ) resp = self.post_webhook(action_data=[status_action]) assert resp.status_code == 200, resp.content # Opening dialog should *not* cause the current message to be updated assert resp.content == b"" data = parse_qs(responses.calls[0].request.body) assert data["token"][0] == self.integration.metadata["access_token"] assert data["trigger_id"][0] == self.trigger_id assert "dialog" in data dialog = json.loads(data["dialog"][0]) callback_data = json.loads(dialog["callback_id"]) assert int(callback_data["issue"]) == self.group1.id assert callback_data["orig_response_url"] == self.response_url # Completing the dialog will update the message responses.add( method=responses.POST, url=self.response_url, body='{"ok": true}', status=200, content_type="application/json", ) # make the client raise an API error client_put.side_effect = client.ApiError( 403, '{"detail":"You do not have permission to perform this action."}' ) resp = self.post_webhook( type="dialog_submission", callback_id=dialog["callback_id"], data={"submission": {"resolve_type": "resolved"}}, ) client_put.asser_called() associate_url = build_unlinking_url( self.integration.id, self.org.id, "slack_id", "C065W1189", self.response_url ) assert resp.status_code == 200, resp.content assert resp.data["text"] == UNLINK_IDENTITY_MESSAGE.format( associate_url=associate_url, user_email=self.user.email, org_name=self.org.name )