2
2
// Licensed under the MIT License.
3
3
4
4
using System ;
5
- using System . Collections . Generic ;
6
5
using System . Diagnostics ;
7
6
using System . Threading ;
8
7
using System . Threading . Tasks ;
9
8
using Microsoft . IdentityModel . JsonWebTokens . Tests ;
9
+ using Microsoft . IdentityModel . Logging ;
10
10
using Microsoft . IdentityModel . TestUtils ;
11
11
using Microsoft . IdentityModel . Tokens ;
12
12
using Microsoft . IdentityModel . Tokens . Json . Tests ;
@@ -22,8 +22,8 @@ public async Task ValidateTokenAsync_IssuerValidator_Extensibility(IssuerExtensi
22
22
{
23
23
var context = TestUtilities . WriteHeader ( $ "{ this } .{ nameof ( ValidateTokenAsync_IssuerValidator_Extensibility ) } ", theoryData ) ;
24
24
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 ) ) ;
27
27
28
28
try
29
29
{
@@ -69,11 +69,7 @@ public static TheoryData<IssuerExtensibilityTheoryData> Issuer_ExtensibilityTest
69
69
"CustomIssuerValidatorDelegate" ,
70
70
issuerGuid ,
71
71
CustomIssuerValidationDelegates . CustomIssuerValidatorDelegateAsync ,
72
- [
73
- new StackFrame ( "CustomIssuerValidationDelegates" , 88 ) ,
74
- new StackFrame ( false ) ,
75
- new StackFrame ( false )
76
- ] )
72
+ extraStackFrames : 2 )
77
73
{
78
74
ExpectedException = new ExpectedException (
79
75
typeof ( SecurityTokenInvalidIssuerException ) ,
@@ -82,7 +78,7 @@ public static TheoryData<IssuerExtensibilityTheoryData> Issuer_ExtensibilityTest
82
78
new MessageDetail (
83
79
nameof ( CustomIssuerValidationDelegates . CustomIssuerValidatorDelegateAsync ) , null ) ,
84
80
typeof ( SecurityTokenInvalidIssuerException ) ,
85
- new StackFrame ( "CustomIssuerValidationDelegates" , 88 ) ,
81
+ new StackFrame ( "CustomIssuerValidationDelegates.cs " , 88 ) ,
86
82
issuerGuid )
87
83
} ) ;
88
84
@@ -91,11 +87,7 @@ public static TheoryData<IssuerExtensibilityTheoryData> Issuer_ExtensibilityTest
91
87
"CustomIssuerValidatorCustomExceptionDelegate" ,
92
88
issuerGuid ,
93
89
CustomIssuerValidationDelegates . CustomIssuerValidatorCustomExceptionDelegateAsync ,
94
- [
95
- new StackFrame ( "CustomIssuerValidationDelegates" , 107 ) ,
96
- new StackFrame ( false ) ,
97
- new StackFrame ( false )
98
- ] )
90
+ extraStackFrames : 2 )
99
91
{
100
92
ExpectedException = new ExpectedException (
101
93
typeof ( CustomSecurityTokenInvalidIssuerException ) ,
@@ -104,7 +96,7 @@ public static TheoryData<IssuerExtensibilityTheoryData> Issuer_ExtensibilityTest
104
96
new MessageDetail (
105
97
nameof ( CustomIssuerValidationDelegates . CustomIssuerValidatorCustomExceptionDelegateAsync ) , null ) ,
106
98
typeof ( CustomSecurityTokenInvalidIssuerException ) ,
107
- new StackFrame ( "CustomIssuerValidationDelegates" , 107 ) ,
99
+ new StackFrame ( "CustomIssuerValidationDelegates.cs " , 107 ) ,
108
100
issuerGuid ) ,
109
101
} ) ;
110
102
@@ -113,20 +105,19 @@ public static TheoryData<IssuerExtensibilityTheoryData> Issuer_ExtensibilityTest
113
105
"CustomIssuerValidatorUnknownExceptionDelegate" ,
114
106
issuerGuid ,
115
107
CustomIssuerValidationDelegates . CustomIssuerValidatorUnknownExceptionDelegateAsync ,
116
- [
117
- new StackFrame ( "CustomIssuerValidationDelegates" , 139 ) ,
118
- new StackFrame ( false ) ,
119
- new StackFrame ( false )
120
- ] )
108
+ extraStackFrames : 2 )
121
109
{
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 ) ) ) ,
125
116
IssuerValidationError = new CustomIssuerValidationError (
126
117
new MessageDetail (
127
118
nameof ( CustomIssuerValidationDelegates . CustomIssuerValidatorUnknownExceptionDelegateAsync ) , null ) ,
128
119
typeof ( NotSupportedException ) ,
129
- new StackFrame ( "CustomIssuerValidationDelegates" , 139 ) ,
120
+ new StackFrame ( "CustomIssuerValidationDelegates.cs " , 139 ) ,
130
121
issuerGuid ) ,
131
122
} ) ;
132
123
@@ -135,11 +126,7 @@ public static TheoryData<IssuerExtensibilityTheoryData> Issuer_ExtensibilityTest
135
126
"CustomIssuerValidatorCustomExceptionCustomFailureTypeDelegate" ,
136
127
issuerGuid ,
137
128
CustomIssuerValidationDelegates . CustomIssuerValidatorCustomExceptionCustomFailureTypeDelegateAsync ,
138
- [
139
- new StackFrame ( "CustomIssuerValidationDelegates" , 123 ) ,
140
- new StackFrame ( false ) ,
141
- new StackFrame ( false )
142
- ] )
129
+ extraStackFrames : 2 )
143
130
{
144
131
ExpectedException = new ExpectedException (
145
132
typeof ( CustomSecurityTokenInvalidIssuerException ) ,
@@ -148,7 +135,7 @@ public static TheoryData<IssuerExtensibilityTheoryData> Issuer_ExtensibilityTest
148
135
new MessageDetail (
149
136
nameof ( CustomIssuerValidationDelegates . CustomIssuerValidatorCustomExceptionCustomFailureTypeDelegateAsync ) , null ) ,
150
137
typeof ( CustomSecurityTokenInvalidIssuerException ) ,
151
- new StackFrame ( "CustomIssuerValidationDelegates" , 123 ) ,
138
+ new StackFrame ( "CustomIssuerValidationDelegates.cs " , 123 ) ,
152
139
issuerGuid ,
153
140
CustomIssuerValidationError . CustomIssuerValidationFailureType ,
154
141
null ) ,
@@ -162,11 +149,7 @@ public static TheoryData<IssuerExtensibilityTheoryData> Issuer_ExtensibilityTest
162
149
"IssuerValidatorDelegate" ,
163
150
issuerGuid ,
164
151
CustomIssuerValidationDelegates . IssuerValidatorDelegateAsync ,
165
- [
166
- new StackFrame ( "CustomIssuerValidationDelegates" , 169 ) ,
167
- new StackFrame ( false ) ,
168
- new StackFrame ( false )
169
- ] )
152
+ extraStackFrames : 2 )
170
153
{
171
154
ExpectedException = new ExpectedException (
172
155
typeof ( SecurityTokenInvalidIssuerException ) ,
@@ -175,7 +158,7 @@ public static TheoryData<IssuerExtensibilityTheoryData> Issuer_ExtensibilityTest
175
158
new MessageDetail (
176
159
nameof ( CustomIssuerValidationDelegates . IssuerValidatorDelegateAsync ) , null ) ,
177
160
typeof ( SecurityTokenInvalidIssuerException ) ,
178
- new StackFrame ( "CustomIssuerValidationDelegates" , 169 ) ,
161
+ new StackFrame ( "CustomIssuerValidationDelegates.cs " , 169 ) ,
179
162
issuerGuid )
180
163
} ) ;
181
164
@@ -184,20 +167,19 @@ public static TheoryData<IssuerExtensibilityTheoryData> Issuer_ExtensibilityTest
184
167
"IssuerValidatorCustomIssuerExceptionTypeDelegate" ,
185
168
issuerGuid ,
186
169
CustomIssuerValidationDelegates . IssuerValidatorCustomIssuerExceptionTypeDelegateAsync ,
187
- [
188
- new StackFrame ( "CustomIssuerValidationDelegates" , 196 ) ,
189
- new StackFrame ( false ) ,
190
- new StackFrame ( false )
191
- ] )
170
+ extraStackFrames : 2 )
192
171
{
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 ) ) ) ,
196
178
IssuerValidationError = new IssuerValidationError (
197
179
new MessageDetail (
198
180
nameof ( CustomIssuerValidationDelegates . IssuerValidatorCustomIssuerExceptionTypeDelegateAsync ) , null ) ,
199
181
typeof ( CustomSecurityTokenInvalidIssuerException ) ,
200
- new StackFrame ( "CustomIssuerValidationDelegates" , 196 ) ,
182
+ new StackFrame ( "CustomIssuerValidationDelegates.cs " , 196 ) ,
201
183
issuerGuid )
202
184
} ) ;
203
185
@@ -206,20 +188,19 @@ public static TheoryData<IssuerExtensibilityTheoryData> Issuer_ExtensibilityTest
206
188
"IssuerValidatorCustomExceptionTypeDelegate" ,
207
189
issuerGuid ,
208
190
CustomIssuerValidationDelegates . IssuerValidatorCustomExceptionTypeDelegateAsync ,
209
- [
210
- new StackFrame ( "CustomIssuerValidationDelegates" , 210 ) ,
211
- new StackFrame ( false ) ,
212
- new StackFrame ( false )
213
- ] )
191
+ extraStackFrames : 2 )
214
192
{
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 ) ) ) ,
218
199
IssuerValidationError = new IssuerValidationError (
219
200
new MessageDetail (
220
201
nameof ( CustomIssuerValidationDelegates . IssuerValidatorCustomExceptionTypeDelegateAsync ) , null ) ,
221
202
typeof ( CustomSecurityTokenException ) ,
222
- new StackFrame ( "CustomIssuerValidationDelegates" , 210 ) ,
203
+ new StackFrame ( "CustomIssuerValidationDelegates.cs " , 210 ) ,
223
204
issuerGuid )
224
205
} ) ;
225
206
@@ -228,10 +209,7 @@ public static TheoryData<IssuerExtensibilityTheoryData> Issuer_ExtensibilityTest
228
209
"IssuerValidatorThrows" ,
229
210
issuerGuid ,
230
211
CustomIssuerValidationDelegates . IssuerValidatorThrows ,
231
- [
232
- new StackFrame ( "JsonWebTokenHandler.ValidateToken.Internal.cs" , 300 ) ,
233
- new StackFrame ( false )
234
- ] )
212
+ extraStackFrames : 1 )
235
213
{
236
214
ExpectedException = new ExpectedException (
237
215
typeof ( SecurityTokenInvalidIssuerException ) ,
@@ -255,7 +233,7 @@ public static TheoryData<IssuerExtensibilityTheoryData> Issuer_ExtensibilityTest
255
233
256
234
public class IssuerExtensibilityTheoryData : ValidateTokenAsyncBaseTheoryData
257
235
{
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 )
259
237
{
260
238
JsonWebToken = JsonUtilities . CreateUnsignedJsonWebToken ( "iss" , issuer ) ;
261
239
ValidationParameters = new ValidationParameters
@@ -270,7 +248,7 @@ internal IssuerExtensibilityTheoryData(string testId, string issuer, IssuerValid
270
248
TokenTypeValidator = SkipValidationDelegates . SkipTokenTypeValidation
271
249
} ;
272
250
273
- StackFrames = stackFrames ;
251
+ ExtraStackFrames = extraStackFrames ;
274
252
}
275
253
276
254
public JsonWebToken JsonWebToken { get ; }
@@ -283,7 +261,7 @@ internal IssuerExtensibilityTheoryData(string testId, string issuer, IssuerValid
283
261
284
262
internal IssuerValidationError ? IssuerValidationError { get ; set ; }
285
263
286
- internal IList < StackFrame > StackFrames { get ; }
264
+ internal int ExtraStackFrames { get ; }
287
265
}
288
266
}
289
267
}
0 commit comments