-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from dlcs/feature/gesture_path
Add customerId to gesture path
- Loading branch information
Showing
12 changed files
with
203 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
src/IIIFAuth2/IIIFAuth2.API.Tests/Infrastructure/Web/UrlPathProviderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using FakeItEasy; | ||
using IIIFAuth2.API.Infrastructure.Web; | ||
using IIIFAuth2.API.Settings; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace IIIFAuth2.API.Tests.Infrastructure.Web; | ||
|
||
public class UrlPathProviderTests | ||
{ | ||
private const string CurrentHost = "dlcs.test.example"; | ||
private const string OtherHost = "dlcs.test.other"; | ||
|
||
[Fact] | ||
public void GetGesturePostbackRelativePath_HandlesNoConfiguredDefault() | ||
{ | ||
// Arrange | ||
var gestureTemplates = new Dictionary<string, string> | ||
{ | ||
[OtherHost] = "/access/specific-host" | ||
}; | ||
var sut = GetSut(CurrentHost, gestureTemplates); | ||
|
||
// Act | ||
var result = sut.GetGesturePostbackRelativePath(123); | ||
|
||
// Asset | ||
result.IsAbsoluteUri.Should().BeFalse(); | ||
result.ToString().Should().Be("/access/123/gesture"); | ||
} | ||
|
||
[Fact] | ||
public void GetGesturePostbackRelativePath_HandlesNoConfiguredDefault_WithPathBase() | ||
{ | ||
// Arrange | ||
var gestureTemplates = new Dictionary<string, string> | ||
{ | ||
[OtherHost] = "/access/specific-host" | ||
}; | ||
var sut = GetSut(CurrentHost, gestureTemplates, "auth/v2/"); | ||
|
||
// Act | ||
var result = sut.GetGesturePostbackRelativePath(123); | ||
|
||
// Asset | ||
result.IsAbsoluteUri.Should().BeFalse(); | ||
result.ToString().Should().Be("auth/v2/access/123/gesture"); | ||
} | ||
|
||
[Fact] | ||
public void GetGesturePostbackRelativePath_UsesConfiguredDefault() | ||
{ | ||
// Arrange | ||
var gestureTemplates = new Dictionary<string, string> | ||
{ | ||
["Default"] = "/access/other", | ||
[OtherHost] = "/access/specific-host" | ||
}; | ||
var sut = GetSut(CurrentHost, gestureTemplates); | ||
|
||
// Act | ||
var result = sut.GetGesturePostbackRelativePath(123); | ||
|
||
// Asset | ||
result.IsAbsoluteUri.Should().BeFalse(); | ||
result.ToString().Should().Be("/access/other"); | ||
} | ||
|
||
[Fact] | ||
public void GetGesturePostbackRelativePath_UsesSpecifiedHost_IfFound() | ||
{ | ||
// Arrange | ||
var gestureTemplates = new Dictionary<string, string> | ||
{ | ||
["Default"] = "/access/other", | ||
[CurrentHost] = "/{customerId}/access/gesture" | ||
}; | ||
var sut = GetSut(CurrentHost, gestureTemplates); | ||
|
||
// Act | ||
var result = sut.GetGesturePostbackRelativePath(123); | ||
|
||
// Asset | ||
result.IsAbsoluteUri.Should().BeFalse(); | ||
result.ToString().Should().Be("/123/access/gesture"); | ||
} | ||
|
||
private UrlPathProvider GetSut(string host, Dictionary<string, string> gestureTemplates, string? pathBase = null) | ||
{ | ||
var context = new DefaultHttpContext(); | ||
var request = context.Request; | ||
request.Host = new HostString(host); | ||
request.Scheme = "https"; | ||
var contextAccessor = A.Fake<IHttpContextAccessor>(); | ||
A.CallTo(() => contextAccessor.HttpContext).Returns(context); | ||
|
||
var authSettings = new AuthSettings { GesturePathTemplateForDomain = gestureTemplates }; | ||
var apiSettings = Options.Create(new ApiSettings { Auth = authSettings, PathBase = pathBase }); | ||
|
||
return new UrlPathProvider(contextAccessor, apiSettings); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.