public void IoTCompanyMakeIoTDeviceThrowsExceptionCauseFailedEnrollmentGroupCreation() { // Arrange var mockProvisioningService = new Mock <IProvisioningService>(); mockProvisioningService .Setup( pS => pS.CleanUpAndCreateEnrollmentGroupAsync( It.IsAny <Attestation>())) .Returns(Task.FromResult(false)); var mockFactory = new Mock <IIoTHardwareIntegrator>(); mockFactory .Setup( f => f.ManufactureAsync(It.IsAny <string>(), It.IsAny <string>())) .Returns( Task.FromResult <IIoTDevice>(new Mock <IIoTDevice>().Object)); IIoTCompany company = new IoTCompany( this.config.Object, mockProvisioningService.Object, mockFactory.Object); // Act & Assert company.CleanUpAndCreateEnrollmentGroupAsync().GetAwaiter().GetResult(); Assert.Throws <InvalidOperationException>( () => company.MakeDeviceAsync().GetAwaiter().GetResult()); }
public void IoTCompanyMakeAnIoTDeviceSucessfully() { // Arrange var mockProvisioningService = new Mock <IProvisioningService>(); mockProvisioningService .Setup( pS => pS.CleanUpAndCreateEnrollmentGroupAsync( It.IsAny <Attestation>())) .Returns(Task.FromResult(true)); var mockFactory = new Mock <IIoTHardwareIntegrator>(); mockFactory .Setup( f => f.ManufactureAsync(It.IsAny <string>(), It.IsAny <string>())) .Returns( Task.FromResult <IIoTDevice>(new Mock <IIoTDevice>().Object)); IIoTCompany company = new IoTCompany( this.config.Object, mockProvisioningService.Object, mockFactory.Object); IIoTDevice brandNewIoTDevice = null; // Act company.CleanUpAndCreateEnrollmentGroupAsync().GetAwaiter().GetResult(); brandNewIoTDevice = company.MakeDeviceAsync().GetAwaiter().GetResult(); // Assert Assert.NotNull(brandNewIoTDevice); mockFactory.Verify(f => f.ManufactureAsync(It.IsAny <string>(), It.IsAny <string>())); }
public void RootCADoesntHaveParentCAAndIsProperlyInitialized() { // Arrange IRootCertificateAuthority rootCA = null; var provisioningService = new Mock <IProvisioningService>().Object; // Act rootCA = new IoTCompany(this.config.Object, provisioningService); // Assert Assert.Null(rootCA.ParentCertificateAuthority); Assert.NotNull(rootCA.personalSignedX509Certificate); }
public void CAIsAbleToAcquireAValidSelfSignedCert() { // Arrange var provisioningService = new Mock <IProvisioningService>().Object; IRootCertificateAuthority rootCA = new IoTCompany(this.config.Object, provisioningService); X509Certificate2 justAnotherSelfSignedCert = null; // Act justAnotherSelfSignedCert = rootCA.AcquireSelfSignedCrt(); // Assert Assert.NotNull(justAnotherSelfSignedCert); // TODO: future PR if team says "go", improve assertions here }
public void CAIsAbleToSignCerts() { // Arrange IConfig config = this.config.Object; var provisioningService = new Mock <IProvisioningService>().Object; IRootCertificateAuthority rootCA = new IoTCompany( config, provisioningService); ICertificateAuthority intermedCA = new IoTHardwareIntegrator(config, rootCA); X509Certificate2 signedCrt = null; // Act signedCrt = intermedCA.CreateSignedCrt(this.leafCsr); // Assert Assert.NotNull(signedCrt); // TODO: future PR if team says "go", improve assertions here: isCa false, subject, etc. }
public void CAIsAbleToAcquireAValidCertAndIsProperlyInitialized() { // Arrange IConfig config = this.config.Object; var provisioningService = new Mock <IProvisioningService>().Object; IRootCertificateAuthority rootCA = new IoTCompany( config, provisioningService); ICertificateAuthority intermedCA = null; // Act intermedCA = new IoTHardwareIntegrator(config, rootCA); // Assert Assert.NotNull(intermedCA.personalSignedX509Certificate); Assert.NotNull(intermedCA.ParentCertificateAuthority); Assert.Equal(rootCA, intermedCA.ParentCertificateAuthority); Assert.False(intermedCA.personalSignedX509Certificate.HasPrivateKey); }
private static async Task RunDeviceConnectivitySupplyChain() { using (var iotCompany = new IoTCompany( RuntimeConfig, ProvisioningService)) { // ******** Azure IoT Hub DPS Service ******** // 1. Create a Enrollment Group if not exists Console.Write($"\nCreating a new Enrollment Group: {RuntimeConfig.AzureDPSEnrollmentGroup}..."); await iotCompany.CleanUpAndCreateEnrollmentGroupAsync().ConfigureAwait(false); Console.Write($"OK!\n"); // 2. Go over the PoP await iotCompany.KickoffPoPAsync().ConfigureAwait(false); // ******** Azure IoT Hub DPS Service ******** // 3. Supply Chain with Device Provisioning Console.Write("\nMaking and provisioning a new IoT Device to IoT Hub..."); var brandNewIoTDevice = await iotCompany.MakeDeviceAsync().ConfigureAwait(false); Console.Write($"OK!\n"); // 4. Start sending telemetry Console.Write($"\nAuthenticating {brandNewIoTDevice.DeviceID} and send telemetry sample message..."); await brandNewIoTDevice.AuthNAndSendTelemetryAsync().ConfigureAwait(false); Console.Write($"OK!\n"); Console.WriteLine("\nPress any key to continue..."); Console.ReadKey(); } }