def test_ApacheSSLContext_vault(self, _exists):
     _exists.return_value = True
     self.relation_ids.return_value = ['certificates:60']
     self.related_units.return_value = ['vault/0']
     self.assertEqual(
         horizon_contexts.ApacheSSLContext()(),
         {
             'ssl_configured': True,
             'ssl_cert': '/etc/apache2/ssl/horizon/cert_dashboard',
             'ssl_key': '/etc/apache2/ssl/horizon/key_dashboard'})
 def test_ApacheSSLContext_enabled(self, _chmod):
     self.get_cert.return_value = ('cert', 'key')
     self.b64decode.side_effect = ['cert', 'key']
     with patch_open() as (_open, _file):
         self.assertEqual(
             horizon_contexts.ApacheSSLContext()(), {
                 'ssl_configured': True,
                 'ssl_cert': '/etc/ssl/certs/dashboard.cert',
                 'ssl_key': '/etc/ssl/private/dashboard.key'
             })
         _open.assert_has_calls([
             call('/etc/ssl/certs/dashboard.cert', 'w'),
             call('/etc/ssl/private/dashboard.key', 'w')
         ])
         _file.write.assert_has_calls([call('cert'), call('key')])
     # Security check on key permissions
     _chmod.assert_called_with('/etc/ssl/private/dashboard.key', 0o600)
 }),
 (APACHE_CONF, {
     'hook_contexts':
     [horizon_contexts.HorizonContext(),
      context.SyslogContext()],
     'services': ['apache2', 'memcached'],
 }),
 (APACHE_24_CONF, {
     'hook_contexts':
     [horizon_contexts.HorizonContext(),
      context.SyslogContext()],
     'services': ['apache2', 'memcached'],
 }),
 (APACHE_SSL, {
     'hook_contexts': [
         horizon_contexts.ApacheSSLContext(),
         horizon_contexts.ApacheContext()
     ],
     'services': ['apache2', 'memcached'],
 }),
 (APACHE_24_SSL, {
     'hook_contexts': [
         horizon_contexts.ApacheSSLContext(),
         horizon_contexts.ApacheContext()
     ],
     'services': ['apache2', 'memcached'],
 }),
 (APACHE_DEFAULT, {
     'hook_contexts': [horizon_contexts.ApacheContext()],
     'services': ['apache2', 'memcached'],
 }),
 def test_ApacheSSLContext_disabled(self):
     self.relation_ids.return_value = []
     self.get_cert.return_value = (None, None)
     self.assertEqual(horizon_contexts.ApacheSSLContext()(),
                      {'ssl_configured': False})
Esempio n. 5
0
                       context.SyslogContext(),
                       horizon_contexts.LocalSettingsContext()],
     'services': ['apache2']
 }),
 (APACHE_CONF, {
     'hook_contexts': [horizon_contexts.HorizonContext(),
                       context.SyslogContext()],
     'services': ['apache2'],
 }),
 (APACHE_24_CONF, {
     'hook_contexts': [horizon_contexts.HorizonContext(),
                       context.SyslogContext()],
     'services': ['apache2'],
 }),
 (APACHE_SSL, {
     'hook_contexts': [horizon_contexts.ApacheSSLContext(),
                       horizon_contexts.ApacheContext()],
     'services': ['apache2'],
 }),
 (APACHE_24_SSL, {
     'hook_contexts': [horizon_contexts.ApacheSSLContext(),
                       horizon_contexts.ApacheContext()],
     'services': ['apache2'],
 }),
 (APACHE_DEFAULT, {
     'hook_contexts': [horizon_contexts.ApacheContext()],
     'services': ['apache2'],
 }),
 (APACHE_24_DEFAULT, {
     'hook_contexts': [horizon_contexts.ApacheContext()],
     'services': ['apache2'],