LEFT | RIGHT |
1 /* | 1 /* |
2 Copyright 2013 Google Inc | 2 Copyright 2013 Google Inc |
3 | 3 |
4 Licensed under the Apache License, Version 2.0 (the "License"); | 4 Licensed under the Apache License, Version 2.0 (the "License"); |
5 you may not use this file except in compliance with the License. | 5 you may not use this file except in compliance with the License. |
6 You may obtain a copy of the License at | 6 You may obtain a copy of the License at |
7 | 7 |
8 http://www.apache.org/licenses/LICENSE-2.0 | 8 http://www.apache.org/licenses/LICENSE-2.0 |
9 | 9 |
10 Unless required by applicable law or agreed to in writing, software | 10 Unless required by applicable law or agreed to in writing, software |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 Assert.NotNull(flow.AccessMethod); | 68 Assert.NotNull(flow.AccessMethod); |
69 Assert.That(flow.AccessMethod, Is.InstanceOf<BearerToken.Authorizati
onHeaderAccessMethod>()); | 69 Assert.That(flow.AccessMethod, Is.InstanceOf<BearerToken.Authorizati
onHeaderAccessMethod>()); |
70 Assert.That(flow.AuthorizationServerUrl, Is.EqualTo("https://authori
zation.com")); | 70 Assert.That(flow.AuthorizationServerUrl, Is.EqualTo("https://authori
zation.com")); |
71 Assert.NotNull(flow.ClientSecrets); | 71 Assert.NotNull(flow.ClientSecrets); |
72 Assert.That(flow.ClientSecrets.ClientId, Is.EqualTo("id")); | 72 Assert.That(flow.ClientSecrets.ClientId, Is.EqualTo("id")); |
73 Assert.That(flow.ClientSecrets.ClientSecret, Is.EqualTo("secret")); | 73 Assert.That(flow.ClientSecrets.ClientSecret, Is.EqualTo("secret")); |
74 Assert.That(flow.Clock, Is.InstanceOf<SystemClock>()); | 74 Assert.That(flow.Clock, Is.InstanceOf<SystemClock>()); |
75 Assert.Null(flow.DataStore); | 75 Assert.Null(flow.DataStore); |
76 Assert.NotNull(flow.HttpClient); | 76 Assert.NotNull(flow.HttpClient); |
77 Assert.NotNull(flow.Scopes); | 77 Assert.NotNull(flow.Scopes); |
78 Assert.That(flow.TokenServerEncodedUrl, Is.EqualTo("https://token.co
m")); | 78 Assert.That(flow.TokenServerUrl, Is.EqualTo("https://token.com")); |
79 | 79 |
80 Assert.That(flow.HttpClient.MessageHandler.UnsuccessfulResponseHandl
ers.Count(), Is.EqualTo(1)); | 80 Assert.That(flow.HttpClient.MessageHandler.UnsuccessfulResponseHandl
ers.Count(), Is.EqualTo(1)); |
81 Assert.That(flow.HttpClient.MessageHandler.UnsuccessfulResponseHandl
ers.First(), | 81 Assert.That(flow.HttpClient.MessageHandler.UnsuccessfulResponseHandl
ers.First(), |
82 Is.InstanceOf<BackOffHandler>()); | 82 Is.InstanceOf<BackOffHandler>()); |
83 } | 83 } |
84 | 84 |
85 #endregion | 85 #endregion |
86 | 86 |
87 #region LoadToken | 87 #region LoadToken |
88 | 88 |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 handler.RefreshTokenRequest = new RefreshTokenRequest() | 355 handler.RefreshTokenRequest = new RefreshTokenRequest() |
356 { | 356 { |
357 RefreshToken = "REFRESH", | 357 RefreshToken = "REFRESH", |
358 Scope = "a" | 358 Scope = "a" |
359 }; | 359 }; |
360 handler.Error = true; | 360 handler.Error = true; |
361 SubtestFetchTokenAsync_Error(handler); | 361 SubtestFetchTokenAsync_Error(handler); |
362 } | 362 } |
363 | 363 |
364 /// <summary>Subtest for receiving an error token response.</summary> | 364 /// <summary>Subtest for receiving an error token response.</summary> |
365 /// <param name="handler">The message handler</param> | 365 /// <param name="handler">The message handler.</param> |
366 private void SubtestFetchTokenAsync_Error(FetchTokenMessageHandler handl
er) | 366 private void SubtestFetchTokenAsync_Error(FetchTokenMessageHandler handl
er) |
367 { | 367 { |
368 MockHttpClientFactory mockFactory = new MockHttpClientFactory(handle
r); | 368 MockHttpClientFactory mockFactory = new MockHttpClientFactory(handle
r); |
369 var flow = CreateFlow(httpClientFactory: mockFactory); | 369 var flow = CreateFlow(httpClientFactory: mockFactory); |
370 try | 370 try |
371 { | 371 { |
372 var request = | 372 var request = |
373 (TokenRequest)handler.AuthorizationCodeTokenRequest ?? (Toke
nRequest)handler.RefreshTokenRequest; | 373 (TokenRequest)handler.AuthorizationCodeTokenRequest ?? (Toke
nRequest)handler.RefreshTokenRequest; |
374 var result = flow.FetchTokenAsync("user", request, CancellationT
oken.None).Result; | 374 var result = flow.FetchTokenAsync("user", request, CancellationT
oken.None).Result; |
375 Assert.Fail(); | 375 Assert.Fail(); |
376 } | 376 } |
377 catch (AggregateException aex) | 377 catch (AggregateException aex) |
378 { | 378 { |
379 var ex = aex.InnerException as TokenResponseException; | 379 var ex = aex.InnerException as TokenResponseException; |
380 Assert.IsNotNull(ex); | 380 Assert.IsNotNull(ex); |
381 var result = ex.Error; | 381 var result = ex.Error; |
382 Assert.That(result.Error, Is.EqualTo("error")); | 382 Assert.That(result.Error, Is.EqualTo("error")); |
383 Assert.That(result.ErrorDescription, Is.EqualTo("desc")); | 383 Assert.That(result.ErrorDescription, Is.EqualTo("desc")); |
384 Assert.That(result.ErrorUri, Is.EqualTo("uri")); | 384 Assert.That(result.ErrorUri, Is.EqualTo("uri")); |
385 } | 385 } |
386 } | 386 } |
387 | 387 |
388 #endregion | 388 #endregion |
389 | 389 |
390 /// <summary>Creates an authorization code flow with the given parameter
s.</summary> | 390 /// <summary>Creates an authorization code flow with the given parameter
s.</summary> |
391 /// <param name="dataStore">The data store.</param> | 391 /// <param name="dataStore">The data store.</param> |
392 /// <param name="scopes">The Scopes</param> | 392 /// <param name="scopes">The Scopes.</param> |
393 /// <param name="httpClientFactory">The HTTP client factory. If not set
the default will be used</param> | 393 /// <param name="httpClientFactory">The HTTP client factory. If not set
the default will be used.</param> |
394 /// <returns>Authorization code flow</returns> | 394 /// <returns>Authorization code flow</returns> |
395 private AuthorizationCodeFlow CreateFlow(IDataStore dataStore = null, IE
numerable<string> scopes = null, | 395 private AuthorizationCodeFlow CreateFlow(IDataStore dataStore = null, IE
numerable<string> scopes = null, |
396 IHttpClientFactory httpClientFactory = null) | 396 IHttpClientFactory httpClientFactory = null) |
397 { | 397 { |
398 var secrets = new ClientSecrets() { ClientId = "id", ClientSecret =
"secret" }; | 398 var secrets = new ClientSecrets() { ClientId = "id", ClientSecret =
"secret" }; |
399 var initializer = new AuthorizationCodeFlow.Initializer(Authorizatio
nCodeUrl, TokenUrl) | 399 var initializer = new AuthorizationCodeFlow.Initializer(Authorizatio
nCodeUrl, TokenUrl) |
400 { | 400 { |
401 ClientSecrets = secrets, | 401 ClientSecrets = secrets, |
402 HttpClientFactory = httpClientFactory | 402 HttpClientFactory = httpClientFactory |
403 }; | 403 }; |
(...skipping 12 matching lines...) Expand all Loading... |
416 /// <summary>Verifies that the token response contains the expected data
.</summary> | 416 /// <summary>Verifies that the token response contains the expected data
.</summary> |
417 /// <param name="response">The token response</param> | 417 /// <param name="response">The token response</param> |
418 private void SubtestTokenResponse(TokenResponse response) | 418 private void SubtestTokenResponse(TokenResponse response) |
419 { | 419 { |
420 Assert.That(response.RefreshToken, Is.EqualTo("r")); | 420 Assert.That(response.RefreshToken, Is.EqualTo("r")); |
421 Assert.That(response.ExpiresInSeconds, Is.EqualTo(100)); | 421 Assert.That(response.ExpiresInSeconds, Is.EqualTo(100)); |
422 Assert.That(response.Scope, Is.EqualTo("b")); | 422 Assert.That(response.Scope, Is.EqualTo("b")); |
423 } | 423 } |
424 } | 424 } |
425 } | 425 } |
LEFT | RIGHT |