Skip to content

Commit

Permalink
Adding some unit tests. Modifying SocketsHttpHandler constructor, acc…
Browse files Browse the repository at this point in the history
…epting UseDefaultCredentials
  • Loading branch information
ggnaegi authored and raman-m committed Apr 19, 2024
1 parent c56269c commit 04d2653
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Ocelot/Configuration/HttpHandlerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ public HttpHandlerOptions(bool allowAutoRedirect, bool useCookieContainer, bool
/// <see langword="true"/> if the default credentials are used; otherwise <see langword="false"/>. The default value is <see langword="false"/>.
/// The property value is assignable to the <see cref="HttpClientHandler.UseDefaultCredentials"/> one.
/// </value>
public bool UseDefaultCredentials { get; private set; }
public bool UseDefaultCredentials { get; }
}
}
1 change: 1 addition & 0 deletions src/Ocelot/Requester/MessageInvokerPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ private HttpMessageHandler CreateHandler(DownstreamRoute downstreamRoute)
UseProxy = downstreamRoute.HttpHandlerOptions.UseProxy,
MaxConnectionsPerServer = downstreamRoute.HttpHandlerOptions.MaxConnectionsPerServer,
PooledConnectionLifetime = downstreamRoute.HttpHandlerOptions.PooledConnectionLifeTime,
Credentials = downstreamRoute.HttpHandlerOptions.UseDefaultCredentials ? CredentialCache.DefaultCredentials : null,
};

if (downstreamRoute.HttpHandlerOptions.UseCookieContainer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,41 @@ public void should_create_options_fixing_specified_MaxConnectionsPerServer_range
.Then(x => ThenTheFollowingOptionsReturned(expectedOptions))
.BDDfy();
}

[Fact]
public void Should_create_options_with_useDefaultCredentials_false_as_default()
{
var fileRoute = new FileRoute
{
HttpHandlerOptions = new FileHttpHandlerOptions(),
};

var expectedOptions = new HttpHandlerOptions(false, false, false, true, int.MaxValue, DefaultPooledConnectionLifeTime, false);

this.Given(x => GivenTheFollowing(fileRoute))
.When(x => WhenICreateHttpHandlerOptions())
.Then(x => ThenTheFollowingOptionsReturned(expectedOptions))
.BDDfy();
}

[Fact]
public void Should_create_options_with_useDefaultCredentials_true_if_set()
{
var fileRoute = new FileRoute
{
HttpHandlerOptions = new FileHttpHandlerOptions
{
UseDefaultCredentials = true,
},
};

var expectedOptions = new HttpHandlerOptions(false, false, false, true, int.MaxValue, DefaultPooledConnectionLifeTime, true);

this.Given(x => GivenTheFollowing(fileRoute))
.When(x => WhenICreateHttpHandlerOptions())
.Then(x => ThenTheFollowingOptionsReturned(expectedOptions))
.BDDfy();
}

private void GivenTheFollowing(FileRoute fileRoute)
{
Expand All @@ -203,7 +238,8 @@ private void ThenTheFollowingOptionsReturned(HttpHandlerOptions expected)
_httpHandlerOptions.UseCookieContainer.ShouldBe(expected.UseCookieContainer);
_httpHandlerOptions.UseTracing.ShouldBe(expected.UseTracing);
_httpHandlerOptions.UseProxy.ShouldBe(expected.UseProxy);
_httpHandlerOptions.MaxConnectionsPerServer.ShouldBe(expected.MaxConnectionsPerServer);
_httpHandlerOptions.MaxConnectionsPerServer.ShouldBe(expected.MaxConnectionsPerServer);
_httpHandlerOptions.UseDefaultCredentials.ShouldBe(expected.UseDefaultCredentials);
}

private void GivenARealTracer()
Expand Down

0 comments on commit 04d2653

Please sign in to comment.