Skip to content

Commit dc6076f

Browse files
committed
Fix errors and messages
1 parent b389e86 commit dc6076f

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

src/Ocelot/Authorization/ScopesAuthorizer.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ namespace Ocelot.Authorization
1111
public class ScopesAuthorizer : IScopesAuthorizer
1212
{
1313
private const string ScopeClaimKey = "scope";
14-
private readonly IClaimsParser _claimsParser;
14+
private readonly IClaimsParser _claimsParser;
15+
16+
public ScopesAuthorizer(IClaimsParser claimsParser)
17+
{
18+
_claimsParser = claimsParser;
19+
}
1520

1621
public Response<bool> Authorize(ClaimsPrincipal claimsPrincipal, List<string> routeAllowedScopes)
1722
{
@@ -33,16 +38,16 @@ public Response<bool> Authorize(ClaimsPrincipal claimsPrincipal, List<string> ro
3338
{
3439
var scope = userScopes[0];
3540

36-
if (scope.Contains(" "))
41+
if (scope.Contains(' '))
3742
{
38-
userScopes = scope.Split(" ", StringSplitOptions.RemoveEmptyEntries);
43+
userScopes = scope.Split(' ', StringSplitOptions.RemoveEmptyEntries);
3944
}
4045
}
4146

4247
if (routeAllowedScopes.Except(userScopes).Any())
4348
{
4449
return new ErrorResponse<bool>(
45-
new ScopeNotAuthorizedError($"User scopes: '{string.Join(",", userScopes)}' do not have all allowed route scopes: '{string.Join(",", routeAllowedScopes)}'"));
50+
new ScopeNotAuthorizedError($"User scopes: '{string.Join(',', userScopes)}' do not have all allowed route scopes: '{string.Join(',', routeAllowedScopes)}'"));
4651
}
4752

4853
return new OkResponse<bool>(true);

test/Ocelot.UnitTests/Infrastructure/ScopesAuthorizerTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public ScopesAuthorizerTests()
3131
}
3232

3333
[Fact]
34-
public void should_return_ok_if_no_allowed_scopes()
34+
public void Should_return_ok_if_no_allowed_scopes()
3535
{
3636
this.Given(_ => GivenTheFollowing(new ClaimsPrincipal()))
3737
.And(_ => GivenTheFollowing(new List<string>()))
@@ -41,7 +41,7 @@ public void should_return_ok_if_no_allowed_scopes()
4141
}
4242

4343
[Fact]
44-
public void should_return_ok_if_null_allowed_scopes()
44+
public void Should_return_ok_if_null_allowed_scopes()
4545
{
4646
this.Given(_ => GivenTheFollowing(new ClaimsPrincipal()))
4747
.And(_ => GivenTheFollowing((List<string>)null))
@@ -51,7 +51,7 @@ public void should_return_ok_if_null_allowed_scopes()
5151
}
5252

5353
[Fact]
54-
public void should_return_error_if_claims_parser_returns_error()
54+
public void Should_return_error_if_claims_parser_returns_error()
5555
{
5656
var fakeError = new FakeError();
5757
this.Given(_ => GivenTheFollowing(new ClaimsPrincipal()))
@@ -63,7 +63,7 @@ public void should_return_error_if_claims_parser_returns_error()
6363
}
6464

6565
[Fact]
66-
public void should_match_scopes_and_return_ok_result()
66+
public void Should_match_scopes_and_return_ok_result()
6767
{
6868
var claimsPrincipal = new ClaimsPrincipal();
6969
var allowedScopes = new List<string> { "someScope" };
@@ -77,7 +77,7 @@ public void should_match_scopes_and_return_ok_result()
7777
}
7878

7979
[Fact]
80-
public void should_not_match_scopes_and_return_error_result()
80+
public void Should_not_match_scopes_and_return_error_result()
8181
{
8282
var fakeError = new FakeError();
8383
var claimsPrincipal = new ClaimsPrincipal();

0 commit comments

Comments
 (0)