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

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

Issue 12613010: Update pub to use the latest dart:io stream APIs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 months 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 | « no previous file | 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' as json; 8 import 'dart:json' as json;
9 import 'dart:uri'; 9 import 'dart:uri';
10 10
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 var pub = startPubLish(server); 65 var pub = startPubLish(server);
66 confirmPublish(pub); 66 confirmPublish(pub);
67 67
68 server.handle('POST', '/token', (request, response) { 68 server.handle('POST', '/token', (request, response) {
69 return new ByteStream(request).toBytes().then((bytes) { 69 return new ByteStream(request).toBytes().then((bytes) {
70 var body = new String.fromCharCodes(bytes); 70 var body = new String.fromCharCodes(bytes);
71 expect(body, matches( 71 expect(body, matches(
72 new RegExp(r'(^|&)refresh_token=refresh\+token(&|$)'))); 72 new RegExp(r'(^|&)refresh_token=refresh\+token(&|$)')));
73 73
74 response.headers.contentType = new ContentType("application", "json"); 74 response.headers.contentType = new ContentType("application", "json");
75 response.addString(json.stringify({ 75 response.write(json.stringify({
76 "access_token": "new access token", 76 "access_token": "new access token",
77 "token_type": "bearer" 77 "token_type": "bearer"
78 })); 78 }));
79 response.close(); 79 response.close();
80 }); 80 });
81 }); 81 });
82 82
83 server.handle('GET', '/packages/versions/new.json', (request, response) { 83 server.handle('GET', '/packages/versions/new.json', (request, response) {
84 expect(request.headers.value('authorization'), 84 expect(request.headers.value('authorization'),
85 equals('Bearer new access token')); 85 equals('Bearer new access token'));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 var server = new ScheduledServer(); 152 var server = new ScheduledServer();
153 credentialsFile(server, 'access token').scheduleCreate(); 153 credentialsFile(server, 'access token').scheduleCreate();
154 var pub = startPubLish(server); 154 var pub = startPubLish(server);
155 155
156 confirmPublish(pub); 156 confirmPublish(pub);
157 157
158 server.handle('GET', '/packages/versions/new.json', (request, response) { 158 server.handle('GET', '/packages/versions/new.json', (request, response) {
159 response.statusCode = 401; 159 response.statusCode = 401;
160 response.headers.set('www-authenticate', 'Bearer error="invalid_token",' 160 response.headers.set('www-authenticate', 'Bearer error="invalid_token",'
161 ' error_description="your token sucks"'); 161 ' error_description="your token sucks"');
162 response.addString(json.stringify({ 162 response.write(json.stringify({
163 'error': {'message': 'your token sucks'} 163 'error': {'message': 'your token sucks'}
164 })); 164 }));
165 response.close(); 165 response.close();
166 }); 166 });
167 167
168 expectLater(pub.nextErrLine(), equals('OAuth2 authorization failed (your ' 168 expectLater(pub.nextErrLine(), equals('OAuth2 authorization failed (your '
169 'token sucks).')); 169 'token sucks).'));
170 // TODO(rnystrom): The confirm line is run together with this one because 170 // TODO(rnystrom): The confirm line is run together with this one because
171 // in normal usage, the user will have entered a newline on stdin which 171 // in normal usage, the user will have entered a newline on stdin which
172 // gets echoed to the terminal. Do something better here? 172 // gets echoed to the terminal. Do something better here?
(...skipping 30 matching lines...) Expand all
203 handleAccessTokenRequest(server, accessToken); 203 handleAccessTokenRequest(server, accessToken);
204 } 204 }
205 205
206 void handleAccessTokenRequest(ScheduledServer server, String accessToken) { 206 void handleAccessTokenRequest(ScheduledServer server, String accessToken) {
207 server.handle('POST', '/token', (request, response) { 207 server.handle('POST', '/token', (request, response) {
208 return new ByteStream(request).toBytes().then((bytes) { 208 return new ByteStream(request).toBytes().then((bytes) {
209 var body = new String.fromCharCodes(bytes); 209 var body = new String.fromCharCodes(bytes);
210 expect(body, matches(new RegExp(r'(^|&)code=access\+code(&|$)'))); 210 expect(body, matches(new RegExp(r'(^|&)code=access\+code(&|$)')));
211 211
212 response.headers.contentType = new ContentType("application", "json"); 212 response.headers.contentType = new ContentType("application", "json");
213 response.addString(json.stringify({ 213 response.write(json.stringify({
214 "access_token": accessToken, 214 "access_token": accessToken,
215 "token_type": "bearer" 215 "token_type": "bearer"
216 })); 216 }));
217 response.close(); 217 response.close();
218 }); 218 });
219 }); 219 });
220 } 220 }
OLDNEW
« no previous file with comments | « no previous file | utils/tests/pub/pub_lish_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698