public void WhenStoreExistingKey_ThenReplacesKey() { var fakeKey = new FakeCryptoKey(); var key = new OAuthCryptoKey { Id = "fooid", Bucket = "foo", Handle = "bar", Key = new byte[] { 0x01, 0x01 }, ExpiresUtc = DateTime.UtcNow, }; this.storage.Setup(s => s.Find(It.IsAny <string>())) .Returns(new[] { key }); this.store.StoreKey("foo", "bar", fakeKey); this.storage.Verify(s => s.Delete("fooid"), Times.Once()); this.storage.Verify(s => s.Add(It.Is <OAuthCryptoKey>(ack => ack.Bucket == "foo" && ack.Handle == "bar" && ack.ExpiresUtc == DateTime.Today.ToUniversalTime())), Times.Once()); }
public void WhenGetKeyWithKnownKey_ThenReturnsKey() { var key = new OAuthCryptoKey { Bucket = "foo", Handle = "bar", Key = new byte[] { 0x01, 0x01 }, ExpiresUtc = DateTime.UtcNow, }; this.storage.Setup(s => s.Find(It.IsAny <string>())) .Returns(new[] { key }); var result = this.store.GetKey("foo", "bar"); Assert.Equal(key.Key, result.Key); Assert.Equal(key.ExpiresUtc, result.ExpiresUtc); }
public void WhenRemoveKeyWithKnownHandle_ThenReturnsKeys() { var key = new OAuthCryptoKey { Id = "fooid", Bucket = "foo", Handle = "bar", Key = new byte[] { 0x01, 0x01 }, ExpiresUtc = DateTime.UtcNow, }; this.storage.Setup(s => s.Find(It.IsAny <string>())) .Returns(new[] { key }); this.store.RemoveKey("foo", "bar"); this.storage.Verify(s => s.Delete("fooid"), Times.Once()); }
public void WhenGetKeys_ThenReturnsKeys() { var key = new OAuthCryptoKey { Bucket = "foo", Handle = "bar", Key = new byte[] { 0x01, 0x01 }, ExpiresUtc = DateTime.UtcNow, }; this.storage.Setup(s => s.Find(It.IsAny <string>())) .Returns(new[] { key }); var keys = this.store.GetKeys("foo"); Assert.Equal(1, keys.Count()); }