Example #1
0
        public void IoTDeployersCanInstallDevices()
        {
            // Arrange
            IIoTDeployer deployer = new IoTDeployer(
                this.config.Object,
                this.mockCA.Object);

            var mockIoTDevice = new Mock <IIoTDevice>();
            var mockDeviceHSM = new Mock <IDeviceHSM>();

            mockDeviceHSM.Setup(hsm => hsm.GetPublicKey)
            .Returns(RSA.Create(1536));
            mockIoTDevice.Setup(d => d.HardwareSecurityModel)
            .Returns(mockDeviceHSM.Object);

            // Act
            deployer.InstallAsync(mockIoTDevice.Object,
                                  "testDPSGlobalEndpoint",
                                  "testDPSScopeId").
            GetAwaiter().GetResult();

            // Assert
            mockDeviceHSM.Verify(hsm =>
                                 hsm.StoreX509Cert(
                                     It.IsAny <X509Certificate2>(),
                                     It.IsAny <X509Certificate2Collection>()));

            mockIoTDevice.Verify(d =>
                                 d.ProvisionAsync(
                                     "testDPSGlobalEndpoint",
                                     "testDPSScopeId"));
        }
Example #2
0
        public void IoTDeployersKnowHowToGenerateAValidDistiguishedName()
        {
            // Arrange
            IIoTDeployer deployer = new IoTDeployer(
                this.config.Object,
                this.mockCA.Object);
            string leafDN  = string.Empty;
            var    pattern = "^CN=[a-z0-9-]+, O=Fabrikam Drone Delivery$";

            // Act
            leafDN = deployer.GenerateLeafCertDistinguishedName("test");

            // Assert
            Assert.False(string.IsNullOrEmpty(leafDN));
            Assert.Matches(pattern, leafDN);
        }