test_api_application_rotate_secrets.py 1.1 KB

123456789101112131415161718192021222324252627282930
  1. from django.urls import reverse
  2. from sentry.models import ApiApplication
  3. from sentry.testutils import APITestCase
  4. from sentry.testutils.silo import control_silo_test
  5. @control_silo_test(stable=True)
  6. class ApiApplicationRotateSecretTest(APITestCase):
  7. def setUp(self):
  8. self.app = ApiApplication.objects.create(owner=self.user, name="a")
  9. self.path = reverse("sentry-api-0-api-application-rotate-secret", args=[self.app.client_id])
  10. def test_unauthorized_call(self):
  11. response = self.client.post(self.path)
  12. assert response.status_code == 403
  13. def test_invalid_app_id(self):
  14. self.login_as(self.user)
  15. path_with_invalid_id = reverse("sentry-api-0-api-application-rotate-secret", args=["abc"])
  16. response = self.client.post(path_with_invalid_id)
  17. assert response.status_code == 404
  18. def test_valid_call(self):
  19. self.login_as(self.user)
  20. old_secret = self.app.client_secret
  21. response = self.client.post(self.path, data={})
  22. new_secret = response.data["clientSecret"]
  23. assert len(new_secret) == len(old_secret)
  24. assert new_secret != old_secret