def test_virtualhost_config(self): """get_virtualhost_config returns the config for the virtualhost.""" hookenv = FakeHookEnv() config = get_virtualhost_config(hookenv=hookenv) self.assertEqual( {'domain': '1.2.3.4', 'document_root': '/srv/archive-auth-mirror/static', 'basic_auth_file': '/srv/archive-auth-mirror/basic-auth'}, config)
def test_virtualhost_config_auth_cache_time(self): """If caching time is passed, it's included in the vhost config.""" hookenv = FakeHookEnv() config = get_virtualhost_config(auth_cache_time='5m', hookenv=hookenv) self.assertEqual( { 'domain': '1.2.3.4', 'document_root': '/srv/archive-auth-mirror/static', 'auth_backends': [], 'auth_cache_time': '5m', 'basic_auth_file': '/srv/archive-auth-mirror/basic-auth' }, config)
def test_virtualhost_config_auth_backends(self): """If backends are passed, they're included in the vhost config.""" hookenv = FakeHookEnv() auth_backends = [('1.2.3.4', '8080'), ('5.6.7.8', '9090')] config = get_virtualhost_config(auth_backends=auth_backends, hookenv=hookenv) self.assertEqual( { 'domain': '1.2.3.4', 'document_root': '/srv/archive-auth-mirror/static', 'auth_backends': auth_backends, 'auth_cache_time': None, 'basic_auth_file': '/srv/archive-auth-mirror/basic-auth' }, config)
def test_virtualhost_config_auth_cache_time(self): """If caching time is passed, it's included in the vhost config.""" hookenv = FakeHookEnv() auth_backends = [] resource_name = 'esm-apps' auth_cache_enabled = True auth_cache_duration, auth_cache_inactivity = "1h", "5m" config = get_virtualhost_config(auth_backends, resource_name, auth_cache_enabled, auth_cache_duration, auth_cache_inactivity, hookenv=hookenv) self.assertEqual( { 'domain': '1.2.3.4', 'document_root': '/srv/archive-auth-mirror/static', 'auth_backends': [], 'auth_cache_enabled': True, 'auth_cache_duration': "1h", 'auth_cache_inactivity': "5m", 'basic_auth_file': '/srv/archive-auth-mirror/basic-auth', 'resource_name': 'esm-apps' }, config)
def test_virtualhost_config_auth_backends(self): """If backends are passed, they're included in the vhost config.""" hookenv = FakeHookEnv() auth_backends = [('1.2.3.4', '8080'), ('5.6.7.8', '9090')] resource_name = 'fips' auth_cache_enabled = False auth_cache_duration = auth_cache_inactivity = "" config = get_virtualhost_config(auth_backends, resource_name, auth_cache_enabled, auth_cache_duration, auth_cache_inactivity, hookenv=hookenv) self.assertEqual( { 'domain': '1.2.3.4', 'document_root': '/srv/archive-auth-mirror/static', 'auth_backends': auth_backends, 'auth_cache_enabled': False, 'auth_cache_duration': "", 'auth_cache_inactivity': "", 'basic_auth_file': '/srv/archive-auth-mirror/basic-auth', 'resource_name': 'fips' }, config)
def test_virtualhost_config(self): """get_virtualhost_config returns the config for the virtualhost.""" hookenv = FakeHookEnv() auth_backends = [] resource_name = 'esm' auth_cache_enabled = False auth_cache_duration = auth_cache_inactivity = "" config = get_virtualhost_config(auth_backends, resource_name, auth_cache_enabled, auth_cache_duration, auth_cache_inactivity, hookenv=hookenv) self.assertEqual( { 'domain': '1.2.3.4', 'document_root': '/srv/archive-auth-mirror/static', 'auth_backends': [], 'auth_cache_enabled': False, 'auth_cache_duration': "", 'auth_cache_inactivity': "", 'basic_auth_file': '/srv/archive-auth-mirror/basic-auth', 'resource_name': 'esm' }, config)
def test_get_with_config(self): """If the 'service-url' config is set, it's used as virtualhost.""" hookenv = FakeHookEnv(config={'service-url': 'example.com'}) self.assertEqual('example.com', get_virtualhost_name(hookenv=hookenv))
def test_get_no_config(self): """If the 'service-url' config is not set, the unit IP is returned.""" hookenv = FakeHookEnv() self.assertEqual('1.2.3.4', get_virtualhost_name(hookenv=hookenv))