| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library credentials_test; | 5 library credentials_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 | 9 |
| 10 import 'package:http/http.dart' as http; | 10 import 'package:http/http.dart' as http; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 var expiration = new DateTime.now().subtract(new Duration(hours: 1)); | 36 var expiration = new DateTime.now().subtract(new Duration(hours: 1)); |
| 37 var credentials = new oauth2.Credentials( | 37 var credentials = new oauth2.Credentials( |
| 38 'access token', null, null, null, expiration); | 38 'access token', null, null, null, expiration); |
| 39 expect(credentials.isExpired, isTrue); | 39 expect(credentials.isExpired, isTrue); |
| 40 }); | 40 }); |
| 41 | 41 |
| 42 test("can't refresh without a refresh token", () { | 42 test("can't refresh without a refresh token", () { |
| 43 var credentials = new oauth2.Credentials( | 43 var credentials = new oauth2.Credentials( |
| 44 'access token', null, tokenEndpoint); | 44 'access token', null, tokenEndpoint); |
| 45 expect(credentials.canRefresh, false); | 45 expect(credentials.canRefresh, false); |
| 46 credentials.refresh('identifier', 'secret', httpClient: httpClient) | 46 |
| 47 .catchError(expectAsync1((error) { | 47 expect(credentials.refresh('identifier', 'secret', httpClient: httpClient), |
| 48 expect(error is StateError, isTrue); | 48 throwsStateError); |
| 49 })); | |
| 50 }); | 49 }); |
| 51 | 50 |
| 52 test("can't refresh without a token endpoint", () { | 51 test("can't refresh without a token endpoint", () { |
| 53 var credentials = new oauth2.Credentials('access token', 'refresh token'); | 52 var credentials = new oauth2.Credentials('access token', 'refresh token'); |
| 54 expect(credentials.canRefresh, false); | 53 expect(credentials.canRefresh, false); |
| 55 credentials.refresh('identifier', 'secret', httpClient: httpClient) | 54 |
| 56 .catchError(expectAsync1((error) { | 55 expect(credentials.refresh('identifier', 'secret', httpClient: httpClient), |
| 57 expect(error is StateError, isTrue); | 56 throwsStateError); |
| 58 })); | |
| 59 }); | 57 }); |
| 60 | 58 |
| 61 test("can refresh with a refresh token and a token endpoint", () { | 59 test("can refresh with a refresh token and a token endpoint", () { |
| 62 var credentials = new oauth2.Credentials( | 60 var credentials = new oauth2.Credentials( |
| 63 'access token', 'refresh token', tokenEndpoint, ['scope1', 'scope2']); | 61 'access token', 'refresh token', tokenEndpoint, ['scope1', 'scope2']); |
| 64 expect(credentials.canRefresh, true); | 62 expect(credentials.canRefresh, true); |
| 65 | 63 |
| 66 httpClient.expectRequest((request) { | 64 httpClient.expectRequest((request) { |
| 67 expect(request.method, equals('POST')); | 65 expect(request.method, equals('POST')); |
| 68 expect(request.url.toString(), equals(tokenEndpoint.toString())); | 66 expect(request.url.toString(), equals(tokenEndpoint.toString())); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 expect(() => fromMap({"accessToken": "foo", "scopes": 12}), | 167 expect(() => fromMap({"accessToken": "foo", "scopes": 12}), |
| 170 throwsFormatException); | 168 throwsFormatException); |
| 171 }); | 169 }); |
| 172 | 170 |
| 173 test("should throw a FormatException if expiration is not an int", () { | 171 test("should throw a FormatException if expiration is not an int", () { |
| 174 expect(() => fromMap({"accessToken": "foo", "expiration": "12"}), | 172 expect(() => fromMap({"accessToken": "foo", "expiration": "12"}), |
| 175 throwsFormatException); | 173 throwsFormatException); |
| 176 }); | 174 }); |
| 177 }); | 175 }); |
| 178 } | 176 } |
| OLD | NEW |