|
|
@ -52,4 +52,40 @@ public class CurrentPrincipalAccessor_Tests : AbpIntegratedTest<AbpSecurityTestM |
|
|
currentPrincipal.Identity.ShouldNotBeNull(); |
|
|
currentPrincipal.Identity.ShouldNotBeNull(); |
|
|
currentPrincipal.Identity.IsAuthenticated.ShouldBeFalse(); |
|
|
currentPrincipal.Identity.IsAuthenticated.ShouldBeFalse(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
|
|
|
public void Should_Reflect_Underlying_Source_After_Change_Scope_Disposed() |
|
|
|
|
|
{ |
|
|
|
|
|
var accessor = new TestCurrentPrincipalAccessor(); |
|
|
|
|
|
|
|
|
|
|
|
var changedPrincipal = new ClaimsPrincipal(new ClaimsIdentity(new List<Claim> |
|
|
|
|
|
{ |
|
|
|
|
|
new Claim(ClaimTypes.NameIdentifier, "123456") |
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
using (accessor.Change(changedPrincipal)) |
|
|
|
|
|
{ |
|
|
|
|
|
accessor.Principal.ShouldBe(changedPrincipal); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Disposing the Change scope must not pin the accessor to the fallback principal;
|
|
|
|
|
|
// a principal that becomes available afterwards has to be reflected.
|
|
|
|
|
|
var sourcePrincipal = new ClaimsPrincipal(new ClaimsIdentity(new List<Claim> |
|
|
|
|
|
{ |
|
|
|
|
|
new Claim(ClaimTypes.NameIdentifier, "654321") |
|
|
|
|
|
})); |
|
|
|
|
|
accessor.SourcePrincipal = sourcePrincipal; |
|
|
|
|
|
|
|
|
|
|
|
accessor.Principal.ShouldBe(sourcePrincipal); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private class TestCurrentPrincipalAccessor : CurrentPrincipalAccessorBase |
|
|
|
|
|
{ |
|
|
|
|
|
public ClaimsPrincipal? SourcePrincipal { get; set; } |
|
|
|
|
|
|
|
|
|
|
|
protected override ClaimsPrincipal GetClaimsPrincipal() |
|
|
|
|
|
{ |
|
|
|
|
|
return SourcePrincipal ?? new ClaimsPrincipal(new ClaimsIdentity()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|