def test_update_with_pnp_and_no_models_fails(self): with self.assertRaises(CLIError) as context: update(self, test_id=self.test_id, badge_type=BadgeType.Pnp.value) self.assertEqual( "If badge type is Pnp, models is required", str(context.exception) )
def test_update_symmetric_key_to_cert(self, mock_from_get, mock_sdk_update, mock_read_certificate): mock_read_certificate.return_value = "MockBase64String" mock_test_data = { "certificationBadgeConfigurations": [{ "type": "IotDevice" }], "deviceType": "DevKit", "id": self.test_id, "productId": "product_1234", "provisioningConfiguration": { "deviceConnectionString": None, "deviceId": "device_1234", "dpsRegistrationId": "DPS_1234", "region": "region_1", "symmetricKeyEnrollmentInformation": { "primaryKey": "primary_key", "registrationId": "registration_1234", "scopeId": "scope_1", "secondaryKey": "secondary_key", }, "tpmEnrollmentInformation": None, "type": "SymmetricKey", "x509EnrollmentInformation": None, }, "validationType": "Certification", } return_data = mock.Mock() return_data.response.json.return_value = mock_test_data mock_from_get.return_value = return_data update( self, test_id=self.test_id, attestation_type=AttestationType.x509.value, certificate_path="mycertificate.cer", ) mock_read_certificate.assert_called_with("mycertificate.cer") mock_sdk_update.assert_called_with( device_test_id=self.test_id, generate_provisioning_configuration=True, raw=True, body={ "certificationBadgeConfigurations": [{ "type": "IotDevice" }], "deviceType": "DevKit", "id": self.test_id, "productId": "product_1234", "provisioningConfiguration": { "dpsRegistrationId": "DPS_1234", "type": AttestationType.x509.value, "x509EnrollmentInformation": { "base64EncodedX509Certificate": "MockBase64String" }, }, "validationType": "Certification", }, )
def test_update_with_tpm_and_no_endorsement_key_fails(self): with self.assertRaises(CLIError) as context: update(self, test_id=self.test_id, attestation_type=AttestationType.tpm.value) self.assertEqual( "If attestation type is tpm, endorsement key is required", str(context.exception), )
def test_update_with_x509_and_no_certificate_fails(self): with self.assertRaises(CLIError) as context: update(self, test_id=self.test_id, attestation_type=AttestationType.x509.value) self.assertEqual( "If attestation type is x509, certificate path is required", str(context.exception), )
def test_update_from_file(self, mock_from_file, mock_sdk_update): mock_file_data = {"mock": "data"} mock_from_file.return_value = mock_file_data update(self, test_id=self.test_id, configuration_file="somefile") mock_from_file.assert_called_with("somefile") mock_sdk_update.assert_called_with( device_test_id=self.test_id, generate_provisioning_configuration=False, body=mock_file_data, raw=True, )
def test_edge_module_without_connection_string_fails(self): with self.assertRaises(CLIError) as context: update( self, test_id=self.test_id, attestation_type=AttestationType.connectionString.value, badge_type=BadgeType.IotEdgeCompatible.value, ) self.assertEqual( "Connection string is required for Edge Compatible modules testing", str(context.exception), )
def test_connection_string_for_pnp_fails(self): with self.assertRaises(CLIError) as context: update( self, test_id=self.test_id, attestation_type=AttestationType.connectionString.value, badge_type=BadgeType.Pnp.value, models="./stuff", ) self.assertEqual( "Connection string is only available for Edge Compatible modules testing", str(context.exception), )
def test_update_pnp_to_iotdevice(self, mock_from_get, mock_sdk_update, mock_process_models): mock_test_data = { "certificationBadgeConfigurations": [{ "type": BadgeType.Pnp.value, "digitalTwinModelDefinitions": [ '{"@id":"model1"}', '{"@id":"model2"}', '{"@id":"model3"}', ], }], "deviceType": "DevKit", "id": self.test_id, "productId": "product_1234", "provisioningConfiguration": { "deviceConnectionString": None, "deviceId": "device_1234", "dpsRegistrationId": "DPS_1234", "region": "region_1", "symmetricKeyEnrollmentInformation": { "primaryKey": "primary_key", "registrationId": "registration_1234", "scopeId": "scope_1", "secondaryKey": "secondary_key", }, "tpmEnrollmentInformation": None, "type": "SymmetricKey", "x509EnrollmentInformation": None, }, "validationType": "Certification", } return_data = mock.Mock() return_data.response.json.return_value = mock_test_data mock_from_get.return_value = return_data update(self, test_id=self.test_id, badge_type=BadgeType.IotDevice.value) mock_process_models.assert_not_called() mock_sdk_update.assert_called_with( device_test_id=self.test_id, generate_provisioning_configuration=False, raw=True, body={ "certificationBadgeConfigurations": [{ "type": BadgeType.IotDevice.value, }], "deviceType": "DevKit", "id": self.test_id, "productId": "product_1234", "provisioningConfiguration": { "deviceConnectionString": None, "deviceId": "device_1234", "dpsRegistrationId": "DPS_1234", "region": "region_1", "symmetricKeyEnrollmentInformation": { "primaryKey": "primary_key", "registrationId": "registration_1234", "scopeId": "scope_1", "secondaryKey": "secondary_key", }, "tpmEnrollmentInformation": None, "type": "SymmetricKey", "x509EnrollmentInformation": None, }, "validationType": "Certification", }, )