forked from dotnet/aspnetcore
-
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 AuthZ ToString PR (dotnet#15350)
Rebased verison of dotnet#10822
- Loading branch information
Showing
17 changed files
with
400 additions
and
10 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
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
32 changes: 32 additions & 0 deletions
32
src/Security/Authorization/test/AssertionRequirementsTests.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,32 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Microsoft.AspNetCore.Authorization.Infrastructure; | ||
using Xunit; | ||
|
||
namespace Microsoft.AspNetCore.Authorization.Test | ||
{ | ||
public class AssertionRequirementsTests | ||
{ | ||
private AssertionRequirement CreateRequirement() | ||
{ | ||
return new AssertionRequirement(context => true); | ||
} | ||
|
||
[Fact] | ||
public void ToString_ShouldReturnFormatValue() | ||
{ | ||
// Arrange | ||
var requirement = new AssertionRequirement(context => true); | ||
|
||
// Act | ||
var formattedValue = requirement.ToString(); | ||
|
||
// Assert | ||
Assert.Equal("Handler assertion should evaluate to true.", formattedValue); | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/Security/Authorization/test/ClaimsAuthorizationRequirementTests.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,58 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Microsoft.AspNetCore.Authorization.Infrastructure; | ||
using Xunit; | ||
|
||
namespace Microsoft.AspNetCore.Authorization.Test | ||
{ | ||
public class ClaimsAuthorizationRequirementTests | ||
{ | ||
public ClaimsAuthorizationRequirement CreateRequirement(string claimType, params string[] allowedValues) | ||
{ | ||
return new ClaimsAuthorizationRequirement(claimType, allowedValues); | ||
} | ||
|
||
[Fact] | ||
public void ToString_ShouldReturnAndDescriptionWhenAllowedValuesNotNull() | ||
{ | ||
// Arrange | ||
var requirement = CreateRequirement("Custom", "CustomValue1", "CustomValue2"); | ||
|
||
// Act | ||
var formattedValue = requirement.ToString(); | ||
|
||
// Assert | ||
Assert.Equal("ClaimsAuthorizationRequirement:Claim.Type=Custom and Claim.Value is one of the following values: (CustomValue1|CustomValue2)", formattedValue); | ||
} | ||
|
||
[Fact] | ||
public void ToString_ShouldReturnWithoutAllowedDescriptionWhenAllowedValuesIsNull() | ||
{ | ||
// Arrange | ||
var requirement = CreateRequirement("Custom", (string[])null); | ||
|
||
// Act | ||
var formattedValue = requirement.ToString(); | ||
|
||
// Assert | ||
Assert.Equal("ClaimsAuthorizationRequirement:Claim.Type=Custom", formattedValue); | ||
} | ||
|
||
[Fact] | ||
public void ToString_ShouldReturnWithoutAllowedDescriptionWhenAllowedValuesIsEmpty() | ||
{ | ||
// Arrange | ||
var requirement = CreateRequirement("Custom", Array.Empty<string>()); | ||
|
||
// Act | ||
var formattedValue = requirement.ToString(); | ||
|
||
// Assert | ||
Assert.Equal("ClaimsAuthorizationRequirement:Claim.Type=Custom", formattedValue); | ||
} | ||
} | ||
} |
Oops, something went wrong.