public async void GenerateClaimsForIdentity_NoIssuer_ThrowException() { var expectedInvalidIssuer = TestHelper.GenerateRandomString(); var issuer = TestHelper.GenerateRandomString(); authenticateInfo = GenerateAuthenticateInfo(issuer, false); authenticateInfo.Properties.Items["scheme"] = FabricIdentityConstants.AuthenticationSchemes.Azure; AppConfiguration.AzureActiveDirectorySettings.IssuerWhiteList = new string[] { issuer = expectedInvalidIssuer }; Exception expectedException = null; try { var result = await ClaimsService.GenerateClaimsForIdentity(authenticateInfo, authorizationRequest); Assert.True(false, "The code should not call this line. It should have thrown an exception."); } catch (Exception exc) { expectedException = exc; } Assert.NotNull(expectedException); Assert.IsType <MissingIssuerClaimException>(expectedException); Assert.Equal <string>( ExceptionMessageResources.MissingIssuerClaimMessage, expectedException.Message); }
public async void GenerateClaimsForIdentity_HappyPathNonAzure_RemovesNameIdentitiferUserIdClaim() { authenticateInfo = GenerateAuthenticateInfo(null, true, false); var result = await ClaimsService.GenerateClaimsForIdentity(authenticateInfo, authorizationRequest); Assert.False(result.Claims.Any(x => x.Type == ClaimTypes.NameIdentifier)); }
public async void GenerateClaimsForIdentity_HappyPathNonAzure_RemovesSubjectUserIdClaim() { authenticateInfo = GenerateAuthenticateInfo(null, true, false); var result = await ClaimsService.GenerateClaimsForIdentity(authenticateInfo, authorizationRequest); Assert.DoesNotContain(result.Claims, x => x.Type == JwtClaimTypes.Subject); }
public async void GenerateClaimsForIdentity_HappyPathAzure_ReturnsClaimsResult() { var issuer = TestHelper.GenerateRandomString(); authenticateInfo = GenerateAuthenticateInfo(issuer); authenticateInfo.Properties.Items["scheme"] = FabricIdentityConstants.AuthenticationSchemes.Azure; AppConfiguration.AzureActiveDirectorySettings.IssuerWhiteList = new string[] { issuer = "LOCAL AUTHORITY" }; var result = await ClaimsService.GenerateClaimsForIdentity(authenticateInfo, authorizationRequest); AssertClaimsResult(authenticateInfo, authorizationRequest, result); }
public async void GenerateClaimsForIdentity_NullInfo_ReturnsException() { Exception excResult = null; try { var result = await ClaimsService.GenerateClaimsForIdentity(null, new AuthorizationRequest()); Assert.True(false, "Should not get past this function call."); } catch (Exception exc) { excResult = exc; } Assert.NotNull(excResult); Assert.IsType <ArgumentNullException>(excResult); Assert.True(excResult.Message.Contains("The object name 'info' cannot be null.")); }
public async void GenerateClaimsForIdentity_NoUserIdClaim_ThrowException() { authenticateInfo = GenerateAuthenticateInfo(null, true, false, false); Exception expectedException = null; try { var result = await ClaimsService.GenerateClaimsForIdentity(authenticateInfo, authorizationRequest); Assert.True(false, "The code should not call this line. It should have thrown an exception."); } catch (Exception exc) { expectedException = exc; } Assert.NotNull(expectedException); Assert.IsType <MissingUserClaimException>(expectedException); Assert.Equal <string>( ExceptionMessageResources.MissingUserClaimMessage, expectedException.Message); }
public async void GenerateClaimsForIdentity_HappyPathNonAzure_ReturnsClaimsResult() { var result = await ClaimsService.GenerateClaimsForIdentity(authenticateInfo, authorizationRequest); AssertClaimsResult(authenticateInfo, authorizationRequest, result); }