-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
chore(jira): Use new CDN signed installs #29465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
98b7f2f
✨ Use new CDN signed installs on jira
leeandher 6a8ddf3
🔇 Remove logs
leeandher dc75f60
✅ Add tests for jira installation hooks
leeandher 4e075d9
✏️ i made a typo
leeandher 2b7bd9c
🔥 Remove import changes
leeandher cda50b2
🏷 Correct types and typos
leeandher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import jwt | ||
| import responses | ||
|
|
||
| from sentry.constants import ObjectStatus | ||
| from sentry.integrations.atlassian_connect import get_query_hash | ||
| from sentry.models import Integration | ||
| from sentry.testutils import APITestCase | ||
| from sentry.utils.http import absolute_uri | ||
| from tests.sentry.utils.test_jwt import RS256_KEY, RS256_PUB_KEY | ||
|
|
||
|
|
||
| class JiraInstalledTest(APITestCase): | ||
| external_id = "it2may+cody" | ||
| jira_signing_algorithm = "RS256" | ||
| kid = "cudi" | ||
leeandher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| path = "/extensions/jira/installed/" | ||
|
|
||
| def jwt_token(self): | ||
| return jwt.encode( | ||
| { | ||
| "iss": self.external_id, | ||
| "aud": absolute_uri(), | ||
| "qsh": get_query_hash(self.path, method="POST", query_params={}), | ||
| }, | ||
| RS256_KEY, | ||
| algorithm=self.jira_signing_algorithm, | ||
| headers={"kid": self.kid, "alg": self.jira_signing_algorithm}, | ||
| ) | ||
|
|
||
| @responses.activate | ||
| def test_simple(self): | ||
| responses.add( | ||
| responses.GET, | ||
| f"https://connect-install-keys.atlassian.com/{self.kid}", | ||
| body=RS256_PUB_KEY, | ||
| ) | ||
|
|
||
| resp = self.client.post( | ||
| self.path, | ||
| data={ | ||
| "jira": { | ||
| "metadata": {}, | ||
| "external_id": self.external_id, | ||
| }, | ||
| "clientKey": "limepie", | ||
| "oauthClientId": "EFG", | ||
| "publicKey": "yourCar", | ||
| "sharedSecret": "garden", | ||
| "baseUrl": "https://sentry.io.org.xyz.online.dev.sentry.io", | ||
| }, | ||
| HTTP_AUTHORIZATION="JWT " + self.jwt_token(), | ||
| ) | ||
| integration = Integration.objects.get(provider="jira", external_id=self.external_id) | ||
| assert integration.status == ObjectStatus.VISIBLE | ||
| assert resp.status_code == 200 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,48 @@ | ||
| from unittest.mock import patch | ||
| import jwt | ||
| import responses | ||
|
|
||
| from sentry.constants import ObjectStatus | ||
| from sentry.integrations.atlassian_connect import get_query_hash | ||
| from sentry.models import Integration | ||
| from sentry.testutils import APITestCase | ||
| from sentry.utils.http import absolute_uri | ||
| from tests.sentry.utils.test_jwt import RS256_KEY, RS256_PUB_KEY | ||
|
|
||
|
|
||
| class JiraUninstalledTest(APITestCase): | ||
| external_id = "it2may+cody" | ||
| jira_signing_algorithm = "RS256" | ||
| kid = "cudi" | ||
| path = "/extensions/jira/uninstalled/" | ||
|
|
||
| def jwt_token(self): | ||
| return jwt.encode( | ||
| { | ||
| "iss": self.external_id, | ||
| "aud": absolute_uri(), | ||
| "qsh": get_query_hash(self.path, method="POST", query_params={}), | ||
| }, | ||
| RS256_KEY, | ||
| algorithm=self.jira_signing_algorithm, | ||
| headers={"kid": self.kid, "alg": self.jira_signing_algorithm}, | ||
| ) | ||
|
|
||
| @responses.activate | ||
| def test_simple(self): | ||
| org = self.organization | ||
|
|
||
| integration = Integration.objects.create( | ||
| provider="jira", name="Example Jira", status=ObjectStatus.VISIBLE | ||
| provider="jira", status=ObjectStatus.VISIBLE, external_id=self.external_id | ||
| ) | ||
| integration.add_organization(org, self.user) | ||
|
|
||
| path = "/extensions/jira/uninstalled/" | ||
| responses.add( | ||
| responses.GET, | ||
| f"https://connect-install-keys.atlassian.com/{self.kid}", | ||
| body=RS256_PUB_KEY, | ||
| ) | ||
|
|
||
| with patch( | ||
| "sentry.integrations.jira.uninstalled.get_integration_from_jwt", | ||
| return_value=integration, | ||
| ): | ||
| resp = self.client.post(path, data={}, HTTP_AUTHORIZATION="JWT anexampletoken") | ||
| integration = Integration.objects.get(id=integration.id) | ||
| assert integration.status == ObjectStatus.DISABLED | ||
| assert resp.status_code == 200 | ||
| resp = self.client.post(self.path, data={}, HTTP_AUTHORIZATION="JWT " + self.jwt_token()) | ||
| integration = Integration.objects.get(id=integration.id) | ||
| assert integration.status == ObjectStatus.DISABLED | ||
| assert resp.status_code == 200 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.