Skip to content

Commit e415733

Browse files
committed
test: Verify DigestAuthenticator uses injected RestClientOptions
Added unit test VerifyHandshakeUsesInjectedClientOptions to ensure DigestAuthenticator correctly applies injected RestClientOptions (tested via Proxy callback) during the digest handshake request.
1 parent adde47e commit e415733

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

test/DigestAuthenticator.Tests/DigestIntegrationTest.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public async Task Given_ADigestAuthEndpoint_When_ITryToGetInfo_Then_TheAuthMustB
4242
[Fact]
4343
public async Task Given_ADigestAuthEndpoint_When_ITryToInjectOwnClient_Then_TheAuthMustBeResolved()
4444
{
45+
bool proxyCalled = false;
46+
4547
var loggerMock = Substitute.For<ILogger>();
4648
loggerMock.BeginScope("DigestServerStub");
4749

@@ -50,13 +52,16 @@ public async Task Given_ADigestAuthEndpoint_When_ITryToInjectOwnClient_Then_TheA
5052

5153
RestClientOptions options = new RestClientOptions()
5254
{
53-
MaxRedirects = 2
55+
Proxy = new TestProxy(() => proxyCalled = true)
5456
};
5557

5658
var client = _fixture.CreateInjectedOptionClient(loggerMock, options);
5759
var response = await client.ExecuteAsync(request);
5860

5961
response.StatusCode.Should().Be(HttpStatusCode.OK);
6062
loggerMock.ReceivedWithAnyArgs().LogDebug("NONONO");
63+
64+
Assert.True(proxyCalled, "Injected RestClientOptions.Proxy should be used in digest handshake.");
65+
6166
}
6267
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Net;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace RestSharp.Authenticators.Digest.Tests.Fixtures;
9+
internal class TestProxy : IWebProxy
10+
{
11+
private readonly Action _onProxyCalled;
12+
13+
public TestProxy(Action onProxyCalled)
14+
{
15+
_onProxyCalled = onProxyCalled;
16+
}
17+
18+
public Uri GetProxy(Uri destination)
19+
{
20+
_onProxyCalled();
21+
return destination;
22+
}
23+
24+
public bool IsBypassed(Uri host) => false;
25+
26+
public ICredentials? Credentials { get; set; }
27+
}

0 commit comments

Comments
 (0)