Fixing UnitTests
This commit is contained in:
@@ -111,7 +111,7 @@ namespace Microsoft.AspNetCore.Authorization
|
|||||||
if (validator == null)
|
if (validator == null)
|
||||||
return 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)
|
if (result == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ namespace AMWD.Common.AspNetCore.BasicAuthentication
|
|||||||
string password = plain[(username.Length + 1)..];
|
string password = plain[(username.Length + 1)..];
|
||||||
|
|
||||||
var ipAddress = Context.GetRemoteIpAddress();
|
var ipAddress = Context.GetRemoteIpAddress();
|
||||||
principal = await validator.ValidateAsync(username, password, ipAddress);
|
principal = await validator.ValidateAsync(username, password, ipAddress, Context.RequestAborted);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ namespace AMWD.Common.AspNetCore.BasicAuthentication
|
|||||||
string username = plain.Split(':').First();
|
string username = plain.Split(':').First();
|
||||||
string password = plain[(username.Length + 1)..];
|
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)
|
if (principal == null)
|
||||||
{
|
{
|
||||||
SetAuthenticateRequest(httpContext, validator.Realm);
|
SetAuthenticateRequest(httpContext, validator.Realm);
|
||||||
|
|||||||
@@ -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/),
|
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).
|
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_
|
_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
|
## [v1.8.0](https://git.am-wd.de/AM.WD/common/compare/v1.7.0...v1.8.0) - 2022-08-07
|
||||||
### Added
|
### Added
|
||||||
- Converters for `Newtonsoft.Json`
|
- Converters for `Newtonsoft.Json`
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AMWD.Common.AspNetCore.BasicAuthentication;
|
using AMWD.Common.AspNetCore.BasicAuthentication;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
@@ -299,7 +300,7 @@ namespace UnitTests.AspNetCore.Attributes
|
|||||||
.Setup(v => v.Realm)
|
.Setup(v => v.Realm)
|
||||||
.Returns(validatorRealm);
|
.Returns(validatorRealm);
|
||||||
validatorMock
|
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);
|
.ReturnsAsync(validatorResult);
|
||||||
|
|
||||||
requestServicesMock
|
requestServicesMock
|
||||||
@@ -325,6 +326,9 @@ namespace UnitTests.AspNetCore.Attributes
|
|||||||
contextMock
|
contextMock
|
||||||
.Setup(c => c.Connection)
|
.Setup(c => c.Connection)
|
||||||
.Returns(connectionInfoMock.Object);
|
.Returns(connectionInfoMock.Object);
|
||||||
|
contextMock
|
||||||
|
.Setup(c => c.RequestAborted)
|
||||||
|
.Returns(CancellationToken.None);
|
||||||
|
|
||||||
var routeDataMock = new Mock<RouteData>();
|
var routeDataMock = new Mock<RouteData>();
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AMWD.Common.AspNetCore.BasicAuthentication;
|
using AMWD.Common.AspNetCore.BasicAuthentication;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
@@ -142,8 +143,8 @@ namespace UnitTests.AspNetCore.BasicAuthentication
|
|||||||
.Setup(v => v.Realm)
|
.Setup(v => v.Realm)
|
||||||
.Returns(validatorRealm);
|
.Returns(validatorRealm);
|
||||||
validatorMock
|
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>()))
|
||||||
.Callback<string, string, IPAddress>((username, password, ipAddress) => validatorCallback.Add((username, password, ipAddress)))
|
.Callback<string, string, IPAddress, CancellationToken>((username, password, ipAddress, _) => validatorCallback.Add((username, password, ipAddress)))
|
||||||
.ReturnsAsync(validatorResponse);
|
.ReturnsAsync(validatorResponse);
|
||||||
|
|
||||||
return new BasicAuthenticationMiddleware(nextMock.Object, validatorMock.Object);
|
return new BasicAuthenticationMiddleware(nextMock.Object, validatorMock.Object);
|
||||||
@@ -207,6 +208,9 @@ namespace UnitTests.AspNetCore.BasicAuthentication
|
|||||||
contextMock
|
contextMock
|
||||||
.Setup(c => c.RequestServices)
|
.Setup(c => c.RequestServices)
|
||||||
.Returns(requestServicesMock.Object);
|
.Returns(requestServicesMock.Object);
|
||||||
|
contextMock
|
||||||
|
.Setup(c => c.RequestAborted)
|
||||||
|
.Returns(CancellationToken.None);
|
||||||
|
|
||||||
return contextMock.Object;
|
return contextMock.Object;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user