misc: make sure identical hobo in different db have the same key (#72264)
This commit is contained in:
parent
82b7e01caf
commit
7cece8ce44
|
@ -35,7 +35,7 @@ from django.utils.encoding import force_text
|
|||
from django.utils.timezone import now
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from .utils import Zone, get_installed_services
|
||||
from .utils import Zone, get_installed_services, get_local_key
|
||||
|
||||
SECRET_CHARS = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
|
||||
FLOAT_RE = re.compile(r'^\s*[0-9]+\.[0-9]+\s*')
|
||||
|
@ -190,6 +190,9 @@ class ServiceBase(models.Model):
|
|||
if not self.base_url.endswith('/'):
|
||||
self.base_url += '/'
|
||||
if not self.secret_key:
|
||||
if self.Extra.service_id == 'hobo':
|
||||
self.secret_key = get_local_key(self.base_url)
|
||||
else:
|
||||
self.secret_key = get_random_string(50, SECRET_CHARS)
|
||||
|
||||
is_new = self.id is None
|
||||
|
|
|
@ -346,6 +346,18 @@ def test_multipublik(tenants, mocker):
|
|||
assert Combo.objects.filter(secondary=True).count() == 1
|
||||
assert Combo.objects.filter(secondary=False).count() == 1
|
||||
|
||||
# check hobo secret keys
|
||||
with tenant_context(hobo1):
|
||||
hobo_secret_keys = {
|
||||
hobo1.base_url: Hobo.objects.filter(base_url=hobo1.base_url)[0].secret_key,
|
||||
hobo2.base_url: Hobo.objects.filter(base_url=hobo2.base_url)[0].secret_key,
|
||||
hobo3.base_url: Hobo.objects.filter(base_url=hobo3.base_url)[0].secret_key,
|
||||
}
|
||||
for hobo in (hobo2, hobo3):
|
||||
with tenant_context(hobo):
|
||||
for hobo_instance in Hobo.objects.all():
|
||||
assert hobo_instance.secret_key == hobo_secret_keys.get(hobo_instance.base_url)
|
||||
|
||||
# URL change in interco portal
|
||||
with tenant_context(hobo1):
|
||||
combo = Combo.objects.get(slug='portal')
|
||||
|
|
Loading…
Reference in New Issue