def test_policy_disallow_create(self):
     bay = obj_utils.create_test_bay(self.context)
     cert = api_utils.cert_post_data(bay_uuid=bay.uuid)
     self._common_policy_check("certificate:create",
                               self.post_json,
                               '/certificates',
                               cert,
                               expect_errors=True)
Example #2
0
 def test_policy_disallow_create(self):
     cluster = obj_utils.create_test_cluster(self.context)
     cert = api_utils.cert_post_data(cluster_uuid=cluster.uuid)
     self._common_policy_check("certificate:create",
                               self.post_json,
                               '/certificates',
                               cert,
                               expect_errors=True)
Example #3
0
    def test_create_cert(self, ):
        new_cert = apiutils.cert_post_data(bay_uuid=self.bay.uuid)
        del new_cert['pem']

        response = self.post_json('/certificates', new_cert)
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(201, response.status_int)
        self.assertEqual(new_cert['bay_uuid'], response.json['bay_uuid'])
        self.assertEqual('fake-pem', response.json['pem'])
Example #4
0
    def test_create_cert_by_cluster_name(self, ):
        new_cert = api_utils.cert_post_data(cluster_uuid=self.cluster.name)
        del new_cert['pem']

        response = self.post_json('/certificates', new_cert, headers=HEADERS)

        self.assertEqual('application/json', response.content_type)
        self.assertEqual(201, response.status_int)
        self.assertEqual(self.cluster.uuid, response.json['cluster_uuid'])
        self.assertEqual('fake-pem', response.json['pem'])
Example #5
0
    def test_create_cert_by_cluster_name(self, ):
        new_cert = api_utils.cert_post_data(cluster_uuid=self.cluster.name)
        del new_cert['pem']

        response = self.post_json('/certificates', new_cert)

        self.assertEqual('application/json', response.content_type)
        self.assertEqual(201, response.status_int)
        self.assertEqual(self.cluster.uuid, response.json['cluster_uuid'])
        self.assertEqual('fake-pem', response.json['pem'])
Example #6
0
    def test_create_cert_bay_not_found(self, ):
        new_cert = apiutils.cert_post_data(bay_uuid='not_found')
        del new_cert['pem']

        response = self.post_json('/certificates', new_cert,
                                  expect_errors=True)

        self.assertEqual(400, response.status_int)
        self.assertEqual('application/json', response.content_type)
        self.assertTrue(response.json['error_message'])
Example #7
0
    def test_create_cert_cluster_not_found(self, ):
        new_cert = api_utils.cert_post_data(cluster_uuid='not_found')
        del new_cert['pem']

        response = self.post_json('/certificates', new_cert,
                                  expect_errors=True, headers=HEADERS)

        self.assertEqual(400, response.status_int)
        self.assertEqual('application/json', response.content_type)
        self.assertTrue(response.json['errors'])
Example #8
0
    def test_cert_init(self, mock_get_rpc_resource):
        cert_dict = apiutils.cert_post_data()
        mock_bay = mock.MagicMock()
        mock_bay.uuid = cert_dict['bay_uuid']
        mock_get_rpc_resource.return_value = mock_bay

        cert = api_cert.Certificate(**cert_dict)

        self.assertEqual(cert_dict['bay_uuid'], cert.bay_uuid)
        self.assertEqual(cert_dict['csr'], cert.csr)
        self.assertEqual(cert_dict['pem'], cert.pem)
Example #9
0
    def test_rotate_ca_cert(self, mock_policy):
        mock_policy.return_value = True
        fake_cert = api_utils.cert_post_data()
        mock_cert = mock.MagicMock()
        mock_cert.as_dict.return_value = fake_cert
        self.conductor_api.rotate_ca_certificate.return_value = mock_cert

        response = self.patch_json('/certificates/%s' % self.cluster.uuid,
                                   params={}, headers=HEADERS)

        self.assertEqual(202, response.status_code)
Example #10
0
    def test_get_one_by_name(self):
        fake_cert = apiutils.cert_post_data()
        mock_cert = mock.MagicMock()
        mock_cert.as_dict.return_value = fake_cert
        self.conductor_api.get_ca_certificate.return_value = mock_cert

        response = self.get_json('/certificates/%s' % self.bay.name)

        self.assertEqual(self.bay.uuid, response['bay_uuid'])
        self.assertEqual(fake_cert['csr'], response['csr'])
        self.assertEqual(fake_cert['pem'], response['pem'])
Example #11
0
    def test_create_cert(self, ):
        new_cert = api_utils.cert_post_data(cluster_uuid=self.cluster.uuid)
        del new_cert['pem']

        response = self.post_json('/certificates', new_cert, headers=HEADERS)
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(201, response.status_int)
        self.assertEqual(new_cert['cluster_uuid'],
                         response.json['cluster_uuid'])
        # verify bay_uuid is still valid as well
        self.assertEqual(new_cert['cluster_uuid'], response.json['bay_uuid'])
        self.assertEqual('fake-pem', response.json['pem'])
Example #12
0
    def test_create_cert(self, ):
        new_cert = api_utils.cert_post_data(cluster_uuid=self.cluster.uuid)
        del new_cert['pem']

        response = self.post_json('/certificates', new_cert)
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(201, response.status_int)
        self.assertEqual(new_cert['cluster_uuid'],
                         response.json['cluster_uuid'])
        # verify bay_uuid is still valid as well
        self.assertEqual(new_cert['cluster_uuid'], response.json['bay_uuid'])
        self.assertEqual('fake-pem', response.json['pem'])
Example #13
0
    def test_rotate_ca_cert_non_tls(self, mock_policy):
        mock_policy.return_value = True
        fake_cert = api_utils.cert_post_data()
        mock_cert = mock.MagicMock()
        mock_cert.as_dict.return_value = fake_cert
        self.conductor_api.rotate_ca_certificate.return_value = mock_cert

        response = self.patch_json('/certificates/%s' % self.cluster.uuid,
                                   params={}, headers=HEADERS,
                                   expect_errors=True)
        self.assertEqual(400, response.status_code)
        self.assertIn("Rotating the CA certificate on a non-TLS cluster",
                      response.json['errors'][0]['detail'])
Example #14
0
    def test_get_one(self):
        fake_cert = api_utils.cert_post_data()
        mock_cert = mock.MagicMock()
        mock_cert.as_dict.return_value = fake_cert
        self.conductor_api.get_ca_certificate.return_value = mock_cert

        response = self.get_json('/certificates/%s' % self.cluster.uuid)

        self.assertEqual(self.cluster.uuid, response['cluster_uuid'])
        # check that bay is still valid as well
        self.assertEqual(self.cluster.uuid, response['bay_uuid'])
        self.assertEqual(fake_cert['csr'], response['csr'])
        self.assertEqual(fake_cert['pem'], response['pem'])
Example #15
0
    def test_get_one(self):
        fake_cert = api_utils.cert_post_data()
        mock_cert = mock.MagicMock()
        mock_cert.as_dict.return_value = fake_cert
        self.conductor_api.get_ca_certificate.return_value = mock_cert

        response = self.get_json('/certificates/%s' % self.cluster.uuid)

        self.assertEqual(self.cluster.uuid, response['cluster_uuid'])
        # check that bay is still valid as well
        self.assertEqual(self.cluster.uuid, response['bay_uuid'])
        self.assertEqual(fake_cert['csr'], response['csr'])
        self.assertEqual(fake_cert['pem'], response['pem'])
Example #16
0
    def test_links(self):
        fake_cert = apiutils.cert_post_data()
        mock_cert = mock.MagicMock()
        mock_cert.as_dict.return_value = fake_cert
        self.conductor_api.get_ca_certificate.return_value = mock_cert

        response = self.get_json('/certificates/%s' % self.bay.uuid)

        self.assertIn('links', response.keys())
        self.assertEqual(2, len(response['links']))
        self.assertIn(self.bay.uuid, response['links'][0]['href'])
        for l in response['links']:
            bookmark = l['rel'] == 'bookmark'
            self.assertTrue(self.validate_link(l['href'], bookmark=bookmark))
Example #17
0
 def test_policy_disallow_create(self):
     cert = apiutils.cert_post_data()
     self._common_policy_check("certificate:create", self.post_json,
                               '/certificates', cert)
Example #18
0
 def test_policy_disallow_create(self):
     cert = apiutils.cert_post_data()
     self._common_policy_check(
         "certificate:create", self.post_json, '/certificates', cert)
Example #19
0
 def test_policy_disallow_create(self):
     cluster = obj_utils.create_test_cluster(self.context)
     cert = api_utils.cert_post_data(cluster_uuid=cluster.uuid)
     self._common_policy_check(
         "certificate:create", self.post_json, '/certificates', cert,
         expect_errors=True)
Example #20
0
 def test_policy_disallow_create(self):
     bay = obj_utils.create_test_bay(self.context)
     cert = apiutils.cert_post_data(bay_uuid=bay.uuid)
     self._common_policy_check(
         "certificate:create", self.post_json, '/certificates', cert,
         expect_errors=True)