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 import 'dart:convert'; | 5 import 'dart:convert'; |
6 | 6 |
7 import 'package:scheduled_test/scheduled_test.dart'; | 7 import 'package:scheduled_test/scheduled_test.dart'; |
8 import 'package:scheduled_test/scheduled_server.dart'; | 8 import 'package:scheduled_test/scheduled_server.dart'; |
9 import 'package:shelf/shelf.dart' as shelf; | 9 import 'package:shelf/shelf.dart' as shelf; |
10 | 10 |
11 import '../descriptor.dart' as d; | 11 import '../descriptor.dart' as d; |
12 import '../test_pub.dart'; | 12 import '../test_pub.dart'; |
13 | 13 |
14 main() { | 14 main() { |
15 initConfig(); | 15 initConfig(); |
16 integration('with an expired credentials.json, refreshes and saves the ' | 16 integration( |
17 'refreshed access token to credentials.json', () { | 17 'with an expired credentials.json, refreshes and saves the ' |
| 18 'refreshed access token to credentials.json', |
| 19 () { |
18 d.validPackage.create(); | 20 d.validPackage.create(); |
19 | 21 |
20 var server = new ScheduledServer(); | 22 var server = new ScheduledServer(); |
21 d.credentialsFile(server, 'access token', | 23 d.credentialsFile( |
| 24 server, |
| 25 'access token', |
22 refreshToken: 'refresh token', | 26 refreshToken: 'refresh token', |
23 expiration: new DateTime.now().subtract(new Duration(hours: 1))) | 27 expiration: new DateTime.now().subtract(new Duration(hours: 1))).create(
); |
24 .create(); | |
25 | 28 |
26 var pub = startPublish(server); | 29 var pub = startPublish(server); |
27 confirmPublish(pub); | 30 confirmPublish(pub); |
28 | 31 |
29 server.handle('POST', '/token', (request) { | 32 server.handle('POST', '/token', (request) { |
30 return request.readAsString().then((body) { | 33 return request.readAsString().then((body) { |
31 expect(body, matches( | 34 expect( |
32 new RegExp(r'(^|&)refresh_token=refresh\+token(&|$)'))); | 35 body, |
| 36 matches(new RegExp(r'(^|&)refresh_token=refresh\+token(&|$)'))); |
33 | 37 |
34 return new shelf.Response.ok(JSON.encode({ | 38 return new shelf.Response.ok(JSON.encode({ |
35 "access_token": "new access token", | 39 "access_token": "new access token", |
36 "token_type": "bearer" | 40 "token_type": "bearer" |
37 }), headers: {'content-type': 'application/json'}); | 41 }), headers: { |
| 42 'content-type': 'application/json' |
| 43 }); |
38 }); | 44 }); |
39 }); | 45 }); |
40 | 46 |
41 server.handle('GET', '/api/packages/versions/new', (request) { | 47 server.handle('GET', '/api/packages/versions/new', (request) { |
42 expect(request.headers, | 48 expect( |
| 49 request.headers, |
43 containsPair('authorization', 'Bearer new access token')); | 50 containsPair('authorization', 'Bearer new access token')); |
44 | 51 |
45 return new shelf.Response(200); | 52 return new shelf.Response(200); |
46 }); | 53 }); |
47 | 54 |
48 pub.shouldExit(); | 55 pub.shouldExit(); |
49 | 56 |
50 d.credentialsFile(server, 'new access token', refreshToken: 'refresh token') | 57 d.credentialsFile( |
51 .validate(); | 58 server, |
| 59 'new access token', |
| 60 refreshToken: 'refresh token').validate(); |
52 }); | 61 }); |
53 } | 62 } |
OLD | NEW |