Esempio n. 1
0
        public async Task SendAsync_NoHeader_WhenExpired()
        {
            var handler = new MockDelegatingHandler();

            handler.Responses.Add(new HttpResponseMessage(HttpStatusCode.OK));
            var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/test");
            var sut     = new WrappedAuthenticationProvider(() => Task.FromResult(ExpiredAuthenticationToken), "X-ZUMO-AUTH")
            {
                InnerHandler = handler
            };

            var response = await sut.WrappedSendAsync(request).ConfigureAwait(false);

            Assert.NotNull(response);
            Assert.Single(handler.Requests);
            var headers = handler.Requests[0].Headers;

            Assert.False(headers.Contains("X-ZUMO-AUTH"));
        }
Esempio n. 2
0
        public async Task SendAsync_AddsHeader_BearerAuth()
        {
            var handler = new MockDelegatingHandler();

            handler.Responses.Add(new HttpResponseMessage(HttpStatusCode.OK));
            var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/test");
            var sut     = new WrappedAuthenticationProvider(() => Task.FromResult(ValidAuthenticationToken))
            {
                InnerHandler = handler
            };

            var response = await sut.WrappedSendAsync(request).ConfigureAwait(false);

            Assert.NotNull(response);
            Assert.Single(handler.Requests);
            var headers = handler.Requests[0].Headers;

            Assert.Equal(ValidAuthenticationToken.Token, headers.Authorization.Parameter);
            Assert.Equal("Bearer", headers.Authorization.Scheme);
        }
Esempio n. 3
0
        public async Task SendAsync_OverwritesHeader_WhenNotExpired()
        {
            var handler = new MockDelegatingHandler();

            handler.Responses.Add(new HttpResponseMessage(HttpStatusCode.OK));
            var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/test");

            request.Headers.Add("X-ZUMO-AUTH", "a-test-header");
            var sut = new WrappedAuthenticationProvider(() => Task.FromResult(ValidAuthenticationToken), "X-ZUMO-AUTH")
            {
                InnerHandler = handler
            };

            var response = await sut.WrappedSendAsync(request).ConfigureAwait(false);

            Assert.NotNull(response);
            Assert.Single(handler.Requests);
            var headers = handler.Requests[0].Headers;

            Assert.Equal(ValidAuthenticationToken.Token, headers.GetValues("X-ZUMO-AUTH").First());
        }