Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(429)

Side by Side Diff: utils/tests/pub/oauth2_test.dart

Issue 11464015: Revert "Stop working around issue 6984." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Base files Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utils/pub/oauth2.dart ('k') | utils/tests/pub/pub_lish_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 oauth2_test; 5 library oauth2_test;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 import 'dart:json'; 8 import 'dart:json';
9 import 'dart:uri'; 9 import 'dart:uri';
10 10
11 import 'test_pub.dart'; 11 import 'test_pub.dart';
12 import '../../../pkg/http/lib/http.dart' as http; 12 import '../../../pkg/http/lib/http.dart' as http;
13 import '../../../pkg/unittest/lib/unittest.dart'; 13 import '../../../pkg/unittest/lib/unittest.dart';
14 import '../../pub/io.dart'; 14 import '../../pub/io.dart';
15 import '../../pub/utils.dart'; 15 import '../../pub/utils.dart';
16 16
17 main() { 17 main() {
18 setUp(() => dir(appPath, [libPubspec("test_pkg", "1.0.0")]).scheduleCreate()); 18 setUp(() => dir(appPath, [libPubspec("test_pkg", "1.0.0")]).scheduleCreate());
19 19
20 test('with no credentials.json, authenticates and saves credentials.json', 20 test('with no credentials.json, authenticates and saves credentials.json',
21 () { 21 () {
22 var server = new ScheduledServer(); 22 var server = new ScheduledServer();
23 var pub = startPubLish(server); 23 var pub = startPubLish(server);
24 authorizePub(pub, server); 24 authorizePub(pub, server);
25 25
26 server.handle('GET', '/packages/versions/new.json', (request, response) { 26 server.handle('GET', '/packages/versions/new.json', (request, response) {
27 expect(request.headers.value('authorization'), 27 expect(request.headers.value('authorization'),
28 equals('Bearer access token')); 28 equals('Bearer access token'));
29 29
30 response.outputStream.close(); 30 return closeHttpResponse(request, response);
31 }); 31 });
32 32
33 pub.kill(); 33 pub.kill();
34 34
35 credentialsFile(server, 'access token').scheduleValidate(); 35 credentialsFile(server, 'access token').scheduleValidate();
36 36
37 run(); 37 run();
38 }); 38 });
39 39
40 test('with a pre-existing credentials.json does not authenticate', () { 40 test('with a pre-existing credentials.json does not authenticate', () {
41 var server = new ScheduledServer(); 41 var server = new ScheduledServer();
42 credentialsFile(server, 'access token').scheduleCreate(); 42 credentialsFile(server, 'access token').scheduleCreate();
43 var pub = startPubLish(server); 43 var pub = startPubLish(server);
44 44
45 server.handle('GET', '/packages/versions/new.json', (request, response) { 45 server.handle('GET', '/packages/versions/new.json', (request, response) {
46 expect(request.headers.value('authorization'), 46 expect(request.headers.value('authorization'),
47 equals('Bearer access token')); 47 equals('Bearer access token'));
48 48
49 response.outputStream.close(); 49 return closeHttpResponse(request, response);
50 }); 50 });
51 51
52 pub.kill(); 52 pub.kill();
53 53
54 run(); 54 run();
55 }); 55 });
56 56
57 test('with an expired credentials.json, refreshes and saves the refreshed ' 57 test('with an expired credentials.json, refreshes and saves the refreshed '
58 'access token to credentials.json', () { 58 'access token to credentials.json', () {
59 var server = new ScheduledServer(); 59 var server = new ScheduledServer();
(...skipping 16 matching lines...) Expand all
76 "token_type": "bearer" 76 "token_type": "bearer"
77 })); 77 }));
78 response.outputStream.close(); 78 response.outputStream.close();
79 }); 79 });
80 }); 80 });
81 81
82 server.handle('GET', '/packages/versions/new.json', (request, response) { 82 server.handle('GET', '/packages/versions/new.json', (request, response) {
83 expect(request.headers.value('authorization'), 83 expect(request.headers.value('authorization'),
84 equals('Bearer new access token')); 84 equals('Bearer new access token'));
85 85
86 response.outputStream.close(); 86 return closeHttpResponse(request, response);
87 }); 87 });
88 88
89 pub.shouldExit(); 89 pub.shouldExit();
90 90
91 credentialsFile(server, 'new access token', refreshToken: 'refresh token') 91 credentialsFile(server, 'new access token', refreshToken: 'refresh token')
92 .scheduleValidate(); 92 .scheduleValidate();
93 93
94 run(); 94 run();
95 }); 95 });
96 96
97 test('with an expired credentials.json without a refresh token, ' 97 test('with an expired credentials.json without a refresh token, '
98 'authenticates again and saves credentials.json', () { 98 'authenticates again and saves credentials.json', () {
99 var server = new ScheduledServer(); 99 var server = new ScheduledServer();
100 credentialsFile(server, 'access token', 100 credentialsFile(server, 'access token',
101 expiration: new Date.now().subtract(new Duration(hours: 1))) 101 expiration: new Date.now().subtract(new Duration(hours: 1)))
102 .scheduleCreate(); 102 .scheduleCreate();
103 103
104 var pub = startPubLish(server); 104 var pub = startPubLish(server);
105 105
106 expectLater(pub.nextErrLine(), equals("Pub's authorization to upload " 106 expectLater(pub.nextErrLine(), equals("Pub's authorization to upload "
107 "packages has expired and can't be automatically refreshed.")); 107 "packages has expired and can't be automatically refreshed."));
108 authorizePub(pub, server, "new access token"); 108 authorizePub(pub, server, "new access token");
109 109
110 server.handle('GET', '/packages/versions/new.json', (request, response) { 110 server.handle('GET', '/packages/versions/new.json', (request, response) {
111 expect(request.headers.value('authorization'), 111 expect(request.headers.value('authorization'),
112 equals('Bearer new access token')); 112 equals('Bearer new access token'));
113 113
114 response.outputStream.close(); 114 return closeHttpResponse(request, response);
115 }); 115 });
116 116
117 pub.kill(); 117 pub.kill();
118 118
119 credentialsFile(server, 'new access token').scheduleValidate(); 119 credentialsFile(server, 'new access token').scheduleValidate();
120 120
121 run(); 121 run();
122 }); 122 });
123 123
124 test('with a malformed credentials.json, authenticates again and saves ' 124 test('with a malformed credentials.json, authenticates again and saves '
125 'credentials.json', () { 125 'credentials.json', () {
126 var server = new ScheduledServer(); 126 var server = new ScheduledServer();
127 dir(cachePath, [ 127 dir(cachePath, [
128 file('credentials.json', '{bad json') 128 file('credentials.json', '{bad json')
129 ]).scheduleCreate(); 129 ]).scheduleCreate();
130 130
131 var pub = startPubLish(server); 131 var pub = startPubLish(server);
132 authorizePub(pub, server, "new access token"); 132 authorizePub(pub, server, "new access token");
133 133
134 server.handle('GET', '/packages/versions/new.json', (request, response) { 134 server.handle('GET', '/packages/versions/new.json', (request, response) {
135 expect(request.headers.value('authorization'), 135 expect(request.headers.value('authorization'),
136 equals('Bearer new access token')); 136 equals('Bearer new access token'));
137 137
138 response.outputStream.close(); 138 return closeHttpResponse(request, response);
139 }); 139 });
140 140
141 pub.kill(); 141 pub.kill();
142 142
143 credentialsFile(server, 'new access token').scheduleValidate(); 143 credentialsFile(server, 'new access token').scheduleValidate();
144 144
145 run(); 145 run();
146 }); 146 });
147 } 147 }
148 148
(...skipping 27 matching lines...) Expand all
176 176
177 response.headers.contentType = new ContentType("application", "json"); 177 response.headers.contentType = new ContentType("application", "json");
178 response.outputStream.writeString(JSON.stringify({ 178 response.outputStream.writeString(JSON.stringify({
179 "access_token": accessToken, 179 "access_token": accessToken,
180 "token_type": "bearer" 180 "token_type": "bearer"
181 })); 181 }));
182 response.outputStream.close(); 182 response.outputStream.close();
183 }); 183 });
184 }); 184 });
185 } 185 }
OLDNEW
« no previous file with comments | « utils/pub/oauth2.dart ('k') | utils/tests/pub/pub_lish_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698