Exemplo n.º 1
0
        public async Task SmokeTest()
        {
            // Arrange
            IEncryptionProvider                 encryptionProvider = new TestEncryptionProvider();
            IEntityStore <string, string>       entityStore        = GetEntityStore <string, string>("smokeTest");
            IKeyValueStore <string, TestDevice> encryptedStore     = new EncryptedStore <string, TestDevice>(entityStore, encryptionProvider);
            string key    = "device1";
            var    device = new TestDevice(Guid.NewGuid().ToString(), new KeyAuth(Guid.NewGuid().ToString()));

            // Act / Assert
            bool contains = await encryptedStore.Contains("device1");

            Assert.False(contains);

            await encryptedStore.Put(key, device);

            contains = await encryptedStore.Contains("device1");

            Assert.True(contains);

            Option <TestDevice> retrievedValue = await encryptedStore.Get("device1");

            Assert.True(retrievedValue.HasValue);
            Assert.Equal(device.GenId, retrievedValue.OrDefault().GenId);
            Assert.Equal(device.Auth.Key, retrievedValue.OrDefault().Auth.Key);

            Option <string> storedValue = await entityStore.Get("device1");

            Assert.True(storedValue.HasValue);

            string deviceJson          = JsonConvert.SerializeObject(device);
            string encryptedDeviceJson = Convert.ToBase64String(Encoding.UTF8.GetBytes(deviceJson));

            Assert.Equal(encryptedDeviceJson, storedValue.OrDefault());

            retrievedValue = await encryptedStore.Get("device2");

            Assert.False(retrievedValue.HasValue);

            await encryptedStore.Remove("device1");

            contains = await encryptedStore.Contains("device1");

            Assert.False(contains);

            retrievedValue = await encryptedStore.Get("device1");

            Assert.False(retrievedValue.HasValue);
        }
Exemplo n.º 2
0
        public async Task KeyResetTest()
        {
            // Arrange
            var encryptionProvider = new ResettableEncryptionProvider();
            IEntityStore <string, string>       entityStore    = GetEntityStore <string, string>("smokeTest");
            IKeyValueStore <string, TestDevice> encryptedStore = new EncryptedStore <string, TestDevice>(entityStore, encryptionProvider);
            string key    = "device1";
            var    device = new TestDevice(Guid.NewGuid().ToString(), new KeyAuth(Guid.NewGuid().ToString()));

            // Act / Assert
            bool contains = await encryptedStore.Contains("device1");

            Assert.False(contains);

            await encryptedStore.Put(key, device);

            contains = await encryptedStore.Contains("device1");

            Assert.True(contains);

            Option <TestDevice> retrievedValue = await encryptedStore.Get("device1");

            Assert.True(retrievedValue.HasValue);
            Assert.Equal(device.GenId, retrievedValue.OrDefault().GenId);
            Assert.Equal(device.Auth.Key, retrievedValue.OrDefault().Auth.Key);

            encryptionProvider.Reset();

            retrievedValue = await encryptedStore.Get("device1");

            Assert.False(retrievedValue.HasValue);

            contains = await encryptedStore.Contains("device1");

            Assert.False(contains);

            await encryptedStore.Put(key, device);

            contains = await encryptedStore.Contains("device1");

            Assert.True(contains);

            retrievedValue = await encryptedStore.Get("device1");

            Assert.True(retrievedValue.HasValue);
            Assert.Equal(device.GenId, retrievedValue.OrDefault().GenId);
            Assert.Equal(device.Auth.Key, retrievedValue.OrDefault().Auth.Key);
        }