Exemplo n.º 1
0
            public static MockChallenge Create(string challengeType = null, string authority = null, string resource = null, string scope = null)
            {
                var mock = new MockChallenge();

                mock.ChallengeType       = challengeType ?? "Bearer";
                mock.AuthorizationServer = authority ?? CreateMockUrl(1);
                mock.Resource            = resource ?? CreateMockUrl(0);
                mock.Scope = scope ?? mock.Resource + "/.default";
                return(mock);
            }
Exemplo n.º 2
0
        public async Task CacheNotUpdatedNon401Aysnc()
        {
            var handler = new ChallengeCacheHandler();

            var expChallenge = MockChallenge.Create();

            handler.InnerHandler = new StaticChallengeResponseHandler(HttpStatusCode.Forbidden, expChallenge.ToString());

            var client = new HttpClient(handler);

            var requestUrl = CreateMockUrl(2);

            var _ = await client.SendAsync(new HttpRequestMessage(HttpMethod.Get, requestUrl));

            AssertChallengeCacheEntry(requestUrl, null);
        }
Exemplo n.º 3
0
        private static void AssertChallengeCacheEntry(string requestUrl, MockChallenge expChallenge)
        {
            var actChallenge = HttpBearerChallengeCache.GetInstance().GetChallengeForURL(new Uri(requestUrl));

            if (expChallenge == null)
            {
                Assert.Null(actChallenge);
            }
            else
            {
                Assert.NotNull(actChallenge);

                Assert.Equal(expChallenge.AuthorizationServer, actChallenge.AuthorizationServer);

                Assert.Equal(expChallenge.Scope, actChallenge.Scope);

                Assert.Equal(expChallenge.Resource, actChallenge.Resource);
            }
        }
Exemplo n.º 4
0
        public async Task CacheUpdateOn401Async()
        {
            string requestUrlBase = CreateMockUrl();

            string requestUrl1 = CreateMockUrl(requestUrlBase, 2);

            HttpBearerChallengeCache.GetInstance().SetChallengeForURL(new Uri(requestUrl1), MockChallenge.Create().ToHttpBearerChallenge(requestUrl1));

            string requestUrl2 = CreateMockUrl(requestUrlBase, 2);

            var handler = new ChallengeCacheHandler();

            var expChallenge = MockChallenge.Create();

            handler.InnerHandler = new StaticChallengeResponseHandler(HttpStatusCode.Unauthorized, expChallenge.ToString());

            var client = new HttpClient(handler);

            var _ = await client.SendAsync(new HttpRequestMessage(HttpMethod.Get, requestUrl2));

            AssertChallengeCacheEntry(requestUrl1, expChallenge);

            AssertChallengeCacheEntry(requestUrl2, expChallenge);
        }
Exemplo n.º 5
0
        public async Task CacheNotUpdatedNonBearerChallengeAsync()
        {
            var handler = new ChallengeCacheHandler();

            handler.InnerHandler = new StaticChallengeResponseHandler(HttpStatusCode.Unauthorized, MockChallenge.Create("PoP").ToString());

            var client = new HttpClient(handler);

            var requestUrl = CreateMockUrl(2);

            var _ = await client.SendAsync(new HttpRequestMessage(HttpMethod.Get, requestUrl));

            AssertChallengeCacheEntry(requestUrl, null);
        }