def test_overwrites_existing_external_id(self, unsign): existing_identity = Identity.objects.create( user=self.user, idp=self.idp, external_id='old-slack-id', status=IdentityStatus.VALID, ) unsign.return_value = { 'integration_id': self.integration.id, 'organization_id': self.org.id, 'slack_id': 'new-slack-id', 'channel_id': 'my-channel', 'response_url': 'http://example.slack.com/response_url', } linking_url = build_linking_url( self.integration, self.org, 'new-slack-id', 'my-channel', 'http://example.slack.com/response_url') responses.add( method=responses.POST, url='http://example.slack.com/response_url', body='{"ok": true}', status=200, content_type='application/json', ) self.client.post(linking_url) assert Identity.objects.filter( id=existing_identity.id, external_id='new-slack-id', user=self.user, ).exists()
def test_basic_flow(self): linking_url = build_linking_url(self.integration, self.org, 'new-slack-id', 'my-channel') resp = self.client.get(linking_url) assert resp.status_code == 200 self.assertTemplateUsed(resp, 'sentry/auth-link-identity.html') responses.add( method=responses.POST, url='https://slack.com/api/chat.postEphemeral', body='{"ok": true}', status=200, content_type='application/json', ) # Link identity of user resp = self.client.post(linking_url) identity = Identity.objects.filter( external_id='new-slack-id', user=self.user, ) assert len(identity) == 1 assert identity[0].idp == self.idp assert identity[0].status == IdentityStatus.VALID assert len(responses.calls) == 1
def test_ask_linking(self, sign): sign.return_value = "signed_parameters" resp = self.post_webhook(slack_user={"id": "invalid-id", "domain": "example"}) associate_url = build_linking_url( self.integration, self.org, "invalid-id", "C065W1189", self.response_url ) assert resp.status_code == 200, resp.content assert resp.data["response_type"] == "ephemeral" assert resp.data["text"] == LINK_IDENTITY_MESSAGE.format(associate_url=associate_url)
def test_ask_linking(self): resp = self.post_webhook(slack_user={ 'id': 'invalid-id', 'domain': 'example', }) associate_url = build_linking_url(self.integration, self.org, 'invalid-id', 'C065W1189') assert resp.status_code == 200, resp.content assert resp.data['response_type'] == 'ephemeral' assert resp.data['text'] == LINK_IDENTITY_MESSAGE.format( associate_url=associate_url, )
def test_basic_flow(self, unsign): unsign.return_value = { 'integration_id': self.integration.id, 'organization_id': self.org.id, 'slack_id': 'new-slack-id', 'channel_id': 'my-channel', 'response_url': 'http://example.slack.com/response_url', } linking_url = build_linking_url( self.integration, self.org, 'new-slack-id', 'my-channel', 'http://example.slack.com/response_url' ) resp = self.client.get(linking_url) assert resp.status_code == 200 self.assertTemplateUsed(resp, 'sentry/auth-link-identity.html') responses.add( method=responses.POST, url='http://example.slack.com/response_url', body='{"ok": true}', status=200, content_type='application/json', ) # Link identity of user resp = self.client.post(linking_url) identity = Identity.objects.filter( external_id='new-slack-id', user=self.user1, ) assert len(identity) == 1 assert identity[0].idp == self.idp assert identity[0].status == IdentityStatus.VALID assert len(responses.calls) == 1
def test_basic_flow(self, unsign): unsign.return_value = { 'integration_id': self.integration.id, 'organization_id': self.org.id, 'slack_id': 'new-slack-id', 'channel_id': 'my-channel', 'response_url': 'http://example.slack.com/response_url', } linking_url = build_linking_url( self.integration, self.org, 'new-slack-id', 'my-channel', 'http://example.slack.com/response_url' ) resp = self.client.get(linking_url) assert resp.status_code == 200 self.assertTemplateUsed(resp, 'sentry/auth-link-identity.html') responses.add( method=responses.POST, url='http://example.slack.com/response_url', body='{"ok": true}', status=200, content_type='application/json', ) # Link identity of user resp = self.client.post(linking_url) identity = Identity.objects.filter( external_id='new-slack-id', user=self.user, ) assert len(identity) == 1 assert identity[0].idp == self.idp assert identity[0].status == IdentityStatus.VALID assert len(responses.calls) == 1
def test_ask_linking(self, sign): sign.return_value = 'signed_parameters' resp = self.post_webhook(slack_user={ 'id': 'invalid-id', 'domain': 'example', }) associate_url = build_linking_url( self.integration, self.org, 'invalid-id', 'C065W1189', self.response_url ) assert resp.status_code == 200, resp.content assert resp.data['response_type'] == 'ephemeral' assert resp.data['text'] == LINK_IDENTITY_MESSAGE.format( associate_url=associate_url, )
def test_overwrites_existing_identities(self, unsign): Identity.objects.create(user=self.user1, idp=self.idp, external_id="slack-id1", status=IdentityStatus.VALID) Identity.objects.create(user=self.user2, idp=self.idp, external_id="slack-id2", status=IdentityStatus.VALID) unsign.return_value = { "integration_id": self.integration.id, "organization_id": self.org.id, "slack_id": "slack-id2", "channel_id": "my-channel", "response_url": "http://example.slack.com/response_url", } linking_url = build_linking_url( self.integration, self.org, "slack-id2", "my-channel", "http://example.slack.com/response_url", ) responses.add( method=responses.POST, url="http://example.slack.com/response_url", body='{"ok": true}', status=200, content_type="application/json", ) self.client.post(linking_url) Identity.objects.get(external_id="slack-id2", user=self.user1) assert not Identity.objects.filter(external_id="slack-id1", user=self.user1).exists() assert not Identity.objects.filter(external_id="slack-id2", user=self.user2).exists()
def test_basic_flow(self, unsign): unsign.return_value = { "integration_id": self.integration.id, "organization_id": self.org.id, "slack_id": "new-slack-id", "channel_id": "my-channel", "response_url": "http://example.slack.com/response_url", } linking_url = build_linking_url( self.integration, self.org, "new-slack-id", "my-channel", "http://example.slack.com/response_url", ) resp = self.client.get(linking_url) assert resp.status_code == 200 self.assertTemplateUsed(resp, "sentry/auth-link-identity.html") responses.add( method=responses.POST, url="http://example.slack.com/response_url", body='{"ok": true}', status=200, content_type="application/json", ) # Link identity of user resp = self.client.post(linking_url) identity = Identity.objects.filter(external_id="new-slack-id", user=self.user1) assert len(identity) == 1 assert identity[0].idp == self.idp assert identity[0].status == IdentityStatus.VALID assert len(responses.calls) == 1
def test_overwrites_existing_external_id(self, unsign): existing_identity = Identity.objects.create( user=self.user, idp=self.idp, external_id='old-slack-id', status=IdentityStatus.VALID, ) unsign.return_value = { 'integration_id': self.integration.id, 'organization_id': self.org.id, 'slack_id': 'new-slack-id', 'channel_id': 'my-channel', 'response_url': 'http://example.slack.com/response_url', } linking_url = build_linking_url( self.integration, self.org, 'new-slack-id', 'my-channel', 'http://example.slack.com/response_url' ) responses.add( method=responses.POST, url='http://example.slack.com/response_url', body='{"ok": true}', status=200, content_type='application/json', ) self.client.post(linking_url) assert Identity.objects.filter( id=existing_identity.id, external_id='new-slack-id', user=self.user, ).exists()