@@ -20,7 +20,8 @@ public async Task RemoteAuthenticationService_SignIn_UpdatesUserOnSuccess()
20
20
var options = CreateOptions ( ) ;
21
21
var runtime = new RemoteAuthenticationService < RemoteAuthenticationState , OidcProviderOptions > (
22
22
testJsRuntime ,
23
- options ) ;
23
+ options ,
24
+ new TestNavigationManager ( ) ) ;
24
25
25
26
var state = new RemoteAuthenticationState ( ) ;
26
27
testJsRuntime . SignInResult = new RemoteAuthenticationResult < RemoteAuthenticationState >
@@ -49,7 +50,8 @@ public async Task RemoteAuthenticationService_SignIn_DoesNotUpdateUserOnOtherRes
49
50
var options = CreateOptions ( ) ;
50
51
var runtime = new RemoteAuthenticationService < RemoteAuthenticationState , OidcProviderOptions > (
51
52
testJsRuntime ,
52
- options ) ;
53
+ options ,
54
+ new TestNavigationManager ( ) ) ;
53
55
54
56
var state = new RemoteAuthenticationState ( ) ;
55
57
testJsRuntime . SignInResult = new RemoteAuthenticationResult < RemoteAuthenticationState >
@@ -74,7 +76,8 @@ public async Task RemoteAuthenticationService_CompleteSignInAsync_UpdatesUserOnS
74
76
var options = CreateOptions ( ) ;
75
77
var runtime = new RemoteAuthenticationService < RemoteAuthenticationState , OidcProviderOptions > (
76
78
testJsRuntime ,
77
- options ) ;
79
+ options ,
80
+ new TestNavigationManager ( ) ) ;
78
81
79
82
var state = new RemoteAuthenticationState ( ) ;
80
83
testJsRuntime . CompleteSignInResult = new RemoteAuthenticationResult < RemoteAuthenticationState >
@@ -103,7 +106,8 @@ public async Task RemoteAuthenticationService_CompleteSignInAsync_DoesNotUpdateU
103
106
var options = CreateOptions ( ) ;
104
107
var runtime = new RemoteAuthenticationService < RemoteAuthenticationState , OidcProviderOptions > (
105
108
testJsRuntime ,
106
- options ) ;
109
+ options ,
110
+ new TestNavigationManager ( ) ) ;
107
111
108
112
var state = new RemoteAuthenticationState ( ) ;
109
113
testJsRuntime . CompleteSignInResult = new RemoteAuthenticationResult < RemoteAuthenticationState >
@@ -128,7 +132,8 @@ public async Task RemoteAuthenticationService_SignOut_UpdatesUserOnSuccess()
128
132
var options = CreateOptions ( ) ;
129
133
var runtime = new RemoteAuthenticationService < RemoteAuthenticationState , OidcProviderOptions > (
130
134
testJsRuntime ,
131
- options ) ;
135
+ options ,
136
+ new TestNavigationManager ( ) ) ;
132
137
133
138
var state = new RemoteAuthenticationState ( ) ;
134
139
testJsRuntime . SignOutResult = new RemoteAuthenticationResult < RemoteAuthenticationState >
@@ -157,7 +162,8 @@ public async Task RemoteAuthenticationService_SignOut_DoesNotUpdateUserOnOtherRe
157
162
var options = CreateOptions ( ) ;
158
163
var runtime = new RemoteAuthenticationService < RemoteAuthenticationState , OidcProviderOptions > (
159
164
testJsRuntime ,
160
- options ) ;
165
+ options ,
166
+ new TestNavigationManager ( ) ) ;
161
167
162
168
var state = new RemoteAuthenticationState ( ) ;
163
169
testJsRuntime . SignOutResult = new RemoteAuthenticationResult < RemoteAuthenticationState >
@@ -182,7 +188,8 @@ public async Task RemoteAuthenticationService_CompleteSignOutAsync_UpdatesUserOn
182
188
var options = CreateOptions ( ) ;
183
189
var runtime = new RemoteAuthenticationService < RemoteAuthenticationState , OidcProviderOptions > (
184
190
testJsRuntime ,
185
- options ) ;
191
+ options ,
192
+ new TestNavigationManager ( ) ) ;
186
193
187
194
var state = new RemoteAuthenticationState ( ) ;
188
195
testJsRuntime . CompleteSignOutResult = new RemoteAuthenticationResult < RemoteAuthenticationState >
@@ -211,7 +218,8 @@ public async Task RemoteAuthenticationService_CompleteSignOutAsync_DoesNotUpdate
211
218
var options = CreateOptions ( ) ;
212
219
var runtime = new RemoteAuthenticationService < RemoteAuthenticationState , OidcProviderOptions > (
213
220
testJsRuntime ,
214
- options ) ;
221
+ options ,
222
+ new TestNavigationManager ( ) ) ;
215
223
216
224
var state = new RemoteAuthenticationState ( ) ;
217
225
testJsRuntime . CompleteSignOutResult = new RemoteAuthenticationResult < RemoteAuthenticationState >
@@ -236,7 +244,8 @@ public async Task RemoteAuthenticationService_GetAccessToken_ReturnsAccessTokenR
236
244
var options = CreateOptions ( ) ;
237
245
var runtime = new RemoteAuthenticationService < RemoteAuthenticationState , OidcProviderOptions > (
238
246
testJsRuntime ,
239
- options ) ;
247
+ options ,
248
+ new TestNavigationManager ( ) ) ;
240
249
241
250
var state = new RemoteAuthenticationState ( ) ;
242
251
testJsRuntime . GetAccessTokenResult = new AccessTokenResult
@@ -269,20 +278,60 @@ public async Task RemoteAuthenticationService_GetAccessToken_PassesDownOptions()
269
278
var options = CreateOptions ( ) ;
270
279
var runtime = new RemoteAuthenticationService < RemoteAuthenticationState , OidcProviderOptions > (
271
280
testJsRuntime ,
272
- options ) ;
281
+ options ,
282
+ new TestNavigationManager ( ) ) ;
273
283
274
284
var state = new RemoteAuthenticationState ( ) ;
275
285
testJsRuntime . GetAccessTokenResult = new AccessTokenResult
276
286
{
277
287
Status = AccessTokenResultStatus . RequiresRedirect ,
278
- RedirectUrl = "https://www.example.com/base/auth/login"
279
288
} ;
280
289
281
290
var tokenOptions = new AccessTokenRequestOptions
282
291
{
283
292
Scopes = new [ ] { "something" }
284
293
} ;
285
294
295
+ var expectedRedirectUrl = "https://www.example.com/base/login?returnUrl=https%3A%2F%2Fwww.example.com%2Fbase%2Fadd-product" ;
296
+
297
+ // Act
298
+ var result = await runtime . GetAccessToken ( tokenOptions ) ;
299
+
300
+ // Assert
301
+ Assert . Equal (
302
+ new [ ] { "AuthenticationService.init" , "AuthenticationService.getAccessToken" } ,
303
+ testJsRuntime . PastInvocations . Select ( i => i . identifier ) . ToArray ( ) ) ;
304
+
305
+ Assert . Equal ( result , testJsRuntime . GetAccessTokenResult ) ;
306
+ Assert . Equal ( expectedRedirectUrl , result . RedirectUrl ) ;
307
+ Assert . Equal ( tokenOptions , ( AccessTokenRequestOptions ) testJsRuntime . PastInvocations [ ^ 1 ] . args [ 0 ] ) ;
308
+ }
309
+
310
+ [ Fact ]
311
+ public async Task RemoteAuthenticationService_GetAccessToken_ComputesDefaultReturnUrlOnRequiresRedirect ( )
312
+ {
313
+ // Arrange
314
+ var testJsRuntime = new TestJsRuntime ( ) ;
315
+ var options = CreateOptions ( ) ;
316
+ var runtime = new RemoteAuthenticationService < RemoteAuthenticationState , OidcProviderOptions > (
317
+ testJsRuntime ,
318
+ options ,
319
+ new TestNavigationManager ( ) ) ;
320
+
321
+ var state = new RemoteAuthenticationState ( ) ;
322
+ testJsRuntime . GetAccessTokenResult = new AccessTokenResult
323
+ {
324
+ Status = AccessTokenResultStatus . RequiresRedirect ,
325
+ } ;
326
+
327
+ var tokenOptions = new AccessTokenRequestOptions
328
+ {
329
+ Scopes = new [ ] { "something" } ,
330
+ ReturnUrl = "https://www.example.com/base/add-saved-product/123413241234"
331
+ } ;
332
+
333
+ var expectedRedirectUrl = "https://www.example.com/base/login?returnUrl=https%3A%2F%2Fwww.example.com%2Fbase%2Fadd-saved-product%2F123413241234" ;
334
+
286
335
// Act
287
336
var result = await runtime . GetAccessToken ( tokenOptions ) ;
288
337
@@ -292,6 +341,7 @@ public async Task RemoteAuthenticationService_GetAccessToken_PassesDownOptions()
292
341
testJsRuntime . PastInvocations . Select ( i => i . identifier ) . ToArray ( ) ) ;
293
342
294
343
Assert . Equal ( result , testJsRuntime . GetAccessTokenResult ) ;
344
+ Assert . Equal ( expectedRedirectUrl , result . RedirectUrl ) ;
295
345
Assert . Equal ( tokenOptions , ( AccessTokenRequestOptions ) testJsRuntime . PastInvocations [ ^ 1 ] . args [ 0 ] ) ;
296
346
}
297
347
@@ -303,7 +353,8 @@ public async Task RemoteAuthenticationService_GetUser_ReturnsAnonymousClaimsPrin
303
353
var options = CreateOptions ( ) ;
304
354
var runtime = new RemoteAuthenticationService < RemoteAuthenticationState , OidcProviderOptions > (
305
355
testJsRuntime ,
306
- options ) ;
356
+ options ,
357
+ new TestNavigationManager ( ) ) ;
307
358
308
359
testJsRuntime . GetUserResult = null ;
309
360
@@ -328,7 +379,8 @@ public async Task RemoteAuthenticationService_GetUser_ReturnsUser_ForAuthenticat
328
379
var options = CreateOptions ( ) ;
329
380
var runtime = new RemoteAuthenticationService < RemoteAuthenticationState , OidcProviderOptions > (
330
381
testJsRuntime ,
331
- options ) ;
382
+ options ,
383
+ new TestNavigationManager ( ) ) ;
332
384
333
385
var serializationOptions = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy . CamelCase , PropertyNameCaseInsensitive = true } ;
334
386
var serializedUser = JsonSerializer . Serialize ( new
@@ -360,7 +412,8 @@ public async Task RemoteAuthenticationService_GetUser_DoesNotMapScopesToRoles()
360
412
var options = CreateOptions ( "scope" ) ;
361
413
var runtime = new RemoteAuthenticationService < RemoteAuthenticationState , OidcProviderOptions > (
362
414
testJsRuntime ,
363
- options ) ;
415
+ options ,
416
+ new TestNavigationManager ( ) ) ;
364
417
365
418
var serializationOptions = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy . CamelCase , PropertyNameCaseInsensitive = true } ;
366
419
var serializedUser = JsonSerializer . Serialize ( new
@@ -402,7 +455,7 @@ private static IOptions<RemoteAuthenticationOptions<OidcProviderOptions>> Create
402
455
{
403
456
AuthenticationPaths = new RemoteAuthenticationApplicationPathsOptions
404
457
{
405
- LogInPath = "a " ,
458
+ LogInPath = "login " ,
406
459
LogInCallbackPath = "a" ,
407
460
LogInFailedPath = "a" ,
408
461
RegisterPath = "a" ,
@@ -489,4 +542,12 @@ private object GetInvocationResult<TValue>(string identifier)
489
542
}
490
543
}
491
544
}
545
+
546
+ internal class TestNavigationManager : NavigationManager
547
+ {
548
+ public TestNavigationManager ( ) =>
549
+ Initialize ( "https://www.example.com/base/" , "https://www.example.com/base/add-product" ) ;
550
+
551
+ protected override void NavigateToCore ( string uri , bool forceLoad ) => throw new NotImplementedException ( ) ;
552
+ }
492
553
}
0 commit comments