Ejemplo n.º 1
0
    def test_use_certificate(self):
        sv1 = apache.VirtualHost(ssl_template)

        self.assertEqual('/etc/aws/keys/ssl/https.crt', sv1.ssl_cert_path)
        self.assertEqual('/etc/aws/keys/ssl/https.key', sv1.ssl_key_path)
        with self.assertRaises(NoPathError):
            print sv1.ssl_chain_path

        custom_certificate = apache.SSLCertificate(1)
        cert_path = custom_certificate.cert_path
        key_path = custom_certificate.key_path
        chain_path = custom_certificate.chain_path
        sv1.use_certificate(cert_path, key_path, chain_path)
        self.assertEqual('/etc/scalr/private.d/keys/https_1.crt',
                         sv1.ssl_cert_path)
        self.assertEqual('/etc/scalr/private.d/keys/https_1.key',
                         sv1.ssl_key_path)
        self.assertEqual('/etc/scalr/private.d/keys/https_1-ca.crt',
                         sv1.ssl_chain_path)

        default_certificate = apache.SSLCertificate()
        sv1.use_certificate(default_certificate.cert_path,
                            default_certificate.key_path)
        self.assertEqual('/etc/scalr/private.d/keys/https.crt',
                         sv1.ssl_cert_path)
        self.assertEqual('/etc/scalr/private.d/keys/https.key',
                         sv1.ssl_key_path)
        with self.assertRaises(NoPathError):
            print sv1.ssl_chain_path

        v1 = apache.VirtualHost(simple_template)
        with self.assertRaises(apache.ApacheError):
            v1.use_certificate(default_certificate.cert_path,
                               default_certificate.key_path)
Ejemplo n.º 2
0
 def test_parse_ssl_template(self):
     sv1 = apache.VirtualHost(ssl_template)
     self.assertTrue(sv1.body)
     self.assertTrue('/etc/aws/' in sv1.body)
     self.assertEqual(443, sv1.port)
     self.assertEqual('secure.dima.com', sv1.server_name)
     self.assertEqual('/var/log/http-dima.com-access.log',
                      sv1.custom_log_path)
     self.assertEqual('/var/log/http-dima.com-ssl.log', sv1.error_log_path)
     self.assertEqual(['/var/www'], sv1.document_root_paths)
     self.assertEqual('/etc/aws/keys/ssl/https.crt', sv1.ssl_cert_path)
     self.assertEqual('/etc/aws/keys/ssl/https.key', sv1.ssl_key_path)
     with self.assertRaises(NoPathError):
         print sv1.ssl_chain_path
Ejemplo n.º 3
0
    def test_parse_simple_template(self):
        v1 = apache.VirtualHost(simple_template)

        self.assertTrue(v1.body)

        self.assertEqual(80, v1.port)
        v1.port = 8080

        self.assertEqual(8080, v1.port)

        self.assertEqual('dima.com', v1.server_name)
        v1.server_name = 'new.dima.com'
        self.assertEqual(v1.server_name, 'new.dima.com')

        self.assertEqual('/var/log/http-dima.com-access.log',
                         v1.custom_log_path)
        self.assertEqual(['/var/www'], v1.document_root_paths)

        with self.assertRaises(NoPathError):
            print v1.error_log_path
            print v1.ssl_cert_path
            print v1.ssl_key_path
            print v1.ssl_chain_path
Ejemplo n.º 4
0
    def _test_virtual_host_lifecycle(self):
        #TODO: Enable when all system objects are mocked
        #creating objects
        path = self.api.create_vhost('dima.com',
                                     80,
                                     simple_template,
                                     ssl=False)
        cv_path = self.api.create_vhost('custom.dima.com',
                                        8080,
                                        custom_template,
                                        ssl=False)
        ov_path = self.api.create_vhost('old.dima.com',
                                        443,
                                        old_ssl_template,
                                        ssl=True)
        sv_path = self.api.create_vhost(hostname='secure.dima.com',
                                        port=443,
                                        template=ssl_template,
                                        ssl=True,
                                        ssl_certificate_id=1)

        #files created
        self.assertTrue(os.path.exists(path))
        self.assertTrue(os.path.exists(cv_path))
        self.assertTrue(os.path.exists(ov_path))
        self.assertTrue(os.path.exists(sv_path))

        #reading created files
        template = open(path, 'r').read().strip()
        cv_template = open(cv_path, 'r').read().strip()
        ov_template = open(ov_path, 'r').read().strip()
        sv_template = open(sv_path, 'r').read().strip()

        #re-creating objects
        v_host = apache.VirtualHost(template)
        cv_host = apache.VirtualHost(cv_template)
        old_v_host = apache.VirtualHost(ov_template)
        ssl_v_host = apache.VirtualHost(sv_template)

        #asserting ports
        self.assertEqual(80, v_host.port)
        self.assertEqual(8080, cv_host.port)
        self.assertEqual(443, old_v_host.port)
        self.assertEqual(443, ssl_v_host.port)

        #asserting bodies
        self.assertEqual(simple_template, v_host.body)
        self.assertEqual(custom_template, cv_host.body)
        #ssl cert paths changed
        self.assertNotEqual(old_ssl_template, v_host.body)
        self.assertNotEqual(ssl_template, cv_host.body)

        #asserting created paths
        self.assertTrue(os.path.exists(v_host.custom_log_path))
        self.assertTrue(os.path.exists(
            cv_host.custom_log_path))  # TODO: USE DIFFERENT PATHS
        self.assertTrue(os.path.exists(old_v_host.custom_log_path))
        self.assertTrue(os.path.exists(ssl_v_host.custom_log_path))

        self.assertTrue(os.path.exists(v_host.document_root_paths[0]))
        self.assertTrue(os.path.exists(cv_host.document_root_paths[0]))
        self.assertTrue(os.path.exists(old_v_host.document_root_paths[0]))
        self.assertTrue(os.path.exists(ssl_v_host.document_root_paths[0]))

        self.assertTrue(os.path.exists(old_v_host.error_log_path))
        self.assertTrue(os.path.exists(ssl_v_host.error_log_path))

        #each virtual host is served by apache
        self.assertTrue(
            os.path.basename(path) in self.api.list_served_virtual_hosts())
        self.assertTrue(
            os.path.basename(cv_path) in self.api.list_served_virtual_hosts())
        self.assertTrue(
            os.path.basename(ov_path) in self.api.list_served_virtual_hosts())
        self.assertTrue(
            os.path.basename(sv_path) in self.api.list_served_virtual_hosts())
        #TODO: check apache.conf for port
        #TODO: check if service restart occured

        svh_data = ['dima.com', 80, simple_template, False]
        ovh_data = ['old.dima.com', 443, old_ssl_template, True]

        data = ovh_data, svh_data
        self.api.reconfigure(data)

        #Files of removed virtual hosts no longer exist.
        self.assertFalse(os.path.exists(cv_path))
        self.assertFalse(os.path.exists(sv_path))

        #Removed virtual hosts are no longer served by apache
        self.assertFalse(
            os.path.basename(cv_path) in self.api.list_served_virtual_hosts())
        self.assertFalse(
            os.path.basename(sv_path) in self.api.list_served_virtual_hosts())

        #TODO: expand check on reconfigure

        #But reconfigured virtual hosts stil healthy.
        self.assertTrue(os.path.exists(path))
        self.assertTrue(os.path.exists(ov_path))

        #TODO: Update two virtual hosts left

        #removing all created virtual hosts
        signature1 = (v_host.server_name, v_host.port)
        signature2 = (old_v_host.server_name, old_v_host.port)
        hosts_to_remove = (signature1, signature2)
        self.api.delete_vhosts(hosts_to_remove, reload=True)

        #Files of removed virtual hosts no longer exist.
        self.assertFalse(os.path.exists(path))
        self.assertFalse(os.path.exists(ov_path))

        #Removed virtual hosts are no longer served by apache
        self.assertFalse(
            os.path.basename(path) in self.api.list_served_virtual_hosts())
        self.assertFalse(
            os.path.basename(ov_path) in self.api.list_served_virtual_hosts())