misc: skip tenants with unallowed hostname (#4794) #1244

Open
fpeters wants to merge 1 commits from wip/4794-mark-vhost-name into main
4 changed files with 32 additions and 0 deletions

View File

@ -234,6 +234,7 @@ def setuptest():
hobo_cmd.all_services = HOBO_JSON
CompatWcsPublisher.APP_DIR = tempfile.mkdtemp()
pub = create_temporary_pub()
pub.set_tenant_by_hostname('example.net')
pub.cfg['language'] = {'language': 'en'}
yield pub, hobo_cmd

View File

@ -160,6 +160,24 @@ def test_get_tenants():
assert 'xxx' not in hostnames
assert 'plop.invalid' not in hostnames
os.mkdir(os.path.join(pub.APP_DIR, 'example.org'))
assert {x.hostname for x in pub.__class__.get_tenants()} == {'example.net', 'example.org'}
# empty site-options
with open(os.path.join(pub.APP_DIR, 'example.org', 'site-options.cfg'), 'w') as fd:
pass
assert {x.hostname for x in pub.__class__.get_tenants()} == {'example.net', 'example.org'}
# site-options with appropriate hostname
with open(os.path.join(pub.APP_DIR, 'example.org', 'site-options.cfg'), 'w') as fd:
fd.write('[options]\nallowed_hostname = example.org\n')
assert {x.hostname for x in pub.__class__.get_tenants()} == {'example.net', 'example.org'}
# site-options with inappropriate hostname
with open(os.path.join(pub.APP_DIR, 'example.org', 'site-options.cfg'), 'w') as fd:
fd.write('[options]\nallowed_hostname = another-example.org\n')
assert {x.hostname for x in pub.__class__.get_tenants()} == {'example.net'}
def test_register_cronjobs():
pub.register_cronjobs()

View File

@ -446,6 +446,8 @@ class Command(TenantCommand):
if 'options' not in config.sections():
config.add_section('options')
config.set('options', 'allowed_hostname', pub.tenant.hostname)
variables = {}
api_secrets = {}
legacy_urls = {}

View File

@ -1009,6 +1009,17 @@ class QommonPublisher(Publisher):
# avoid going twice over same tenants, in case of a tenants/ symlink to
# /var/lib/wcs/.
continue
# check it's not a tenant erroneously renamed
config = configparser.RawConfigParser()
site_options_filepath = os.path.join(tenant_dir, 'site-options.cfg')
if os.path.exists(site_options_filepath):
config.read(site_options_filepath)
try:
allowed_hostname = config.get('options', 'allowed_hostname')
if tenant != allowed_hostname:
continue
except (configparser.NoOptionError, configparser.NoSectionError):
pass # legacy

À noter que la modification à hobo_deploy va faire en sorte que les sites existants auront leur site-options.cfg complété (lors de l'appel à hobo_deploy --redeploy), donc on pourrait imaginer plus tard retirer cette partie "legacy".

À noter que la modification à hobo_deploy va faire en sorte que les sites existants auront leur site-options.cfg complété (lors de l'appel à `hobo_deploy --redeploy`), donc on pourrait imaginer plus tard retirer cette partie "legacy".
seen.add(tenant)
yield Tenant(tenant_dir)