Skip to content

Commit

Permalink
Review after rebasing: fix errors, warnings, merge code
Browse files Browse the repository at this point in the history
  • Loading branch information
raman-m committed Jul 27, 2023
1 parent 9e582dc commit c1afca2
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 309 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Ocelot.Configuration.Creator
{
public class AuthenticationOptionsCreator : IAuthenticationOptionsCreator
{
public AuthenticationOptions Create(FileAuthenticationOptions reRouteAuthOptions,
public AuthenticationOptions Create(FileAuthenticationOptions routeAuthOptions,
FileAuthenticationOptions globalConfAuthOptions)
{
var routeAuthOptionsEmpty = string.IsNullOrEmpty(routeAuthOptions.AuthenticationProviderKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace Ocelot.Configuration.Creator
{
public interface IAuthenticationOptionsCreator
{
AuthenticationOptions Create(FileAuthenticationOptions reRoute, FileAuthenticationOptions globalConfiguration);
AuthenticationOptions Create(FileAuthenticationOptions routeAuthOptions, FileAuthenticationOptions globalConfAuthOptions);
}
}
2 changes: 1 addition & 1 deletion src/Ocelot/Configuration/Creator/RoutesCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private DownstreamRoute SetUpDownstreamRoute(FileRoute fileRoute, FileGlobalConf

var upstreamTemplatePattern = _upstreamTemplatePatternCreator.Create(fileRoute);

var authOptionsForRoute = _authOptionsCreator.Create(fileReRoute.AuthenticationOptions, globalConfiguration.AuthenticationOptions);
var authOptionsForRoute = _authOptionsCreator.Create(fileRoute.AuthenticationOptions, globalConfiguration.AuthenticationOptions);

var claimsToHeaders = _claimsToThingCreator.Create(fileRoute.AddHeadersToRequest);

Expand Down
1 change: 1 addition & 0 deletions src/Ocelot/Configuration/File/FileAuthenticationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public FileAuthenticationOptions()

public string AuthenticationProviderKey { get; set; }
public List<string> AllowedScopes { get; set; }

// the property below is significant only if the global AuthenticationOptions are used
public bool AllowAnonymousForGlobalAuthenticationOptions { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Ocelot.UnitTests.Configuration
public class AuthenticationOptionsCreatorTests
{
private readonly AuthenticationOptionsCreator _authOptionsCreator;
private FileReRoute _fileReRoute;
private FileRoute _fileRoute;
private FileGlobalConfiguration _fileGlobalConfig;
private AuthenticationOptions _result;

Expand All @@ -43,7 +43,7 @@ public void should_return_auth_options()
.WithAuthenticationProviderKey("Test")
.Build();

this.Given(x => x.GivenTheFollowingReRoute(fileReRoute))
this.Given(x => x.GivenTheFollowingRoute(fileRoute))
.And(x => x.GivenTheFollowingGlobalConfig(globalConfig))
.When(x => x.WhenICreateTheAuthenticationOptions())
.Then(x => x.ThenTheFollowingConfigIsReturned(expected))
Expand All @@ -53,7 +53,7 @@ public void should_return_auth_options()
[Fact]
public void should_use_global_configuration()
{
var reRoute = new FileReRoute();
var route = new FileRoute();
var globalConfig = new FileGlobalConfiguration
{
AuthenticationOptions = new FileAuthenticationOptions()
Expand All @@ -68,7 +68,7 @@ public void should_use_global_configuration()
.WithAuthenticationProviderKey(globalConfig.AuthenticationOptions?.AuthenticationProviderKey)
.Build();

this.Given(x => x.GivenTheFollowingReRoute(reRoute))
this.Given(x => x.GivenTheFollowingRoute(route))
.And(x => x.GivenTheFollowingGlobalConfig(globalConfig))
.When(x => x.WhenICreateTheAuthenticationOptions())
.Then(x => x.ThenTheFollowingConfigIsReturned(expected))
Expand Down Expand Up @@ -110,7 +110,7 @@ public void should_use_global_configuration_when_route_provider_key_is_empty()
[Fact]
public void should_use_route_over_global_specific()
{
var reRoute = new FileReRoute
var route = new FileRoute
{
AuthenticationOptions = new FileAuthenticationOptions()
{
Expand All @@ -128,18 +128,18 @@ public void should_use_route_over_global_specific()
};

var expected = new AuthenticationOptionsBuilder()
.WithAllowedScopes(reRoute.AuthenticationOptions?.AllowedScopes)
.WithAuthenticationProviderKey(reRoute.AuthenticationOptions?.AuthenticationProviderKey)
.WithAllowedScopes(route.AuthenticationOptions?.AllowedScopes)
.WithAuthenticationProviderKey(route.AuthenticationOptions?.AuthenticationProviderKey)
.Build();

this.Given(x => x.GivenTheFollowingReRoute(reRoute))
this.Given(x => x.GivenTheFollowingRoute(route))
.And(x => x.GivenTheFollowingGlobalConfig(globalConfig))
.When(x => x.WhenICreateTheAuthenticationOptions())
.Then(x => x.ThenTheFollowingConfigIsReturned(expected))
.BDDfy();
}

private void GivenTheFollowingReRoute(FileReRoute fileReRoute)
private void GivenTheFollowingRoute(FileRoute fileRoute)
{
_fileRoute = fileRoute;
}
Expand All @@ -151,7 +151,7 @@ private void GivenTheFollowingGlobalConfig(FileGlobalConfiguration globalConfig)

private void WhenICreateTheAuthenticationOptions()
{
_result = _authOptionsCreator.Create(_fileReRoute.AuthenticationOptions, _fileGlobalConfig.AuthenticationOptions);
_result = _authOptionsCreator.Create(_fileRoute.AuthenticationOptions, _fileGlobalConfig.AuthenticationOptions);
}

private void ThenTheFollowingConfigIsReturned(AuthenticationOptions expected)
Expand Down
Loading

0 comments on commit c1afca2

Please sign in to comment.