Skip to content

fix(app-platform): Only build internal slug once #13657

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 1 commit into from
Jun 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/sentry/models/sentryapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import hmac
import itertools
import hashlib
import re

from django.db import models
from django.utils import timezone
Expand Down Expand Up @@ -171,12 +172,15 @@ def _set_slug(self):
if not self.slug:
self.slug = slugify(self.name)

if self.is_internal:
if self.is_internal and not self._has_internal_slug():
self.slug = u'{}-{}'.format(
self.slug,
hashlib.sha1(self.owner.slug).hexdigest()[0:6],
)

def _has_internal_slug(self):
return re.match(r'\w+-[0-9a-zA-Z]+', self.slug)

def build_signature(self, body):
secret = self.application.client_secret
return hmac.new(
Expand Down
9 changes: 9 additions & 0 deletions tests/sentry/models/test_sentryapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ def test_internal_slug(self):
hashlib.sha1(self.org.slug).hexdigest()[0:6]
)

def test_internal_slug_on_update(self):
self.sentry_app.status = SentryAppStatus.INTERNAL
self.sentry_app.save()
self.sentry_app.save()

assert self.sentry_app.slug == u'nulldb-{}'.format(
hashlib.sha1(self.org.slug).hexdigest()[0:6]
)

def test_paranoid(self):
self.sentry_app.save()
self.sentry_app.delete()
Expand Down