Example #1
0
        public async Task RoundtripTokenCredentialsWithEncryptionTest()
        {
            // Arrange
            string iothubHostName    = "iothub1.azure.net";
            string callerProductInfo = "productInfo";
            string sasToken          = TokenHelper.CreateSasToken($"{iothubHostName}/devices/device1/modules/moduleId");
            var    identity          = Mock.Of <IIdentity>(i => i.Id == "d1");
            var    credentials       = new TokenCredentials(identity, sasToken, callerProductInfo);

            var            dbStoreProvider       = new InMemoryDbStoreProvider();
            IStoreProvider storeProvider         = new StoreProvider(dbStoreProvider);
            var            tokenCredentialsStore = new TokenCredentialsStore(storeProvider.GetEntityStore <string, string>("tokenCredentials"), new TestEncryptionProvider());

            // Act
            await tokenCredentialsStore.Add(credentials);

            Option <IClientCredentials> storedCredentials = await tokenCredentialsStore.Get(identity);

            // Assert
            Assert.True(storedCredentials.HasValue);
            var storedTokenCredentials = storedCredentials.OrDefault() as ITokenCredentials;

            Assert.NotNull(storedTokenCredentials);
            Assert.Equal(sasToken, storedTokenCredentials.Token);
        }
Example #2
0
        public async Task RoundtripNonTokenCredentialsTest()
        {
            // Arrange
            string callerProductInfo = "productInfo";
            var    identity          = Mock.Of <IIdentity>(i => i.Id == "d1");
            var    credentials       = new X509CertCredentials(identity, callerProductInfo);

            var            dbStoreProvider       = new InMemoryDbStoreProvider();
            IStoreProvider storeProvider         = new StoreProvider(dbStoreProvider);
            var            tokenCredentialsStore = new TokenCredentialsStore(storeProvider.GetEntityStore <string, string>("tokenCredentials"), new NullEncryptionProvider());

            // Act
            await tokenCredentialsStore.Add(credentials);

            Option <IClientCredentials> storedCredentials = await tokenCredentialsStore.Get(identity);

            // Assert
            Assert.False(storedCredentials.HasValue);
        }