1
0

Fixing UnitTests

This commit is contained in:
2022-08-07 20:57:11 +02:00
parent 6460142a65
commit d233bf6b0a
6 changed files with 21 additions and 7 deletions

View File

@@ -111,7 +111,7 @@ namespace Microsoft.AspNetCore.Authorization
if (validator == null)
return null;
var result = await validator.ValidateAsync(username, password, context.HttpContext.GetRemoteIpAddress());
var result = await validator.ValidateAsync(username, password, context.HttpContext.GetRemoteIpAddress(), context.HttpContext.RequestAborted);
if (result == null)
return null;

View File

@@ -58,7 +58,7 @@ namespace AMWD.Common.AspNetCore.BasicAuthentication
string password = plain[(username.Length + 1)..];
var ipAddress = Context.GetRemoteIpAddress();
principal = await validator.ValidateAsync(username, password, ipAddress);
principal = await validator.ValidateAsync(username, password, ipAddress, Context.RequestAborted);
}
catch (Exception ex)
{

View File

@@ -51,7 +51,7 @@ namespace AMWD.Common.AspNetCore.BasicAuthentication
string username = plain.Split(':').First();
string password = plain[(username.Length + 1)..];
var principal = await validator.ValidateAsync(username, password, httpContext.GetRemoteIpAddress());
var principal = await validator.ValidateAsync(username, password, httpContext.GetRemoteIpAddress(), httpContext.RequestAborted);
if (principal == null)
{
SetAuthenticateRequest(httpContext, validator.Realm);

View File

@@ -4,10 +4,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased](https://git.am-wd.de/AM.WD/common/compare/v1.8.0...master) - 0000-00-00
## [Unreleased](https://git.am-wd.de/AM.WD/common/compare/v1.8.1...master) - 0000-00-00
_nothing changed yet_
## [v1.8.1](https://git.am-wd.de/AM.WD/common/compare/v1.8.0...v1.8.1) - 2022-08-07
### Fixed
- UnitTests
- BasicAuthentication modules now all use the cancellation token
## [v1.8.0](https://git.am-wd.de/AM.WD/common/compare/v1.7.0...v1.8.0) - 2022-08-07
### Added
- Converters for `Newtonsoft.Json`

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Net;
using System.Security.Claims;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using AMWD.Common.AspNetCore.BasicAuthentication;
using Microsoft.AspNetCore.Authorization;
@@ -299,7 +300,7 @@ namespace UnitTests.AspNetCore.Attributes
.Setup(v => v.Realm)
.Returns(validatorRealm);
validatorMock
.Setup(v => v.ValidateAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<IPAddress>()))
.Setup(v => v.ValidateAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<IPAddress>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(validatorResult);
requestServicesMock
@@ -325,6 +326,9 @@ namespace UnitTests.AspNetCore.Attributes
contextMock
.Setup(c => c.Connection)
.Returns(connectionInfoMock.Object);
contextMock
.Setup(c => c.RequestAborted)
.Returns(CancellationToken.None);
var routeDataMock = new Mock<RouteData>();

View File

@@ -4,6 +4,7 @@ using System.Linq;
using System.Net;
using System.Security.Claims;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using AMWD.Common.AspNetCore.BasicAuthentication;
using Microsoft.AspNetCore.Http;
@@ -142,8 +143,8 @@ namespace UnitTests.AspNetCore.BasicAuthentication
.Setup(v => v.Realm)
.Returns(validatorRealm);
validatorMock
.Setup(v => v.ValidateAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<IPAddress>()))
.Callback<string, string, IPAddress>((username, password, ipAddress) => validatorCallback.Add((username, password, ipAddress)))
.Setup(v => v.ValidateAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<IPAddress>(), It.IsAny<CancellationToken>()))
.Callback<string, string, IPAddress, CancellationToken>((username, password, ipAddress, _) => validatorCallback.Add((username, password, ipAddress)))
.ReturnsAsync(validatorResponse);
return new BasicAuthenticationMiddleware(nextMock.Object, validatorMock.Object);
@@ -207,6 +208,9 @@ namespace UnitTests.AspNetCore.BasicAuthentication
contextMock
.Setup(c => c.RequestServices)
.Returns(requestServicesMock.Object);
contextMock
.Setup(c => c.RequestAborted)
.Returns(CancellationToken.None);
return contextMock.Object;
}