Skip to content

Commit af9c434

Browse files
committed
Add NoAuthenticationStrategy and unit tests
Introduced the `NoAuthenticationStrategy` class in the `FlowSynx.Client.Authentication` namespace, implementing the `IAuthenticationStrategy` interface. This class applies no authentication to HTTP requests, with the `ApplyAsync` method being a no-op. Added unit tests in `NoAuthenticationStrategyTests` to verify: - `ApplyAsync` does not set an `Authorization` header on requests without one. - `ApplyAsync` does not modify an existing `Authorization` header. #63
1 parent 98d3990 commit af9c434

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace FlowSynx.Client.Authentication;
2+
3+
/// <summary>
4+
/// Represents an authentication strategy that applies no authentication to HTTP requests.
5+
/// Implements the <see cref="IAuthenticationStrategy"/> interface.
6+
/// </summary>
7+
public class NoAuthenticationStrategy : IAuthenticationStrategy
8+
{
9+
/// <summary>
10+
/// Applies no authentication to the given HTTP request.
11+
/// This method is a no-op and does not modify the request.
12+
/// </summary>
13+
/// <param name="request">The HTTP request to which no authentication will be applied.</param>
14+
/// <returns>A task representing the asynchronous operation.</returns>
15+
public Task ApplyAsync(HttpRequestMessage request) => Task.CompletedTask;
16+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using FlowSynx.Client.Authentication;
2+
3+
namespace FlowSynx.Client.UnitTests.Authentication;
4+
5+
public class NoAuthenticationStrategyTests
6+
{
7+
[Fact]
8+
public async Task ApplyAsync_DoesNotSetAuthorizationHeader()
9+
{
10+
// Arrange
11+
var strategy = new NoAuthenticationStrategy();
12+
var request = new HttpRequestMessage();
13+
14+
// Act
15+
await strategy.ApplyAsync(request);
16+
17+
// Assert
18+
Assert.Null(request.Headers.Authorization);
19+
}
20+
21+
[Fact]
22+
public async Task ApplyAsync_DoesNotModifyExistingAuthorizationHeader()
23+
{
24+
// Arrange
25+
var strategy = new NoAuthenticationStrategy();
26+
var request = new HttpRequestMessage();
27+
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "existing-token");
28+
29+
// Act
30+
await strategy.ApplyAsync(request);
31+
32+
// Assert
33+
Assert.NotNull(request.Headers.Authorization);
34+
Assert.Equal("Bearer", request.Headers.Authorization.Scheme);
35+
Assert.Equal("existing-token", request.Headers.Authorization.Parameter);
36+
}
37+
}

0 commit comments

Comments
 (0)