public async Task Repeated_inactive_token_with_caching_enabled_should_hit_cache() { var expectedToken = "expected_token"; var handler = new IntrospectionEndpointHandler(IntrospectionEndpointHandler.Behavior.Inactive); var server = PipelineFactory.CreateServer(o => { _options(o); o.SaveToken = true; o.EnableCaching = true; o.CacheDuration = TimeSpan.FromMinutes(10); }, handler, true); var client = server.CreateClient(); client.SetBearerToken(expectedToken); var firstResponse = await client.GetAsync("http://test"); firstResponse.StatusCode.Should().Be(HttpStatusCode.Unauthorized); handler.SentIntrospectionRequest.Should().BeTrue(); handler.SentIntrospectionRequest = false; var secondResponse = await client.GetAsync("http://test"); secondResponse.StatusCode.Should().Be(HttpStatusCode.Unauthorized); handler.SentIntrospectionRequest.Should().BeFalse(); AssertCacheItemExists(server, string.Empty, expectedToken); }
public async Task ActiveToken_With_SavedToken_And_Caching_With_Cache_Key_Prefix() { var expectedToken = "expected_token"; var cacheKeyPrefix = "KeyPrefix"; var handler = new IntrospectionEndpointHandler(IntrospectionEndpointHandler.Behavior.Active, TimeSpan.FromHours(1)); var server = PipelineFactory.CreateServer(o => { _options(o); o.SaveToken = true; o.EnableCaching = true; o.CacheKeyPrefix = cacheKeyPrefix; o.CacheDuration = TimeSpan.FromMinutes(10); }, handler, true); var client = server.CreateClient(); client.SetBearerToken(expectedToken); var firstResponse = await client.GetAsync("http://test"); firstResponse.StatusCode.Should().Be(HttpStatusCode.OK); var secondResponse = await client.GetAsync("http://test"); secondResponse.StatusCode.Should().Be(HttpStatusCode.OK); var responseDataStr = await secondResponse.Content.ReadAsStringAsync(); var responseData = JsonConvert.DeserializeObject <Dictionary <string, string> >(responseDataStr); responseData.Should().Contain("token", expectedToken); AssertCacheItemExists(server, cacheKeyPrefix, expectedToken); }