示例#1
0
 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)
示例#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)
示例#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'])
示例#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'])
示例#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'])
示例#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'])
示例#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'])
示例#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)
示例#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)
示例#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'])
示例#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'])
示例#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'])
示例#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'])
示例#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'])
示例#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'])
示例#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))
示例#17
0
 def test_policy_disallow_create(self):
     cert = apiutils.cert_post_data()
     self._common_policy_check("certificate:create", self.post_json,
                               '/certificates', cert)
示例#18
0
 def test_policy_disallow_create(self):
     cert = apiutils.cert_post_data()
     self._common_policy_check(
         "certificate:create", self.post_json, '/certificates', cert)
示例#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)
示例#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)