public void GetJwtPublicKeyReturnsValue() { using (var authDelegatingHandler = new AuthDelegatingHandler() { InnerHandler = _handler }) using (var httpClient = new HttpClient(authDelegatingHandler)) using (var memoryCache = new MemoryCache(new MemoryCacheOptions())) { var fakeClock = new FakeClock(Instant.FromUtc(2019, 05, 07, 2, 3)); var options = new ActionstepServiceConfigurationOptions("clientId", "clientSecret"); var tokenSetRepository = new TestTokenSetRepository(); IActionstepService actionstepService = new ActionstepService(new NullLogger <ActionstepService>(), httpClient, options, tokenSetRepository, fakeClock, memoryCache); var receivedPublicKeyJObject = actionstepService.GetJwtPublicKeyData(); var receivedPublicKey = receivedPublicKeyJObject.Value <string>(JwtPublicKeyIds.ProdPublicKey); const string EXPECTED_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp2ikRwK8OpklNc3U9y2n\n3JE+B1sQftl8TbZs++PHiActfqHqVbdh2n8Pjaft2NDGB9BXOEO9I/F0J3jZJT+H\n2FdO8HoFPLfeMvcrRKvXa2UmSXRrZLA6YIf+wzgI0wgbb+lkEH3LUgHk0XxalnRE\nMmNUpAWtO0ZX2jh8tkp+3ymhzCtXHwYpiI1iJUDUje/kBXvKfdP+QcDgkshehY/w\nph5SEXS/a//r2TWRPbFHlzi96fL7ySZIjTWyQtZ1UwzjTqkA0gRYQLtXEQW5tLgJ\niiwivJ1UiGoGTfp4nj+ZU7OVYV5I/k+t4cv+s1jYAP/hmdW98932DavR9Mmlb80g\nXwIDAQAB\n-----END PUBLIC KEY-----"; Assert.Equal(EXPECTED_PUBLIC_KEY, receivedPublicKey); } }
public void GetJwtPublicKeyThrowsOnInvalidJson() { var localHandler = A.Fake <MockHandler>(opt => opt.CallsBaseMethods()); A.CallTo(() => localHandler.SendAsync(HttpMethod.Get, "https://cdn.actionstep.com/jwt-discovery-public.json")) .ReturnsLazily(() => Success("Not a JSON string. This is invalid JSON.")); using (var authDelegatingHandler = new AuthDelegatingHandler() { InnerHandler = localHandler }) using (var httpClient = new HttpClient(authDelegatingHandler)) using (var memoryCache = new MemoryCache(new MemoryCacheOptions())) { var fakeClock = new FakeClock(Instant.FromUtc(2019, 05, 07, 2, 3)); var options = new ActionstepServiceConfigurationOptions("clientId", "clientSecret"); var tokenSetRepository = new TestTokenSetRepository(); IActionstepService actionstepService = new ActionstepService(new NullLogger <ActionstepService>(), httpClient, options, tokenSetRepository, fakeClock, memoryCache); var ex = Assert.Throws <InvalidJwtDiscoveryResponseException>(() => { actionstepService.GetJwtPublicKeyData(); }); Assert.Equal("There was a problem parsing the JWT Discovery public key response.", ex.Message); } }