Skip to content

Commit

Permalink
added test for audiences validation
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshLozensky committed May 10, 2024
1 parent de4508b commit f2f2ff2
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1709,12 +1709,18 @@ public static TheoryData<JwtTheoryData> ValidateAudienceTheoryData
TestId = "'validateAudience == false, AudienceValidator return false'",
SecurityToken = tokenHandler.CreateJwtSecurityToken(issuer: Default.Issuer, audience: Default.Audience),
ValidationParameters = ValidateAudienceValidationParameters(null, null, ValidationDelegates.AudienceValidatorReturnsFalse, false),
},
new JwtTheoryData
{
TestId = "'validAudiences == audiences, validates successfully'",
SecurityToken = tokenHandler.CreateJwtSecurityToken(new SecurityTokenDescriptor{ Issuer = Default.Issuer, Audiences = Default.Audiences}),
ValidationParameters = ValidateAudienceValidationParameters(null, null, null, true, Default.Audiences),
}
};
}
}

private static TokenValidationParameters ValidateAudienceValidationParameters(string validAudience, IEnumerable<string> validAudiences, AudienceValidator audienceValidator, bool validateAudience)
private static TokenValidationParameters ValidateAudienceValidationParameters(string validAudience, IEnumerable<string> validIssuers, AudienceValidator audienceValidator, bool validateAudience, IEnumerable<string> validAudiences = null)
{
return new TokenValidationParameters
{
Expand All @@ -1724,7 +1730,8 @@ private static TokenValidationParameters ValidateAudienceValidationParameters(st
ValidateIssuer = false,
ValidateLifetime = false,
ValidAudience = validAudience,
ValidIssuers = validAudiences
ValidAudiences = validAudiences,
ValidIssuers = validIssuers
};
}

Expand Down

0 comments on commit f2f2ff2

Please sign in to comment.