public async Task CreateAsync_Should_Include_Claim(string expectedClaimType, object expectedClaimValue) { BackOfficeClaimsPrincipalFactory sut = CreateSut(); ClaimsPrincipal claimsPrincipal = await sut.CreateAsync(_testUser); Assert.True(claimsPrincipal.HasClaim(expectedClaimType, expectedClaimValue.ToString())); Assert.True(claimsPrincipal.GetUmbracoIdentity().HasClaim(expectedClaimType, expectedClaimValue.ToString())); }
public async Task CreateAsync_Should_Create_Principal_With_Claims_Identity() { BackOfficeClaimsPrincipalFactory sut = CreateSut(); ClaimsPrincipal claimsPrincipal = await sut.CreateAsync(_testUser); var umbracoBackOfficeIdentity = claimsPrincipal.Identity as ClaimsIdentity; Assert.IsNotNull(umbracoBackOfficeIdentity); }
public async Task CreateAsync_When_SecurityStamp_Supported_Expect_SecurityStamp_Claim() { const string expectedClaimType = Constants.Security.SecurityStampClaimType; var expectedClaimValue = _testUser.SecurityStamp; _mockUserManager.Setup(x => x.SupportsUserSecurityStamp).Returns(true); _mockUserManager.Setup(x => x.GetSecurityStampAsync(_testUser)).ReturnsAsync(_testUser.SecurityStamp); BackOfficeClaimsPrincipalFactory sut = CreateSut(); ClaimsPrincipal claimsPrincipal = await sut.CreateAsync(_testUser); Assert.True(claimsPrincipal.HasClaim(expectedClaimType, expectedClaimValue)); Assert.True(claimsPrincipal.GetUmbracoIdentity().HasClaim(expectedClaimType, expectedClaimValue)); }
public async Task CreateAsync_When_Roles_Supported_Expect_Role_Claims_In_UmbracoIdentity() { const string expectedClaimType = ClaimTypes.Role; const string expectedClaimValue = "b87309fb-4caf-48dc-b45a-2b752d051508"; _testUser.Roles.Add(new IdentityUserRole <string> { RoleId = expectedClaimValue }); _mockUserManager.Setup(x => x.SupportsUserRole).Returns(true); _mockUserManager.Setup(x => x.GetRolesAsync(_testUser)).ReturnsAsync(new[] { expectedClaimValue }); BackOfficeClaimsPrincipalFactory sut = CreateSut(); ClaimsPrincipal claimsPrincipal = await sut.CreateAsync(_testUser); Assert.True(claimsPrincipal.HasClaim(expectedClaimType, expectedClaimValue)); }
public async Task CreateAsync_When_UserClaims_Supported_Expect_UserClaims_In_Actor() { const string expectedClaimType = "custom"; const string expectedClaimValue = "val"; _testUser.Claims.Add(new IdentityUserClaim <string> { ClaimType = expectedClaimType, ClaimValue = expectedClaimValue }); _mockUserManager.Setup(x => x.SupportsUserClaim).Returns(true); _mockUserManager.Setup(x => x.GetClaimsAsync(_testUser)).ReturnsAsync( new List <Claim> { new Claim(expectedClaimType, expectedClaimValue) }); BackOfficeClaimsPrincipalFactory sut = CreateSut(); ClaimsPrincipal claimsPrincipal = await sut.CreateAsync(_testUser); Assert.True(claimsPrincipal.GetUmbracoIdentity().HasClaim(expectedClaimType, expectedClaimValue)); }
public void CreateAsync_When_User_Is_Null_Expect_ArgumentNullException() { BackOfficeClaimsPrincipalFactory sut = CreateSut(); Assert.ThrowsAsync <ArgumentNullException>(async() => await sut.CreateAsync(null)); }