Skip to content

Commit

Permalink
Adjust uppercase json serialization tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HP712 committed Feb 29, 2024
1 parent aa7d838 commit 2d49891
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 58 deletions.
2 changes: 1 addition & 1 deletion build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<!-- Wilson version -->
<PropertyGroup>
<WilsonCurrentVersion>7.4.0</WilsonCurrentVersion>
<WilsonCurrentVersion>7.4.1</WilsonCurrentVersion>

<PreviewVersionSuffix Condition="'$(PreviewVersionSuffix)' == '' and '$(BuildingInsideVisualStudio)' != 'true'">preview-$([System.DateTime]::Now.AddYears(-2019).Year)$([System.DateTime]::Now.ToString("MMddHHmmss"))</PreviewVersionSuffix>
<!--VS re-evaluates the variables, so having seconds or minutes creates an infinite loop of package updates-->
Expand Down
2 changes: 2 additions & 0 deletions buildPack.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dotnet build /r Product.proj
dotnet pack --no-restore -o artifacts --no-build Product.proj
2 changes: 1 addition & 1 deletion buildTestPack.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
dotnet build /r Product.proj
dotnet test --no-restore --no-build Product.proj
dotnet pack --no-restore --no-build Product.proj
dotnet pack --no-restore -o artifacts --no-build Product.proj
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ internal static string ReadString(ref Utf8JsonReader reader, string propertyName

if (!IsReaderAtTokenType(ref reader, JsonTokenType.String, false))
throw LogHelper.LogExceptionMessage(
CreateJsonReaderExceptionInvalidType(ref reader, "JsonTokenType.StartArray", className, propertyName));
CreateJsonReaderExceptionInvalidType(ref reader, "JsonTokenType.String", className, propertyName));

string retval = reader.GetString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public static OpenIdConnectConfiguration FullyPopulatedWithKeys
#endregion

#region GOOGLE 2/2/2024 https://accounts.google.com/.well-known/openid-configuration
public static string AccountsGoogleCom =>
public static string AccountsGoogleComJson =>
$$"""
{
"issuer": "https://accounts.google.com",
Expand Down Expand Up @@ -225,7 +225,7 @@ public static OpenIdConnectConfiguration AccountsGoogleComConfig
#endregion

#region AADCommonV1 2/2/2024 https://login.microsoftonline.com/common/.well-known/openid-configuration
public static string AADCommonV1 =>
public static string AADCommonV1Json =>
"""
{
"token_endpoint": "https://login.microsoftonline.com/common/oauth2/token",
Expand Down Expand Up @@ -294,7 +294,7 @@ public static OpenIdConnectConfiguration AADCommonV1Config
#endregion

#region AADCommonV2 2/2/2024 https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration
public static string AADCommonV2 =>
public static string AADCommonV2Json =>
"""
{
"token_endpoint": "https://login.microsoftonline.com/common/oauth2/v2.0/token",
Expand Down Expand Up @@ -322,6 +322,7 @@ public static OpenIdConnectConfiguration AADCommonV1Config
"rbac_url": "https://pas.windows.net"
}
""";

public static OpenIdConnectConfiguration AADCommonV2Config
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,24 @@ public static TheoryData<OpenIdConnectTheoryData> DesrializeTheoryData
{
TheoryData<OpenIdConnectTheoryData> theoryData = new TheoryData<OpenIdConnectTheoryData>();

theoryData.Add(new OpenIdConnectTheoryData("AADCommonV1Config")
// the reason to replace AdditionalData with upper case is because the test deserializes uppercase and lowercase.
// we wanted to leave the data sets in original form from discovery to be used in other tests.
theoryData.Add(new OpenIdConnectTheoryData("AADCommonV1")
{
CompareTo = OpenIdConfigData.AADCommonV1Config,
Json = OpenIdConfigData.AADCommonV1
CompareTo = JsonUtilities.SetAdditionalDataKeysToUpperCase(OpenIdConfigData.AADCommonV1Config),
Json = JsonUtilities.SetAdditionalDataKeysToUpperCase(OpenIdConfigData.AADCommonV1Json, OpenIdConfigData.AADCommonV1Config)
});

theoryData.Add(new OpenIdConnectTheoryData("AADCommonV2Config")
theoryData.Add(new OpenIdConnectTheoryData("AADCommonV2")
{
CompareTo = OpenIdConfigData.AADCommonV2Config,
Json = OpenIdConfigData.AADCommonV2
CompareTo = JsonUtilities.SetAdditionalDataKeysToUpperCase(OpenIdConfigData.AADCommonV2Config),
Json = JsonUtilities.SetAdditionalDataKeysToUpperCase(OpenIdConfigData.AADCommonV2Json, OpenIdConfigData.AADCommonV2Config)
});

theoryData.Add(new OpenIdConnectTheoryData("AccountsGoogleCom")
{
CompareTo = OpenIdConfigData.AccountsGoogleComConfig,
Json = OpenIdConfigData.AccountsGoogleCom
CompareTo = JsonUtilities.SetAdditionalDataKeysToUpperCase(OpenIdConfigData.AccountsGoogleComConfig),
Json = JsonUtilities.SetAdditionalDataKeysToUpperCase(OpenIdConfigData.AccountsGoogleComJson, OpenIdConfigData.AccountsGoogleComConfig)
});

theoryData.Add(new OpenIdConnectTheoryData("FrontChannelFalse")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<ProjectReference Include="..\..\src\Microsoft.IdentityModel.JsonWebTokens\Microsoft.IdentityModel.JsonWebTokens.csproj" />
<ProjectReference Include="..\..\src\Microsoft.IdentityModel.Protocols.SignedHttpRequest\Microsoft.IdentityModel.Protocols.SignedHttpRequest.csproj" />
<ProjectReference Include="..\..\src\Microsoft.IdentityModel.Tokens\Microsoft.IdentityModel.Tokens.csproj" />
<ProjectReference Include="..\Microsoft.IdentityModel.Tokens.Tests\Microsoft.IdentityModel.Tokens.Tests.csproj" />
<ProjectReference Include="..\Microsoft.IdentityModel.TestUtils\Microsoft.IdentityModel.TestUtils.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.IdentityModel.JsonWebTokens;
using Microsoft.IdentityModel.TestUtils;
using Microsoft.IdentityModel.Tokens;
using Microsoft.IdentityModel.Tokens.Json.Tests;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using Microsoft.IdentityModel.TestUtils;
using Microsoft.IdentityModel.Tokens.Json.Tests;
using Xunit;

namespace Microsoft.IdentityModel.Tokens.Tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
// Licensed under the MIT License.

using System.Collections.Generic;
using Microsoft.IdentityModel.Tokens;

/// <summary>
/// Data sets for testing
/// </summary>
namespace Microsoft.IdentityModel.TestUtils
namespace Microsoft.IdentityModel.Tokens.Json.Tests
{
public class DataSets
{
Expand Down Expand Up @@ -360,7 +359,7 @@ public static JsonWebKey JsonWebKeyBadX509Data
public static string JsonWebKeySetUseNoKtyString = @"{ ""keys"":[" + JsonWebKeyNoKtyString + "]}";

#region GOOGLE 2/2/2024 https://www.googleapis.com/oauth2/v3/certs
public static string AccountsGoogle =
public static string AccountsGoogleJson =
"""
{
"keys": [
Expand Down Expand Up @@ -430,7 +429,7 @@ public static JsonWebKeySet AccountsGoogleKeySet
#endregion

#region AADCommonV1 2/2/2024 https://login.microsoftonline.com/common/discovery/keys
public static string AADCommonKeySetString_V1 =
public static string AADCommonV1KeySetJson =
"""
{
"keys": [
Expand Down Expand Up @@ -471,7 +470,7 @@ public static JsonWebKeySet AccountsGoogleKeySet
}
""";

public static JsonWebKey AADCommonKey1_V1
public static JsonWebKey AADCommonV1Key1
{
get
{
Expand All @@ -489,7 +488,7 @@ public static JsonWebKey AADCommonKey1_V1
}
}

public static JsonWebKey AADCommonKey2_V1
public static JsonWebKey AADCommonV1Key2
{
get
{
Expand All @@ -507,7 +506,7 @@ public static JsonWebKey AADCommonKey2_V1
}
}

public static JsonWebKey AADCommonKey3_V1
public static JsonWebKey AADCommonV1Key3
{
get
{
Expand All @@ -525,29 +524,29 @@ public static JsonWebKey AADCommonKey3_V1
}
}

public static JsonWebKeySet AADCommonKeySet_V1
public static JsonWebKeySet AADCommonV1KeySet
{
get
{
return new JsonWebKeySet
{
Keys = new List<JsonWebKey>
{
AADCommonKey1_V1,
AADCommonKey2_V1,
AADCommonKey3_V1
AADCommonV1Key1,
AADCommonV1Key2,
AADCommonV1Key3
}
};
}
}

#endregion

#region AADCommonV2 2/2/2024 https://login.microsoftonline.com/common/discovery/v2.0/keys
public static string AADCommonKeySetString_V2 =
public static string AADCommonV2KeySetJson =
"""
{
"keys": [
{
"keys":
[
{
"kty": "RSA",
"use": "sig",
Expand Down Expand Up @@ -612,7 +611,7 @@ public static JsonWebKeySet AADCommonKeySet_V1
}
""";

public static JsonWebKey AADCommonKey1_V2
public static JsonWebKey AADCommonV2Key1
{
get
{
Expand All @@ -631,7 +630,7 @@ public static JsonWebKey AADCommonKey1_V2
}
}

public static JsonWebKey AADCommonKey2_V2
public static JsonWebKey AADCommonV2Key2
{
get
{
Expand All @@ -650,7 +649,7 @@ public static JsonWebKey AADCommonKey2_V2
}
}

public static JsonWebKey AADCommonKey3_V2
public static JsonWebKey AADCommonV2Key3
{
get
{
Expand All @@ -669,7 +668,7 @@ public static JsonWebKey AADCommonKey3_V2
}
}

public static JsonWebKey AADCommonKey4_V2
public static JsonWebKey AADCommonV2Key4
{
get
{
Expand All @@ -688,7 +687,7 @@ public static JsonWebKey AADCommonKey4_V2
}
}

public static JsonWebKey AADCommonKey5_V2
public static JsonWebKey AADCommonV2Key5
{
get
{
Expand All @@ -707,19 +706,19 @@ public static JsonWebKey AADCommonKey5_V2
}
}

public static JsonWebKeySet AADCommonKeySet_V2
public static JsonWebKeySet AADCommonV2KeySet
{
get
{
return new JsonWebKeySet
{
Keys = new List<JsonWebKey>
{
AADCommonKey1_V2,
AADCommonKey2_V2,
AADCommonKey3_V2,
AADCommonKey4_V2,
AADCommonKey5_V2
AADCommonV2Key1,
AADCommonV2Key2,
AADCommonV2Key3,
AADCommonV2Key4,
AADCommonV2Key5
}
};
}
Expand Down
17 changes: 9 additions & 8 deletions test/Microsoft.IdentityModel.Tokens.Tests/Json/JsonData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ namespace Microsoft.IdentityModel.Tokens.Json.Tests
public static class JsonData
{
// Create a unique string for each property, to avoid collisions
public static string ArrayProperty = Guid.NewGuid().ToString();
public static string ObjectProperty = Guid.NewGuid().ToString();
public static string FalseProperty = Guid.NewGuid().ToString();
public static string TrueProperty = Guid.NewGuid().ToString();
public static string StringProperty = Guid.NewGuid().ToString();
public static string StringValue = Guid.NewGuid().ToString();
public static string NullProperty = Guid.NewGuid().ToString();
// Moved these to UpperInvariant so test that perform uppercase to lowercase will work.
public static string ArrayProperty = Guid.NewGuid().ToString().ToUpperInvariant();
public static string ObjectProperty = Guid.NewGuid().ToString().ToUpperInvariant();
public static string FalseProperty = Guid.NewGuid().ToString().ToUpperInvariant();
public static string TrueProperty = Guid.NewGuid().ToString().ToUpperInvariant();
public static string StringProperty = Guid.NewGuid().ToString().ToUpperInvariant();
public static string StringValue = Guid.NewGuid().ToString().ToUpperInvariant();
public static string NullProperty = Guid.NewGuid().ToString().ToUpperInvariant();

// Json strings are name:value (claim) pairs inside an object
// The naming here is:
Expand Down Expand Up @@ -47,7 +48,7 @@ public static class JsonData

public static string ObjectValue =
$$"""
{"object":["ObjectValue1","ObjectValue2"]}
{"OBJECT":["ObjectValue1","ObjectValue2"]}
""";

public static string ObjectClaim =
Expand Down
Loading

0 comments on commit 2d49891

Please sign in to comment.