public async Task GetEncryptionKeyAsync_PublicRSA_TimerExpires_Success() { // Arrange int cacheDurationSeconds = 2; var keyResolver = new KeyResolver( new List <JsonWebKey>(), this.publicRsaJwksService.Object, cacheDurationSeconds); // Act var jsonWebKey = await keyResolver.GetEncryptionKeyAsync(); // Initial call to JWKS Thread.Sleep(2050); jsonWebKey = await keyResolver.GetEncryptionKeyAsync(); // Timer expired. Call JWKS Thread.Sleep(1); jsonWebKey = await keyResolver.GetEncryptionKeyAsync(); // Timer not expired. Use cache // Assert this.publicRsaJwksService.Verify(m => m.GetJsonWebKeyListAsync(), Times.Exactly(2)); }
public async Task GetEncryptionKeyAsync_PublicRSA_NoKeysFound_Throws() { // Arrange var keyResolver = new KeyResolver( new List <JsonWebKey>(), this.publicOctJwksService.Object, // Get Oct key this.cacheDurationSeconds); // Act var jsonWebKey = await keyResolver.GetEncryptionKeyAsync(); // Assert // EncryptionException: "Unable to retrieve public EC or RSA key from JWK store.")] }
public async Task GetEncryptionKeyAsync_PublicRSA_Success() { // Arrange var keyResolver = new KeyResolver( new List <JsonWebKey>(), this.publicRsaJwksService.Object, this.cacheDurationSeconds); // Act var jsonWebKey = await keyResolver.GetEncryptionKeyAsync(); // Assert Assert.IsNotNull(jsonWebKey); Assert.IsFalse(jsonWebKey.HasPrivateKey); Assert.AreEqual("RSA", jsonWebKey.Kty); Assert.AreEqual(false, jsonWebKey.HasPrivateKey); Assert.AreEqual("0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw", jsonWebKey.N); Assert.AreEqual("AQAB", jsonWebKey.E); Assert.AreEqual("RS256", jsonWebKey.Alg); Assert.AreEqual("3072F4C6-193D-481B-BDD2-0F09F5A7DDFB", jsonWebKey.Kid); Assert.AreEqual(2048, jsonWebKey.KeySize); }
public async Task GetEncryptionKeyAsync_PublicEC_Success() { // Arrange var keyResolver = new KeyResolver( new List <JsonWebKey>(), this.publicEcJwksService.Object, this.cacheDurationSeconds); // Act var jsonWebKey = await keyResolver.GetEncryptionKeyAsync(); // Assert Assert.IsNotNull(jsonWebKey); Assert.IsFalse(jsonWebKey.HasPrivateKey); Assert.AreEqual("EC", jsonWebKey.Kty); Assert.AreEqual(false, jsonWebKey.HasPrivateKey); Assert.AreEqual("P-256", jsonWebKey.Crv); Assert.AreEqual("MKBCTNIcKUSDii11ySs3526iDZ8AiTo7Tu6KPAqv7D4", jsonWebKey.X); Assert.AreEqual("4Etl6SRW2YiLUrN5vfvVHuhp7x8PxltmWWlbbM4IFyM", jsonWebKey.Y); Assert.AreEqual("enc", jsonWebKey.Use); Assert.AreEqual("B7B4F5C7-2B46-4F54-A81A-51E8A886B094", jsonWebKey.Kid); Assert.AreEqual(256, jsonWebKey.KeySize); }