Skip to content
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

Restore AOT compatibility for IdentityModel #2773

Merged
merged 3 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public enum ExceptionType
SecurityTokenReplayDetected,
SecurityTokenReplayAddFailed,
SecurityTokenSignatureKeyNotFound,
ExceptionTypeCount
}

private Exception ExceptionFromType(ExceptionType exceptionType, Exception innerException)
Expand Down
19 changes: 19 additions & 0 deletions test/Microsoft.IdentityModel.TestUtils/ExpectedException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,25 @@ public static ExpectedException JsonException(string substringExpected = null, T
{
return new ExpectedException(typeof(JsonException), substringExpected, innerTypeExpected);
}
public static ExpectedException SecurityTokenDecompressionFailedException(string substringExpected = null, Type innerTypeExpected = null)
iNinja marked this conversation as resolved.
Show resolved Hide resolved
{
return new ExpectedException(typeof(SecurityTokenDecompressionFailedException), substringExpected, innerTypeExpected);
}

public static ExpectedException SecurityTokenMalformedException(string substringExpected = null, Type innerTypeExpected = null)
{
return new ExpectedException(typeof(SecurityTokenMalformedException), substringExpected, innerTypeExpected);
}

public static ExpectedException SecurityTokenReplayDetectedException(string substringExpected = null, Type innerTypeExpected = null)
{
return new ExpectedException(typeof(SecurityTokenReplayDetectedException), substringExpected, innerTypeExpected);
}

public static ExpectedException SecurityTokenReplayAddFailedException(string substringExpected = null, Type innerTypeExpected = null)
{
return new ExpectedException(typeof(SecurityTokenReplayAddFailedException), substringExpected, innerTypeExpected);
}

public bool IgnoreExceptionType { get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.


using System;
using System.Linq;
using Microsoft.IdentityModel.TestUtils;
using Xunit;

namespace Microsoft.IdentityModel.Tokens.Tests
{
public class ExceptionDetailsTests
{
[Theory, MemberData(nameof(ExceptionDetailsTestCases), DisableDiscoveryEnumeration = true)]
public void ExceptionDetails(ExceptionDetailsTheoryData theoryData)
{
var context = TestUtilities.WriteHeader($"{this}.ExceptionDetails", theoryData);
ExceptionDetail exceptionDetail = new ExceptionDetail(
new MessageDetail(""),
theoryData.ExceptionType,
new System.Diagnostics.StackFrame());

theoryData.ExpectedException.ProcessException(exceptionDetail.GetException(), context);

TestUtilities.AssertFailIfErrors(context);
}

[Fact]
public void ExceptionDetails_UnknownType_Throws()
{
ExceptionDetail exceptionDetail = new ExceptionDetail(
new MessageDetail(""),
ExceptionDetail.ExceptionType.Unknown,
new System.Diagnostics.StackFrame());

Assert.Throws<ArgumentException>(() => exceptionDetail.GetException());
}

[Fact]
public void All_ExceptionDetails_HaveTests()
{
// If this test fails, we are missing a test for a new ExceptionDetail.ExceptionType
Assert.Equal(((int)ExceptionDetail.ExceptionType.ExceptionTypeCount), ExceptionDetailsTestCases.Count());
}

public static TheoryData<ExceptionDetailsTheoryData> ExceptionDetailsTestCases
{
get
{
return new()
{
new ExceptionDetailsTheoryData
{
TestId = "ArgumentNull",
ExceptionType = ExceptionDetail.ExceptionType.ArgumentNull,
ExpectedException = ExpectedException.ArgumentNullException(),
},
new ExceptionDetailsTheoryData
{
TestId = "InvalidOperation",
ExceptionType = ExceptionDetail.ExceptionType.InvalidOperation,
ExpectedException = ExpectedException.InvalidOperationException(),
},
new ExceptionDetailsTheoryData
{
TestId = "SecurityToken",
ExceptionType = ExceptionDetail.ExceptionType.SecurityToken,
ExpectedException = ExpectedException.SecurityTokenException(),
},
new ExceptionDetailsTheoryData
{
TestId = "SecurityTokenDecompressionFailed",
ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenDecompressionFailed,
ExpectedException = ExpectedException.SecurityTokenDecompressionFailedException(),
},
new ExceptionDetailsTheoryData
{
TestId = "SecurityTokenDecryptionFailed",
ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenDecryptionFailed,
ExpectedException = ExpectedException.SecurityTokenDecryptionFailedException(),
},
new ExceptionDetailsTheoryData
{
TestId = "SecurityTokenExpired",
ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenExpired,
ExpectedException = ExpectedException.SecurityTokenExpiredException(),
},
new ExceptionDetailsTheoryData
{
TestId = "SecurityTokenInvalidAudience",
ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenInvalidAudience,
ExpectedException = ExpectedException.SecurityTokenInvalidAudienceException(),
},
new ExceptionDetailsTheoryData
{
TestId = "SecurityTokenInvalidAlgorithm",
ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenInvalidAlgorithm,
ExpectedException = ExpectedException.SecurityTokenInvalidAlgorithmException(),
},
new ExceptionDetailsTheoryData
{
TestId = "SecurityTokenInvalidIssuer",
ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenInvalidIssuer,
ExpectedException = ExpectedException.SecurityTokenInvalidIssuerException(),
},
new ExceptionDetailsTheoryData
{
TestId = "SecurityTokenInvalidLifetime",
ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenInvalidLifetime,
ExpectedException = ExpectedException.SecurityTokenInvalidLifetimeException(),
},
new ExceptionDetailsTheoryData
{
TestId = "SecurityTokenInvalidSigningKey",
ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenInvalidSigningKey,
ExpectedException = ExpectedException.SecurityTokenInvalidSigningKeyException(),
},
new ExceptionDetailsTheoryData
{
TestId = "SecurityTokenInvalidSignature",
ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenInvalidSignature,
ExpectedException = ExpectedException.SecurityTokenInvalidSignatureException(),
},
new ExceptionDetailsTheoryData
{
TestId = "SecurityTokenInvalidType",
ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenInvalidType,
ExpectedException = ExpectedException.SecurityTokenInvalidTypeException(),
},
new ExceptionDetailsTheoryData
{
TestId = "SecurityTokenKeyWrap",
ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenKeyWrap,
ExpectedException = ExpectedException.SecurityTokenKeyWrapException(),
},
new ExceptionDetailsTheoryData
{
TestId = "SecurityTokenMalformed",
ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenMalformed,
ExpectedException = ExpectedException.SecurityTokenMalformedException(),
},
new ExceptionDetailsTheoryData
{
TestId = "SecurityTokenNoExpiration",
ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenNoExpiration,
ExpectedException = ExpectedException.SecurityTokenNoExpirationException(),
},
new ExceptionDetailsTheoryData
{
TestId = "SecurityTokenNotYetValid",
ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenNotYetValid,
ExpectedException = ExpectedException.SecurityTokenNotYetValidException(),
},
new ExceptionDetailsTheoryData
{
TestId = "SecurityTokenReplayDetected",
ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenReplayDetected,
ExpectedException = ExpectedException.SecurityTokenReplayDetectedException(),
},
new ExceptionDetailsTheoryData
{
TestId = "SecurityTokenReplayAddFailed",
ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenReplayAddFailed,
ExpectedException = ExpectedException.SecurityTokenReplayAddFailedException(),
},
new ExceptionDetailsTheoryData
{
TestId = "SecurityTokenSignatureKeyNotFound",
ExceptionType = ExceptionDetail.ExceptionType.SecurityTokenSignatureKeyNotFound,
ExpectedException = ExpectedException.SecurityTokenSignatureKeyNotFoundException(),
},
};
}
}
}

public class ExceptionDetailsTheoryData : TheoryDataBase
{
internal ExceptionDetail.ExceptionType ExceptionType { get; set; }
}
}
Loading