public async Task AuthenticateAsync_TokenRequestedAndPrepareRequest_RequestAuthHeaderIsSetCorrect() { const string expectedToken = "TokenData"; var jwtClientMock = A.Fake <IJwtClient>(); A.CallTo(() => jwtClientMock.RequestTokenInfoAsync(new Uri("http://authtest.com/auth"), A <JwtTokenRequest> .Ignored)) .Returns(Task.FromResult(new JwtTokenInfo(expectedToken))); var jwtHttpClientAuthenticator = new JwtHttpClientAuthenticator(jwtClientMock) { Credentials = new NetworkCredential("user", "pass"), TokenRequestUri = new Uri("http://authtest.com/auth") }; await jwtHttpClientAuthenticator.AuthenticateAsync(new Uri("http://test.com")); var request = new HttpRequestMessage(); jwtHttpClientAuthenticator.PrepareHttpRequest(request); var authHeader = request.Headers.Authorization; Assert.NotNull(authHeader); Assert.Equal("Bearer", authHeader.Scheme); Assert.Equal(expectedToken, authHeader.Parameter); }
public async Task AuthenticateAsync_CanAuthenticateFalse_JwtClientIsNotCalled() { const string expectedToken = "TokenData"; var jwtClientMock = A.Fake <IJwtClient>(); A.CallTo(() => jwtClientMock.RequestTokenInfoAsync(new Uri("http://authtest.com/auth"), A <JwtTokenRequest> .Ignored)) .Returns(Task.FromResult(new JwtTokenInfo(expectedToken))); var jwtHttpClientAuthenticator = new JwtHttpClientAuthenticator(jwtClientMock); await jwtHttpClientAuthenticator.AuthenticateAsync(new Uri("http://test.com")); A.CallTo(() => jwtClientMock.RequestTokenInfoAsync(A <Uri> .Ignored, A <JwtTokenRequest> .Ignored)) .MustNotHaveHappened(); }