class ManagementCertificateManagementServiceTest(AzureTestCase):
    def setUp(self):
        self.sms = ServiceManagementService(
            credentials.getSubscriptionId(),
            credentials.getManagementCertFile())
        set_service_options(self.sms)

        self.certificate_thumbprints = []

    def tearDown(self):
        for thumbprint in self.certificate_thumbprints:
            try:
                self.sms.delete_management_certificate(thumbprint)
            except:
                pass

    #--Helpers-----------------------------------------------------------------
    def _create_management_certificate(self, cert):
        self.certificate_thumbprints.append(cert.thumbprint)
        result = self.sms.add_management_certificate(cert.public_key,
                                                     cert.thumbprint,
                                                     cert.data)
        self.assertIsNone(result)

    def _management_certificate_exists(self, thumbprint):
        try:
            props = self.sms.get_management_certificate(thumbprint)
            return props is not None
        except:
            return False

    #--Test cases for management certificates ----------------------------
    def test_list_management_certificates(self):
        # Arrange
        local_cert = _local_certificate()
        self._create_management_certificate(local_cert)

        # Act
        result = self.sms.list_management_certificates()

        # Assert
        self.assertIsNotNone(result)
        self.assertTrue(len(result) > 0)

        cert = None
        for temp in result:
            if temp.subscription_certificate_thumbprint == \
                local_cert.thumbprint:
                cert = temp
                break

        self.assertIsNotNone(cert)
        self.assertIsNotNone(cert.created)
        self.assertEqual(cert.subscription_certificate_public_key,
                         local_cert.public_key)
        self.assertEqual(cert.subscription_certificate_data, local_cert.data)
        self.assertEqual(cert.subscription_certificate_thumbprint,
                         local_cert.thumbprint)

    def test_get_management_certificate(self):
        # Arrange
        local_cert = _local_certificate()
        self._create_management_certificate(local_cert)

        # Act
        result = self.sms.get_management_certificate(local_cert.thumbprint)

        # Assert
        self.assertIsNotNone(result)
        self.assertIsNotNone(result.created)
        self.assertEqual(result.subscription_certificate_public_key,
                         local_cert.public_key)
        self.assertEqual(result.subscription_certificate_data, local_cert.data)
        self.assertEqual(result.subscription_certificate_thumbprint,
                         local_cert.thumbprint)

    def test_add_management_certificate(self):
        # Arrange
        local_cert = _local_certificate()

        # Act
        self.certificate_thumbprints.append(local_cert.thumbprint)
        result = self.sms.add_management_certificate(local_cert.public_key,
                                                     local_cert.thumbprint,
                                                     local_cert.data)

        # Assert
        self.assertIsNone(result)
        self.assertTrue(
            self._management_certificate_exists(local_cert.thumbprint))

    def test_delete_management_certificate(self):
        # Arrange
        local_cert = _local_certificate()
        self._create_management_certificate(local_cert)

        # Act
        result = self.sms.delete_management_certificate(local_cert.thumbprint)

        # Assert
        self.assertIsNone(result)
        self.assertFalse(
            self._management_certificate_exists(local_cert.thumbprint))
Exemplo n.º 2
0
class ManagementCertificateManagementServiceTest(AzureTestCase):

    def setUp(self):
        proxy_host = credentials.getProxyHost()
        proxy_port = credentials.getProxyPort()

        self.sms = ServiceManagementService(credentials.getSubscriptionId(), credentials.getManagementCertFile())
        if proxy_host:
            self.sms.set_proxy(proxy_host, proxy_port)

        self.management_certificate_name = getUniqueNameBasedOnCurrentTime('utmgmtcert')

    def tearDown(self):
        try:
            self.sms.delete_management_certificate(self.management_certificate_name)
        except: pass

    #--Helpers-----------------------------------------------------------------
    def _create_management_certificate(self, thumbprint):
        result = self.sms.add_management_certificate(MANAGEMENT_CERT_PUBLICKEY, thumbprint, MANAGEMENT_CERT_DATA)
        self.assertIsNone(result)

    def _management_certificate_exists(self, thumbprint):
        try:
            props = self.sms.get_management_certificate(thumbprint)
            return props is not None
        except:
            return False

    #--Test cases for management certificates ----------------------------
    def test_list_management_certificates(self):
        # Arrange
        self._create_management_certificate(self.management_certificate_name)

        # Act
        result = self.sms.list_management_certificates()

        # Assert
        self.assertIsNotNone(result)
        self.assertTrue(len(result) > 0)
        
        cert = None
        for temp in result:
            if temp.subscription_certificate_thumbprint == self.management_certificate_name:
                cert = temp
                break

        self.assertIsNotNone(cert)
        self.assertIsNotNone(cert.created)
        self.assertEqual(cert.subscription_certificate_public_key, MANAGEMENT_CERT_PUBLICKEY)
        self.assertEqual(cert.subscription_certificate_data, MANAGEMENT_CERT_DATA)
        self.assertEqual(cert.subscription_certificate_thumbprint, self.management_certificate_name)

    def test_get_management_certificate(self):
        # Arrange
        self._create_management_certificate(self.management_certificate_name)

        # Act
        result = self.sms.get_management_certificate(self.management_certificate_name)

        # Assert
        self.assertIsNotNone(result)
        self.assertIsNotNone(result.created)
        self.assertEqual(result.subscription_certificate_public_key, MANAGEMENT_CERT_PUBLICKEY)
        self.assertEqual(result.subscription_certificate_data, MANAGEMENT_CERT_DATA)
        self.assertEqual(result.subscription_certificate_thumbprint, self.management_certificate_name)

    def test_add_management_certificate(self):
        # Arrange
        public_key = MANAGEMENT_CERT_PUBLICKEY
        data = MANAGEMENT_CERT_DATA

        # Act
        result = self.sms.add_management_certificate(public_key, self.management_certificate_name, data)

        # Assert
        self.assertIsNone(result)
        self.assertTrue(self._management_certificate_exists(self.management_certificate_name))

    def test_delete_management_certificate(self):
        # Arrange
        self._create_management_certificate(self.management_certificate_name)

        # Act
        result = self.sms.delete_management_certificate(self.management_certificate_name)

        # Assert
        self.assertIsNone(result)
        self.assertFalse(self._management_certificate_exists(self.management_certificate_name))
class ManagementCertificateManagementServiceTest(AzureTestCase):

    def setUp(self):
        self.sms = ServiceManagementService(credentials.getSubscriptionId(),
                                            credentials.getManagementCertFile())

        self.sms.set_proxy(credentials.getProxyHost(),
                           credentials.getProxyPort(),
                           credentials.getProxyUser(),
                           credentials.getProxyPassword())

        self.certificate_thumbprints = []

    def tearDown(self):
        for thumbprint in self.certificate_thumbprints:
            try:
                self.sms.delete_management_certificate(thumbprint)
            except: pass

    #--Helpers-----------------------------------------------------------------
    def _create_management_certificate(self, cert):
        self.certificate_thumbprints.append(cert.thumbprint)
        result = self.sms.add_management_certificate(cert.public_key, 
                                                     cert.thumbprint, 
                                                     cert.data)
        self.assertIsNone(result)

    def _management_certificate_exists(self, thumbprint):
        try:
            props = self.sms.get_management_certificate(thumbprint)
            return props is not None
        except:
            return False

    #--Test cases for management certificates ----------------------------
    def test_list_management_certificates(self):
        # Arrange
        local_cert = _local_certificate()
        self._create_management_certificate(local_cert)

        # Act
        result = self.sms.list_management_certificates()

        # Assert
        self.assertIsNotNone(result)
        self.assertTrue(len(result) > 0)
        
        cert = None
        for temp in result:
            if temp.subscription_certificate_thumbprint == local_cert.thumbprint:
                cert = temp
                break

        self.assertIsNotNone(cert)
        self.assertIsNotNone(cert.created)
        self.assertEqual(cert.subscription_certificate_public_key, local_cert.public_key)
        self.assertEqual(cert.subscription_certificate_data, local_cert.data)
        self.assertEqual(cert.subscription_certificate_thumbprint, local_cert.thumbprint)

    def test_get_management_certificate(self):
        # Arrange
        local_cert = _local_certificate()
        self._create_management_certificate(local_cert)

        # Act
        result = self.sms.get_management_certificate(local_cert.thumbprint)

        # Assert
        self.assertIsNotNone(result)
        self.assertIsNotNone(result.created)
        self.assertEqual(result.subscription_certificate_public_key, local_cert.public_key)
        self.assertEqual(result.subscription_certificate_data, local_cert.data)
        self.assertEqual(result.subscription_certificate_thumbprint, local_cert.thumbprint)

    def test_add_management_certificate(self):
        # Arrange
        local_cert = _local_certificate()

        # Act
        self.certificate_thumbprints.append(local_cert.thumbprint)
        result = self.sms.add_management_certificate(local_cert.public_key,
                                                     local_cert.thumbprint,
                                                     local_cert.data)

        # Assert
        self.assertIsNone(result)
        self.assertTrue(self._management_certificate_exists(local_cert.thumbprint))

    def test_delete_management_certificate(self):
        # Arrange
        local_cert = _local_certificate()
        self._create_management_certificate(local_cert)

        # Act
        result = self.sms.delete_management_certificate(local_cert.thumbprint)

        # Assert
        self.assertIsNone(result)
        self.assertFalse(self._management_certificate_exists(local_cert.thumbprint))