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

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

Issue 11569046: Add a pub command for managing uploaders for packages. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes 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/pub.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
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 142
143 response.outputStream.close(); 143 response.outputStream.close();
144 }); 144 });
145 145
146 pub.kill(); 146 pub.kill();
147 147
148 credentialsFile(server, 'new access token').scheduleValidate(); 148 credentialsFile(server, 'new access token').scheduleValidate();
149 149
150 run(); 150 run();
151 }); 151 });
152
153 test('with server-rejected credentials, authenticates again and saves '
154 'credentials.json', () {
155 var server = new ScheduledServer();
156 credentialsFile(server, 'access token').scheduleCreate();
157 var pub = startPubLish(server);
158
159 confirmPublish(pub);
160
161 server.handle('GET', '/packages/versions/new.json', (request, response) {
162 response.statusCode = 401;
163 response.headers.set('www-authenticate', 'Bearer error="invalid_token",'
164 ' error_description="your token sucks"');
165 response.outputStream.writeString(JSON.stringify({
166 'error': {'message': 'your token sucks'}
167 }));
168 response.outputStream.close();
169 });
170
171 expectLater(pub.nextErrLine(), equals('OAuth2 authorization failed (your '
172 'token sucks).'));
173 // TODO(rnystrom): The confirm line is run together with this one because
174 // in normal usage, the user will have entered a newline on stdin which
175 // gets echoed to the terminal. Do something better here?
176 expectLater(pub.nextLine(), equals(
177 'Looks great! Are you ready to upload your package (y/n)? '
178 'Pub needs your authorization to upload packages on your behalf.'));
179 pub.kill();
180 run();
181 });
152 } 182 }
153 183
154 void authorizePub(ScheduledProcess pub, ScheduledServer server, 184 void authorizePub(ScheduledProcess pub, ScheduledServer server,
155 [String accessToken="access token"]) { 185 [String accessToken="access token"]) {
156 // TODO(rnystrom): The confirm line is run together with this one because 186 // TODO(rnystrom): The confirm line is run together with this one because
157 // in normal usage, the user will have entered a newline on stdin which 187 // in normal usage, the user will have entered a newline on stdin which
158 // gets echoed to the terminal. Do something better here? 188 // gets echoed to the terminal. Do something better here?
159 expectLater(pub.nextLine(), equals( 189 expectLater(pub.nextLine(), equals(
160 'Looks great! Are you ready to upload your package (y/n)? ' 190 'Looks great! Are you ready to upload your package (y/n)? '
161 'Pub needs your authorization to upload packages on your behalf.')); 191 'Pub needs your authorization to upload packages on your behalf.'));
(...skipping 23 matching lines...) Expand all
185 215
186 response.headers.contentType = new ContentType("application", "json"); 216 response.headers.contentType = new ContentType("application", "json");
187 response.outputStream.writeString(JSON.stringify({ 217 response.outputStream.writeString(JSON.stringify({
188 "access_token": accessToken, 218 "access_token": accessToken,
189 "token_type": "bearer" 219 "token_type": "bearer"
190 })); 220 }));
191 response.outputStream.close(); 221 response.outputStream.close();
192 }); 222 });
193 }); 223 });
194 } 224 }
OLDNEW
« no previous file with comments | « utils/pub/pub.dart ('k') | utils/tests/pub/pub_lish_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698