-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New token validation model: Simplify stack frame caching (#2976)
* Added methods to ValidationError to simplify the caching of StackFrame objects by using a concurrent dictionary * Changed methods to be internal
- Loading branch information
Showing
3 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
45 changes: 45 additions & 0 deletions
45
test/Microsoft.IdentityModel.Tokens.Tests/Validation/ValidationErrorTests.cs
This file contains 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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using Xunit; | ||
|
||
namespace Microsoft.IdentityModel.Tokens.Tests | ||
{ | ||
public class ValidationErrorTests | ||
{ | ||
[Fact] | ||
public void ExceptionCreatedFromValidationError_ContainsTheRightStackTrace() | ||
{ | ||
var validationError = new ValidationErrorReturningClass().firstMethod(); | ||
Assert.NotNull(validationError); | ||
Assert.NotNull(validationError.StackFrames); | ||
Assert.Equal(3, validationError.StackFrames.Count); | ||
Assert.NotNull(validationError.GetException()); | ||
Assert.NotNull(validationError.GetException().StackTrace); | ||
Assert.Equal("thirdMethod", validationError.StackFrames[0].GetMethod().Name); | ||
Assert.Equal("secondMethod", validationError.StackFrames[1].GetMethod().Name); | ||
Assert.Equal("firstMethod", validationError.StackFrames[2].GetMethod().Name); | ||
} | ||
class ValidationErrorReturningClass | ||
{ | ||
public ValidationError firstMethod() | ||
{ | ||
return secondMethod().AddCurrentStackFrame(); | ||
} | ||
|
||
public ValidationError secondMethod() | ||
{ | ||
return thirdMethod().AddCurrentStackFrame(); | ||
} | ||
|
||
public ValidationError thirdMethod() | ||
{ | ||
return new ValidationError( | ||
new MessageDetail("This is a test error"), | ||
ValidationFailureType.NullArgument, | ||
typeof(SecurityTokenArgumentNullException), | ||
ValidationError.GetCurrentStackFrame()); | ||
} | ||
} | ||
} | ||
} |