Projet

Général

Profil

0001-misc-make-sure-identical-hobo-in-different-db-have-t.patch

Frédéric Péters, 16 décembre 2022 16:24

Télécharger (2,58 ko)

Voir les différences:

Subject: [PATCH] misc: make sure identical hobo in different db have the same
 key (#72264)

 hobo/environment/models.py            |  7 +++++--
 tests_multipublik/test_multipublik.py | 12 ++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)
hobo/environment/models.py
35 35
from django.utils.timezone import now
36 36
from django.utils.translation import ugettext_lazy as _
37 37

  
38
from .utils import Zone, get_installed_services
38
from .utils import Zone, get_installed_services, get_local_key
39 39

  
40 40
SECRET_CHARS = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
41 41
FLOAT_RE = re.compile(r'^\s*[0-9]+\.[0-9]+\s*')
......
190 190
        if not self.base_url.endswith('/'):
191 191
            self.base_url += '/'
192 192
        if not self.secret_key:
193
            self.secret_key = get_random_string(50, SECRET_CHARS)
193
            if self.Extra.service_id == 'hobo':
194
                self.secret_key = get_local_key(self.base_url)
195
            else:
196
                self.secret_key = get_random_string(50, SECRET_CHARS)
194 197

  
195 198
        is_new = self.id is None
196 199
        super().save(*args, **kwargs)
tests_multipublik/test_multipublik.py
346 346
        assert Combo.objects.filter(secondary=True).count() == 1
347 347
        assert Combo.objects.filter(secondary=False).count() == 1
348 348

  
349
    # check hobo secret keys
350
    with tenant_context(hobo1):
351
        hobo_secret_keys = {
352
            hobo1.base_url: Hobo.objects.filter(base_url=hobo1.base_url)[0].secret_key,
353
            hobo2.base_url: Hobo.objects.filter(base_url=hobo2.base_url)[0].secret_key,
354
            hobo3.base_url: Hobo.objects.filter(base_url=hobo3.base_url)[0].secret_key,
355
        }
356
    for hobo in (hobo2, hobo3):
357
        with tenant_context(hobo):
358
            for hobo_instance in Hobo.objects.all():
359
                assert hobo_instance.secret_key == hobo_secret_keys.get(hobo_instance.base_url)
360

  
349 361
    # URL change in interco portal
350 362
    with tenant_context(hobo1):
351 363
        combo = Combo.objects.get(slug='portal')
352
-