-
Notifications
You must be signed in to change notification settings - Fork 432
Consolidating test statics #2956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
18e49c0
Consolidating statics
0f819a1
clean up
2e09cf9
Merge branch 'dev' into trwalke/ConsolidateTestStatics
trwalke 3e0b85a
Test Update
0fd8f43
Update test/Microsoft.IdentityModel.TestUtils/ReferenceTokens.cs
trwalke 376c1ce
Update
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -9,7 +9,6 @@ | |
| using System.Security.Cryptography; | ||
| using System.Security.Cryptography.X509Certificates; | ||
| using Microsoft.IdentityModel.Tokens; | ||
| using Microsoft.IdentityModel.Tokens.Json; | ||
| using Microsoft.IdentityModel.Tokens.Saml; | ||
| using Microsoft.IdentityModel.Tokens.Saml2; | ||
| using Microsoft.IdentityModel.Xml; | ||
|
|
@@ -398,38 +397,6 @@ public static string AadPayloadString | |
| }.ToString(); | ||
| } | ||
|
|
||
| public static string PayloadString | ||
| { | ||
| get => new JObject() | ||
| { | ||
| { JwtRegisteredClaimNames.Aud, Audience }, | ||
| { JwtRegisteredClaimNames.Azp, Azp }, | ||
| { JwtRegisteredClaimNames.Email, "[email protected]" }, | ||
| { JwtRegisteredClaimNames.Exp, EpochTime.GetIntDate(Expires).ToString() }, | ||
| { JwtRegisteredClaimNames.GivenName, "Bob" }, | ||
| { JwtRegisteredClaimNames.Iss, Issuer }, | ||
| { JwtRegisteredClaimNames.Iat, EpochTime.GetIntDate(IssueInstant).ToString() }, | ||
| { JwtRegisteredClaimNames.Jti, Jti }, | ||
| { JwtRegisteredClaimNames.Nbf, EpochTime.GetIntDate(NotBefore).ToString()}, | ||
| }.ToString(Formatting.None); | ||
| } | ||
|
|
||
| public static string PayloadStringMultipleAudiences | ||
| { | ||
| get => new JObject() | ||
| { | ||
| { JwtRegisteredClaimNames.Aud, JArray.FromObject(Audiences) }, | ||
| { JwtRegisteredClaimNames.Azp, Azp }, | ||
| { JwtRegisteredClaimNames.Email, "[email protected]" }, | ||
| { JwtRegisteredClaimNames.Exp, EpochTime.GetIntDate(Expires).ToString() }, | ||
| { JwtRegisteredClaimNames.GivenName, "Bob" }, | ||
| { JwtRegisteredClaimNames.Iss, Issuer }, | ||
| { JwtRegisteredClaimNames.Iat, EpochTime.GetIntDate(IssueInstant).ToString() }, | ||
| { JwtRegisteredClaimNames.Jti, Jti }, | ||
| { JwtRegisteredClaimNames.Nbf, EpochTime.GetIntDate(NotBefore).ToString()}, | ||
| }.ToString(Formatting.None); | ||
| } | ||
|
|
||
| public static List<Claim> PayloadClaims | ||
| { | ||
| get => new List<Claim>() | ||
|
|
@@ -484,34 +451,17 @@ public static List<Claim> PayloadJsonClaims | |
|
|
||
| public static Dictionary<string, object> PayloadJsonDictionary | ||
| { | ||
| get => new Dictionary<string, object>() | ||
| { | ||
| { JwtRegisteredClaimNames.Aud, Audience }, | ||
| { JwtRegisteredClaimNames.Iss, Issuer }, | ||
| { "ClaimValueTypes.String", "ClaimValueTypes.String.Value" }, | ||
| { "ClaimValueTypes.Boolean.true", true }, | ||
| { "ClaimValueTypes.Boolean.false", false }, | ||
| { "ClaimValueTypes.Double", 123.4 }, | ||
| { "ClaimValueTypes.DateTime.IS8061", DateTime.TryParse("2019-11-15T14:31:21.6101326Z", out DateTime dateTimeValue1) ? dateTimeValue1.ToUniversalTime() : new DateTime()}, | ||
| { "ClaimValueTypes.DateTime", DateTime.TryParse("2019-11-15", out DateTime dateTimeValue2) ? dateTimeValue2 : new DateTime()}, | ||
| { "ClaimValueTypes.JsonClaimValueTypes.Json1", JObject.Parse(@"{""jsonProperty1"":""jsonvalue1""}") }, | ||
| { "ClaimValueTypes.JsonClaimValueTypes.Json2", JObject.Parse(@"{""jsonProperty2"":""jsonvalue2""}") }, | ||
| { "ClaimValueTypes.JsonClaimValueTypes.JsonNull", "" }, | ||
| { "ClaimValueTypes.JsonClaimValueTypes.JsonArray1", JArray.Parse(@"[1,2,3]") }, | ||
| { "ClaimValueTypes.JsonClaimValueTypes.JsonArray2", JArray.Parse(@"[1,""2"",3]") }, | ||
| { "ClaimValueTypes.JsonClaimValueTypes.Integer1", 1 }, | ||
| { JwtRegisteredClaimNames.Exp, EpochTime.GetIntDate(Expires).ToString() } | ||
| }; | ||
| get => PayloadJsonClaims.ToDictionary(x => x.Type, x => (object)x.Value); | ||
| } | ||
|
|
||
| public static ClaimsIdentity PayloadClaimsIdentity | ||
| { | ||
| get => new CaseSensitiveClaimsIdentity(PayloadClaims, "AuthenticationTypes.Federation"); | ||
| } | ||
|
|
||
| public static Dictionary<string, object> PayloadDictionary | ||
| public static JObject PayloadAsJObject | ||
| { | ||
| get => new Dictionary<string, object>() | ||
| get => new JObject() | ||
| { | ||
| { JwtRegisteredClaimNames.Aud, Audience }, | ||
| { JwtRegisteredClaimNames.Azp, Azp }, | ||
|
|
@@ -525,11 +475,21 @@ public static Dictionary<string, object> PayloadDictionary | |
| }; | ||
| } | ||
|
|
||
| public static Dictionary<string, object> PayloadDictionaryMultipleAudiences | ||
| public static string PayloadString | ||
| { | ||
| get => PayloadAsJObject.ToString(Formatting.None); | ||
| } | ||
|
|
||
| public static Dictionary<string, object> PayloadDictionary | ||
| { | ||
| get => PayloadAsJObject.ToObject<Dictionary<string, object>>(); | ||
| } | ||
|
|
||
| public static JObject PayloadAsJObjectMultipleAudiences | ||
| { | ||
| get => new Dictionary<string, object>() | ||
| get => new JObject() | ||
| { | ||
| { JwtRegisteredClaimNames.Aud, JsonSerializerPrimitives.CreateJsonElement(Default.Audiences) }, | ||
| { JwtRegisteredClaimNames.Aud, JArray.FromObject(Audiences) }, | ||
| { JwtRegisteredClaimNames.Azp, Azp }, | ||
| { JwtRegisteredClaimNames.Email, "[email protected]" }, | ||
| { JwtRegisteredClaimNames.Exp, EpochTime.GetIntDate(Expires).ToString() }, | ||
|
|
@@ -541,6 +501,16 @@ public static Dictionary<string, object> PayloadDictionaryMultipleAudiences | |
| }; | ||
| } | ||
|
|
||
| public static string PayloadStringMultipleAudiences | ||
| { | ||
| get => PayloadAsJObjectMultipleAudiences.ToString(Formatting.None); | ||
| } | ||
|
|
||
| public static Dictionary<string, object> PayloadDictionaryMultipleAudiences | ||
| { | ||
| get => PayloadAsJObjectMultipleAudiences.ToObject<Dictionary<string, object>>(); | ||
| } | ||
|
|
||
| public static Dictionary<string, object> RemoveClaim(this Dictionary<string, object> payloadClaims, string claimName) | ||
| { | ||
| payloadClaims.Remove(claimName); | ||
|
|
@@ -859,20 +829,37 @@ public static List<Claim> SamlClaims | |
|
|
||
| /// <summary> | ||
| /// SamlClaims require the ability to split into name / namespace | ||
| /// The <see cref="ClaimTypes.Role"/> claims are added as a list | ||
| /// </summary> | ||
| public static Dictionary<string, object> SamlClaimsDictionary | ||
| { | ||
| get => new Dictionary<string, object>() | ||
| get | ||
| { | ||
| { ClaimTypes.Country, "USA"}, | ||
| { ClaimTypes.NameIdentifier, "Bob" }, | ||
| { ClaimTypes.Email, "[email protected]" }, | ||
| { ClaimTypes.GivenName, "Bob" }, | ||
| { ClaimTypes.HomePhone, "555.1212" }, | ||
| { ClaimTypes.Role, new List<string>{"Developer", "Sales" } }, | ||
| { ClaimTypes.StreetAddress, "123AnyWhereStreet\r\nSomeTown/r/nUSA" }, | ||
| { ClaimsIdentity.DefaultNameClaimType, "Jean-S�bastien" } | ||
| }; | ||
| Dictionary<string, object> dictionary = new Dictionary<string, object>(); | ||
|
|
||
| foreach (Claim claim in SamlClaims) | ||
| { | ||
| if (dictionary.ContainsKey(claim.Type)) | ||
| { | ||
| if (claim.Type == ClaimTypes.Role) | ||
| { | ||
| ((List<string>)dictionary[claim.Type]).Add(claim.Value); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| if (claim.Type == ClaimTypes.Role) | ||
| { | ||
| dictionary[claim.Type] = new List<string> { claim.Value }; | ||
| } | ||
| else | ||
| { | ||
| dictionary[claim.Type] = claim.Value; | ||
| } | ||
| } | ||
| } | ||
| return dictionary; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -373,39 +373,32 @@ public static string SamlToken_Formated | |
| // { "int", 123 }. | ||
| public static string JWSWithSingleAdditionalHeaderClaim = "eyJhbGciOiJSUzI1NiIsImtpZCI6Ikpzb25XZWJLZXlSc2FfMjA0OCIsInR5cCI6IkpXVCIsImludCI6MTIzfQ.eyJlbWFpbCI6IkJvYkBjb250b3NvLmNvbSIsImdpdmVuX25hbWUiOiJCb2IiLCJpc3MiOiJodHRwOi8vRGVmYXVsdC5Jc3N1ZXIuY29tIiwiYXVkIjoiaHR0cDovL0RlZmF1bHQuQXVkaWVuY2UuY29tIiwiaWF0IjoiMTQ4OTc3NTYxNyIsIm5iZiI6IjE0ODk3NzU2MTciLCJleHAiOiIyNTM0MDIzMDA3OTkifQ.DhPiCtD9HWTjG5LDCW8YxSaBXffmPosGnnKINuey6ec50Yf72SzBnMDVZ4Cw9S_SyqSRIxVs0x87g0ZUP8fytUxr_D7ksf0cBI9tqh2MgoAZ2lY8T8oflfIBaTLraZHRmjRCMZGdOLmGj__xqM7mmD0Y1grwAkQgMCLlze2qgCXmym_8jAWfSLQcNc-XNUaDZBlbgebic7TZ0INa93QcJvm_ov6t_rg90Y0l4xCxL_VOdXctdbc5D87bEaaAdqThfVMA1325JZdS_CBWVelLf5zZYPldVDxnD9l93Fy0gqWTWJ0QxMP-BDMgXbQQdUDoSC5HrxXU2JRXnF8V_V4G2g"; | ||
|
|
||
|
|
||
| // This token is unsigned and includes one additional header claim: | ||
| // { "int", 123 }. | ||
| public static string UnsignedJWSWithSingleAdditionalHeaderClaim = "eyJhbGciOiJub25lIiwidHlwIjoiSldUIiwiaW50IjoxMjN9.eyJlbWFpbCI6IkJvYkBjb250b3NvLmNvbSIsImdpdmVuX25hbWUiOiJCb2IiLCJpc3MiOiJodHRwOi8vRGVmYXVsdC5Jc3N1ZXIuY29tIiwiYXVkIjoiaHR0cDovL0RlZmF1bHQuQXVkaWVuY2UuY29tIiwiaWF0IjoiMTQ4OTc3NTYxNyIsIm5iZiI6IjE0ODk3NzU2MTciLCJleHAiOiIyNTM0MDIzMDA3OTkifQ."; | ||
|
|
||
| // the following values are separate from the one in Default.cs, so we can change the Defaults | ||
| // Do not change any of these values either adding new values or order or the tests will break. | ||
| public static Dictionary<string, object> PayloadDictionary | ||
| public static JObject PayloadAsJObject | ||
| { | ||
| get => new Dictionary<string, object>() | ||
| get => new JObject() | ||
| { | ||
| { JwtRegisteredClaimNames.Email, "[email protected]" }, | ||
| { JwtRegisteredClaimNames.GivenName, "Bob" }, | ||
| { JwtRegisteredClaimNames.Iss, Issuer }, | ||
| { JwtRegisteredClaimNames.Aud, Audience }, | ||
| { JwtRegisteredClaimNames.Iat, EpochTime.GetIntDate(IssueInstant).ToString() }, | ||
| { JwtRegisteredClaimNames.Nbf, EpochTime.GetIntDate(NotBefore).ToString()}, | ||
| { JwtRegisteredClaimNames.Exp, EpochTime.GetIntDate(Expires).ToString() } | ||
| { JwtRegisteredClaimNames.Exp, EpochTime.GetIntDate(Expires).ToString() }, | ||
trwalke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
| } | ||
|
|
||
| public static string PayloadString | ||
| { | ||
| get => new JObject() | ||
| { | ||
| { JwtRegisteredClaimNames.Email, "[email protected]" }, | ||
| { JwtRegisteredClaimNames.GivenName, "Bob" }, | ||
| { JwtRegisteredClaimNames.Iss, Issuer }, | ||
| { JwtRegisteredClaimNames.Aud, Audience }, | ||
| { JwtRegisteredClaimNames.Iat, EpochTime.GetIntDate(IssueInstant).ToString() }, | ||
| { JwtRegisteredClaimNames.Nbf, EpochTime.GetIntDate(NotBefore).ToString()}, | ||
| { JwtRegisteredClaimNames.Exp, EpochTime.GetIntDate(Expires).ToString() }, | ||
| }.ToString(Formatting.None); | ||
| get => PayloadAsJObject.ToString(Formatting.None); | ||
| } | ||
|
|
||
| public static Dictionary<string, object> PayloadDictionary | ||
| { | ||
| get => PayloadAsJObject.ToObject<Dictionary<string, object>>(); | ||
| } | ||
|
|
||
| public static string Audience | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.