Skip to content

Commit

Permalink
Increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Ndiritu committed Nov 5, 2024
1 parent 2c77cce commit d54a0ef
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/http/httpClient/KiotaClientFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
using System.Linq;
using System.Net;
using System.Net.Http;
using Microsoft.Kiota.Abstractions.Authentication;
using Microsoft.Kiota.Http.HttpClientLibrary.Middleware;
using Microsoft.Kiota.Http.HttpClientLibrary.Middleware.Options;
using Microsoft.Kiota.Http.HttpClientLibrary.Tests.Mocks;
using Moq;
using Xunit;

namespace Microsoft.Kiota.Http.HttpClientLibrary.Tests
Expand Down Expand Up @@ -138,5 +140,12 @@ public void CreateWithCustomMiddlewarePipelineReturnsHttpClient()
var client = KiotaClientFactory.Create(handlers);
Assert.IsType<HttpClient>(client);
}

[Fact]
public void CreateWithAuthenticationProvider()
{
var client = KiotaClientFactory.Create(new BaseBearerTokenAuthenticationProvider(new Mock<IAccessTokenProvider>().Object));
Assert.IsType<HttpClient>(client);
}
}
}
18 changes: 18 additions & 0 deletions tests/http/httpClient/Middleware/AuthorizationHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,24 @@ public async Task AuthorizationHandlerShouldNotAddAuthHeaderIfPresent()
Assert.Equal($"Bearer existing", response.RequestMessage.Headers.GetValues("Authorization").First());
}

[Fact]
public async Task AuthorizationHandlerShouldNotAddAuthHeaderIfHostIsNotValid()
{
// Arrange
HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "https://example.com");

HttpResponseMessage httpResponse = new HttpResponseMessage(HttpStatusCode.OK);

this._testHttpMessageHandler.SetHttpResponse(httpResponse);// set the mock response

// Act
HttpResponseMessage response = await this._invoker.SendAsync(httpRequestMessage, new CancellationToken());

// Assert
Assert.NotNull(response.RequestMessage);
Assert.False(response.RequestMessage.Headers.Contains("Authorization"));
}

[Fact]
public async Task AuthorizationHandlerShouldAttemptCAEClaimsChallenge()
{
Expand Down

0 comments on commit d54a0ef

Please sign in to comment.