Skip to content

Commit 4ed421d

Browse files
committed
Rename JWT issuer extensibility tests to better align on the solution explorer. Simplified creation of stack frames for comparison
1 parent 2609624 commit 4ed421d

File tree

1 file changed

+39
-61
lines changed

1 file changed

+39
-61
lines changed

test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.Issuer.Extensibility.cs renamed to test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandler.Extensibility.Issuer.cs

Lines changed: 39 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
// Licensed under the MIT License.
33

44
using System;
5-
using System.Collections.Generic;
65
using System.Diagnostics;
76
using System.Threading;
87
using System.Threading.Tasks;
98
using Microsoft.IdentityModel.JsonWebTokens.Tests;
9+
using Microsoft.IdentityModel.Logging;
1010
using Microsoft.IdentityModel.TestUtils;
1111
using Microsoft.IdentityModel.Tokens;
1212
using Microsoft.IdentityModel.Tokens.Json.Tests;
@@ -22,8 +22,8 @@ public async Task ValidateTokenAsync_IssuerValidator_Extensibility(IssuerExtensi
2222
{
2323
var context = TestUtilities.WriteHeader($"{this}.{nameof(ValidateTokenAsync_IssuerValidator_Extensibility)}", theoryData);
2424
context.IgnoreType = false;
25-
for (int i = 1; i < theoryData.StackFrames.Count; i++)
26-
theoryData.IssuerValidationError!.AddStackFrame(theoryData.StackFrames[i]);
25+
for (int i = 0; i < theoryData.ExtraStackFrames; i++)
26+
theoryData.IssuerValidationError!.AddStackFrame(new StackFrame(false));
2727

2828
try
2929
{
@@ -69,11 +69,7 @@ public static TheoryData<IssuerExtensibilityTheoryData> Issuer_ExtensibilityTest
6969
"CustomIssuerValidatorDelegate",
7070
issuerGuid,
7171
CustomIssuerValidationDelegates.CustomIssuerValidatorDelegateAsync,
72-
[
73-
new StackFrame("CustomIssuerValidationDelegates", 88),
74-
new StackFrame(false),
75-
new StackFrame(false)
76-
])
72+
extraStackFrames: 2)
7773
{
7874
ExpectedException = new ExpectedException(
7975
typeof(SecurityTokenInvalidIssuerException),
@@ -82,7 +78,7 @@ public static TheoryData<IssuerExtensibilityTheoryData> Issuer_ExtensibilityTest
8278
new MessageDetail(
8379
nameof(CustomIssuerValidationDelegates.CustomIssuerValidatorDelegateAsync), null),
8480
typeof(SecurityTokenInvalidIssuerException),
85-
new StackFrame("CustomIssuerValidationDelegates", 88),
81+
new StackFrame("CustomIssuerValidationDelegates.cs", 88),
8682
issuerGuid)
8783
});
8884

@@ -91,11 +87,7 @@ public static TheoryData<IssuerExtensibilityTheoryData> Issuer_ExtensibilityTest
9187
"CustomIssuerValidatorCustomExceptionDelegate",
9288
issuerGuid,
9389
CustomIssuerValidationDelegates.CustomIssuerValidatorCustomExceptionDelegateAsync,
94-
[
95-
new StackFrame("CustomIssuerValidationDelegates", 107),
96-
new StackFrame(false),
97-
new StackFrame(false)
98-
])
90+
extraStackFrames: 2)
9991
{
10092
ExpectedException = new ExpectedException(
10193
typeof(CustomSecurityTokenInvalidIssuerException),
@@ -104,7 +96,7 @@ public static TheoryData<IssuerExtensibilityTheoryData> Issuer_ExtensibilityTest
10496
new MessageDetail(
10597
nameof(CustomIssuerValidationDelegates.CustomIssuerValidatorCustomExceptionDelegateAsync), null),
10698
typeof(CustomSecurityTokenInvalidIssuerException),
107-
new StackFrame("CustomIssuerValidationDelegates", 107),
99+
new StackFrame("CustomIssuerValidationDelegates.cs", 107),
108100
issuerGuid),
109101
});
110102

@@ -113,20 +105,19 @@ public static TheoryData<IssuerExtensibilityTheoryData> Issuer_ExtensibilityTest
113105
"CustomIssuerValidatorUnknownExceptionDelegate",
114106
issuerGuid,
115107
CustomIssuerValidationDelegates.CustomIssuerValidatorUnknownExceptionDelegateAsync,
116-
[
117-
new StackFrame("CustomIssuerValidationDelegates", 139),
118-
new StackFrame(false),
119-
new StackFrame(false)
120-
])
108+
extraStackFrames: 2)
121109
{
122-
ExpectedException = new ExpectedException(
123-
typeof(SecurityTokenException),
124-
nameof(CustomIssuerValidationDelegates.CustomIssuerValidatorUnknownExceptionDelegateAsync)),
110+
// CustomIssuerValidationError does not handle the exception type 'NotSupportedException'
111+
ExpectedException = ExpectedException.SecurityTokenException(
112+
LogHelper.FormatInvariant(
113+
Tokens.LogMessages.IDX10002, // "IDX10002: Unknown exception type returned. Type: '{0}'. Message: '{1}'.";
114+
typeof(NotSupportedException),
115+
nameof(CustomIssuerValidationDelegates.CustomIssuerValidatorUnknownExceptionDelegateAsync))),
125116
IssuerValidationError = new CustomIssuerValidationError(
126117
new MessageDetail(
127118
nameof(CustomIssuerValidationDelegates.CustomIssuerValidatorUnknownExceptionDelegateAsync), null),
128119
typeof(NotSupportedException),
129-
new StackFrame("CustomIssuerValidationDelegates", 139),
120+
new StackFrame("CustomIssuerValidationDelegates.cs", 139),
130121
issuerGuid),
131122
});
132123

@@ -135,11 +126,7 @@ public static TheoryData<IssuerExtensibilityTheoryData> Issuer_ExtensibilityTest
135126
"CustomIssuerValidatorCustomExceptionCustomFailureTypeDelegate",
136127
issuerGuid,
137128
CustomIssuerValidationDelegates.CustomIssuerValidatorCustomExceptionCustomFailureTypeDelegateAsync,
138-
[
139-
new StackFrame("CustomIssuerValidationDelegates", 123),
140-
new StackFrame(false),
141-
new StackFrame(false)
142-
])
129+
extraStackFrames: 2)
143130
{
144131
ExpectedException = new ExpectedException(
145132
typeof(CustomSecurityTokenInvalidIssuerException),
@@ -148,7 +135,7 @@ public static TheoryData<IssuerExtensibilityTheoryData> Issuer_ExtensibilityTest
148135
new MessageDetail(
149136
nameof(CustomIssuerValidationDelegates.CustomIssuerValidatorCustomExceptionCustomFailureTypeDelegateAsync), null),
150137
typeof(CustomSecurityTokenInvalidIssuerException),
151-
new StackFrame("CustomIssuerValidationDelegates", 123),
138+
new StackFrame("CustomIssuerValidationDelegates.cs", 123),
152139
issuerGuid,
153140
CustomIssuerValidationError.CustomIssuerValidationFailureType,
154141
null),
@@ -162,11 +149,7 @@ public static TheoryData<IssuerExtensibilityTheoryData> Issuer_ExtensibilityTest
162149
"IssuerValidatorDelegate",
163150
issuerGuid,
164151
CustomIssuerValidationDelegates.IssuerValidatorDelegateAsync,
165-
[
166-
new StackFrame("CustomIssuerValidationDelegates", 169),
167-
new StackFrame(false),
168-
new StackFrame(false)
169-
])
152+
extraStackFrames: 2)
170153
{
171154
ExpectedException = new ExpectedException(
172155
typeof(SecurityTokenInvalidIssuerException),
@@ -175,7 +158,7 @@ public static TheoryData<IssuerExtensibilityTheoryData> Issuer_ExtensibilityTest
175158
new MessageDetail(
176159
nameof(CustomIssuerValidationDelegates.IssuerValidatorDelegateAsync), null),
177160
typeof(SecurityTokenInvalidIssuerException),
178-
new StackFrame("CustomIssuerValidationDelegates", 169),
161+
new StackFrame("CustomIssuerValidationDelegates.cs", 169),
179162
issuerGuid)
180163
});
181164

@@ -184,20 +167,19 @@ public static TheoryData<IssuerExtensibilityTheoryData> Issuer_ExtensibilityTest
184167
"IssuerValidatorCustomIssuerExceptionTypeDelegate",
185168
issuerGuid,
186169
CustomIssuerValidationDelegates.IssuerValidatorCustomIssuerExceptionTypeDelegateAsync,
187-
[
188-
new StackFrame("CustomIssuerValidationDelegates", 196),
189-
new StackFrame(false),
190-
new StackFrame(false)
191-
])
170+
extraStackFrames: 2)
192171
{
193-
ExpectedException = new ExpectedException(
194-
typeof(SecurityTokenException),
195-
nameof(CustomIssuerValidationDelegates.IssuerValidatorCustomIssuerExceptionTypeDelegateAsync)),
172+
// IssuerValidationError does not handle the exception type 'CustomSecurityTokenInvalidIssuerException'
173+
ExpectedException = ExpectedException.SecurityTokenException(
174+
LogHelper.FormatInvariant(
175+
Tokens.LogMessages.IDX10002, // "IDX10002: Unknown exception type returned. Type: '{0}'. Message: '{1}'.";
176+
typeof(CustomSecurityTokenInvalidIssuerException),
177+
nameof(CustomIssuerValidationDelegates.IssuerValidatorCustomIssuerExceptionTypeDelegateAsync))),
196178
IssuerValidationError = new IssuerValidationError(
197179
new MessageDetail(
198180
nameof(CustomIssuerValidationDelegates.IssuerValidatorCustomIssuerExceptionTypeDelegateAsync), null),
199181
typeof(CustomSecurityTokenInvalidIssuerException),
200-
new StackFrame("CustomIssuerValidationDelegates", 196),
182+
new StackFrame("CustomIssuerValidationDelegates.cs", 196),
201183
issuerGuid)
202184
});
203185

@@ -206,20 +188,19 @@ public static TheoryData<IssuerExtensibilityTheoryData> Issuer_ExtensibilityTest
206188
"IssuerValidatorCustomExceptionTypeDelegate",
207189
issuerGuid,
208190
CustomIssuerValidationDelegates.IssuerValidatorCustomExceptionTypeDelegateAsync,
209-
[
210-
new StackFrame("CustomIssuerValidationDelegates", 210),
211-
new StackFrame(false),
212-
new StackFrame(false)
213-
])
191+
extraStackFrames: 2)
214192
{
215-
ExpectedException = new ExpectedException(
216-
typeof(SecurityTokenException),
217-
nameof(CustomIssuerValidationDelegates.IssuerValidatorCustomExceptionTypeDelegateAsync)),
193+
// IssuerValidationError does not handle the exception type 'CustomSecurityTokenException'
194+
ExpectedException = ExpectedException.SecurityTokenException(
195+
LogHelper.FormatInvariant(
196+
Tokens.LogMessages.IDX10002, // "IDX10002: Unknown exception type returned. Type: '{0}'. Message: '{1}'.";
197+
typeof(CustomSecurityTokenException),
198+
nameof(CustomIssuerValidationDelegates.IssuerValidatorCustomExceptionTypeDelegateAsync))),
218199
IssuerValidationError = new IssuerValidationError(
219200
new MessageDetail(
220201
nameof(CustomIssuerValidationDelegates.IssuerValidatorCustomExceptionTypeDelegateAsync), null),
221202
typeof(CustomSecurityTokenException),
222-
new StackFrame("CustomIssuerValidationDelegates", 210),
203+
new StackFrame("CustomIssuerValidationDelegates.cs", 210),
223204
issuerGuid)
224205
});
225206

@@ -228,10 +209,7 @@ public static TheoryData<IssuerExtensibilityTheoryData> Issuer_ExtensibilityTest
228209
"IssuerValidatorThrows",
229210
issuerGuid,
230211
CustomIssuerValidationDelegates.IssuerValidatorThrows,
231-
[
232-
new StackFrame("JsonWebTokenHandler.ValidateToken.Internal.cs", 300),
233-
new StackFrame(false)
234-
])
212+
extraStackFrames: 1)
235213
{
236214
ExpectedException = new ExpectedException(
237215
typeof(SecurityTokenInvalidIssuerException),
@@ -255,7 +233,7 @@ public static TheoryData<IssuerExtensibilityTheoryData> Issuer_ExtensibilityTest
255233

256234
public class IssuerExtensibilityTheoryData : ValidateTokenAsyncBaseTheoryData
257235
{
258-
internal IssuerExtensibilityTheoryData(string testId, string issuer, IssuerValidationDelegateAsync issuerValidator, IList<StackFrame> stackFrames) : base(testId)
236+
internal IssuerExtensibilityTheoryData(string testId, string issuer, IssuerValidationDelegateAsync issuerValidator, int extraStackFrames) : base(testId)
259237
{
260238
JsonWebToken = JsonUtilities.CreateUnsignedJsonWebToken("iss", issuer);
261239
ValidationParameters = new ValidationParameters
@@ -270,7 +248,7 @@ internal IssuerExtensibilityTheoryData(string testId, string issuer, IssuerValid
270248
TokenTypeValidator = SkipValidationDelegates.SkipTokenTypeValidation
271249
};
272250

273-
StackFrames = stackFrames;
251+
ExtraStackFrames = extraStackFrames;
274252
}
275253

276254
public JsonWebToken JsonWebToken { get; }
@@ -283,7 +261,7 @@ internal IssuerExtensibilityTheoryData(string testId, string issuer, IssuerValid
283261

284262
internal IssuerValidationError? IssuerValidationError { get; set; }
285263

286-
internal IList<StackFrame> StackFrames { get; }
264+
internal int ExtraStackFrames { get; }
287265
}
288266
}
289267
}

0 commit comments

Comments
 (0)