| OLD | NEW |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 import 'dart:convert'; | 1 import 'dart:convert'; |
| 6 | |
| 7 import 'package:scheduled_test/scheduled_test.dart'; | 2 import 'package:scheduled_test/scheduled_test.dart'; |
| 8 import 'package:scheduled_test/scheduled_server.dart'; | 3 import 'package:scheduled_test/scheduled_server.dart'; |
| 9 import 'package:shelf/shelf.dart' as shelf; | 4 import 'package:shelf/shelf.dart' as shelf; |
| 10 | |
| 11 import '../../lib/src/io.dart'; | 5 import '../../lib/src/io.dart'; |
| 12 import '../descriptor.dart' as d; | 6 import '../descriptor.dart' as d; |
| 13 import '../test_pub.dart'; | 7 import '../test_pub.dart'; |
| 14 import 'utils.dart'; | 8 import 'utils.dart'; |
| 15 | |
| 16 main() { | 9 main() { |
| 17 initConfig(); | 10 initConfig(); |
| 18 // Regression test for issue 8849. | 11 integration( |
| 19 integration('with a server-rejected refresh token, authenticates again and ' | 12 'with a server-rejected refresh token, authenticates again and ' |
| 20 'saves credentials.json', () { | 13 'saves credentials.json', |
| 14 () { |
| 21 d.validPackage.create(); | 15 d.validPackage.create(); |
| 22 | |
| 23 var server = new ScheduledServer(); | 16 var server = new ScheduledServer(); |
| 24 d.credentialsFile(server, 'access token', | 17 d.credentialsFile( |
| 18 server, |
| 19 'access token', |
| 25 refreshToken: 'bad refresh token', | 20 refreshToken: 'bad refresh token', |
| 26 expiration: new DateTime.now().subtract(new Duration(hours: 1))) | 21 expiration: new DateTime.now().subtract(new Duration(hours: 1))).create(
); |
| 27 .create(); | |
| 28 | |
| 29 var pub = startPublish(server); | 22 var pub = startPublish(server); |
| 30 | |
| 31 confirmPublish(pub); | 23 confirmPublish(pub); |
| 32 | |
| 33 server.handle('POST', '/token', (request) { | 24 server.handle('POST', '/token', (request) { |
| 34 return drainStream(request.read()).then((_) { | 25 return drainStream(request.read()).then((_) { |
| 35 return new shelf.Response(400, | 26 return new shelf.Response(400, body: JSON.encode({ |
| 36 body: JSON.encode({"error": "invalid_request"}), | 27 "error": "invalid_request" |
| 37 headers: {'content-type': 'application/json'}); | 28 }), headers: { |
| 29 'content-type': 'application/json' |
| 30 }); |
| 38 }); | 31 }); |
| 39 }); | 32 }); |
| 40 | |
| 41 pub.stdout.expect(startsWith('Uploading...')); | 33 pub.stdout.expect(startsWith('Uploading...')); |
| 42 authorizePub(pub, server, 'new access token'); | 34 authorizePub(pub, server, 'new access token'); |
| 43 | |
| 44 server.handle('GET', '/api/packages/versions/new', (request) { | 35 server.handle('GET', '/api/packages/versions/new', (request) { |
| 45 expect(request.headers, | 36 expect( |
| 37 request.headers, |
| 46 containsPair('authorization', 'Bearer new access token')); | 38 containsPair('authorization', 'Bearer new access token')); |
| 47 | |
| 48 return new shelf.Response(200); | 39 return new shelf.Response(200); |
| 49 }); | 40 }); |
| 50 | |
| 51 pub.kill(); | 41 pub.kill(); |
| 52 }); | 42 }); |
| 53 } | 43 } |
| OLD | NEW |