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

Unified Diff: utils/tests/pub/oauth2_test.dart

Issue 12782005: Revert "Use scheduled_test for Pub tests." (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « utils/tests/pub/install/relative_symlink_test.dart ('k') | utils/tests/pub/pub_cache_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/tests/pub/oauth2_test.dart
diff --git a/utils/tests/pub/oauth2_test.dart b/utils/tests/pub/oauth2_test.dart
index 0b2772b95acae80bc99c64dcc0de98c9c4b38629..afeedc6521dc5232dce6a3c31d3623af8a464b27 100644
--- a/utils/tests/pub/oauth2_test.dart
+++ b/utils/tests/pub/oauth2_test.dart
@@ -8,53 +8,47 @@ import 'dart:io';
import 'dart:json' as json;
import 'dart:uri';
+import 'test_pub.dart';
import '../../../pkg/http/lib/http.dart' as http;
-import '../../../pkg/scheduled_test/lib/scheduled_process.dart';
-import '../../../pkg/scheduled_test/lib/scheduled_test.dart';
-import '../../../pkg/scheduled_test/lib/scheduled_server.dart';
-
+import '../../../pkg/unittest/lib/unittest.dart';
import '../../pub/io.dart';
import '../../pub/utils.dart';
-import 'descriptor.dart' as d;
-import 'test_pub.dart';
-
-import 'dart:async';
main() {
- setUp(() => d.validPackage.create());
+ setUp(() => normalPackage.scheduleCreate());
integration('with no credentials.json, authenticates and saves '
'credentials.json', () {
var server = new ScheduledServer();
- var pub = startPublish(server);
+ var pub = startPubLish(server);
confirmPublish(pub);
authorizePub(pub, server);
- server.handle('GET', '/packages/versions/new.json', (request) {
+ server.handle('GET', '/packages/versions/new.json', (request, response) {
expect(request.headers.value('authorization'),
equals('Bearer access token'));
- request.response.close();
+ response.close();
});
// After we give pub an invalid response, it should crash. We wait for it to
// do so rather than killing it so it'll write out the credentials file.
pub.shouldExit(1);
- d.credentialsFile(server, 'access token').validate();
+ credentialsFile(server, 'access token').scheduleValidate();
});
integration('with a pre-existing credentials.json does not authenticate', () {
var server = new ScheduledServer();
- d.credentialsFile(server, 'access token').create();
- var pub = startPublish(server);
+ credentialsFile(server, 'access token').scheduleCreate();
+ var pub = startPubLish(server);
confirmPublish(pub);
- server.handle('GET', '/packages/versions/new.json', (request) {
+ server.handle('GET', '/packages/versions/new.json', (request, response) {
expect(request.headers.value('authorization'),
equals('Bearer access token'));
- request.response.close();
+ response.close();
});
pub.kill();
@@ -63,111 +57,110 @@ main() {
integration('with an expired credentials.json, refreshes and saves the '
'refreshed access token to credentials.json', () {
var server = new ScheduledServer();
- d.credentialsFile(server, 'access token',
+ credentialsFile(server, 'access token',
refreshToken: 'refresh token',
expiration: new DateTime.now().subtract(new Duration(hours: 1)))
- .create();
+ .scheduleCreate();
- var pub = startPublish(server);
+ var pub = startPubLish(server);
confirmPublish(pub);
- server.handle('POST', '/token', (request) {
+ server.handle('POST', '/token', (request, response) {
return new ByteStream(request).toBytes().then((bytes) {
var body = new String.fromCharCodes(bytes);
expect(body, matches(
new RegExp(r'(^|&)refresh_token=refresh\+token(&|$)')));
- request.response.headers.contentType =
- new ContentType("application", "json");
- request.response.write(json.stringify({
+ response.headers.contentType = new ContentType("application", "json");
+ response.write(json.stringify({
"access_token": "new access token",
"token_type": "bearer"
}));
- request.response.close();
+ response.close();
});
});
- server.handle('GET', '/packages/versions/new.json', (request) {
+ server.handle('GET', '/packages/versions/new.json', (request, response) {
expect(request.headers.value('authorization'),
equals('Bearer new access token'));
- request.response.close();
+ response.close();
});
pub.shouldExit();
- d.credentialsFile(server, 'new access token', refreshToken: 'refresh token')
- .validate();
+ credentialsFile(server, 'new access token', refreshToken: 'refresh token')
+ .scheduleValidate();
});
integration('with an expired credentials.json without a refresh token, '
'authenticates again and saves credentials.json', () {
var server = new ScheduledServer();
- d.credentialsFile(server, 'access token',
+ credentialsFile(server, 'access token',
expiration: new DateTime.now().subtract(new Duration(hours: 1)))
- .create();
+ .scheduleCreate();
- var pub = startPublish(server);
+ var pub = startPubLish(server);
confirmPublish(pub);
- expect(pub.nextErrLine(), completion(equals("Pub's authorization to upload "
- "packages has expired and can't be automatically refreshed.")));
+ expectLater(pub.nextErrLine(), equals("Pub's authorization to upload "
+ "packages has expired and can't be automatically refreshed."));
authorizePub(pub, server, "new access token");
- server.handle('GET', '/packages/versions/new.json', (request) {
+ server.handle('GET', '/packages/versions/new.json', (request, response) {
expect(request.headers.value('authorization'),
equals('Bearer new access token'));
- request.response.close();
+ response.close();
});
// After we give pub an invalid response, it should crash. We wait for it to
// do so rather than killing it so it'll write out the credentials file.
pub.shouldExit(1);
- d.credentialsFile(server, 'new access token').validate();
+ credentialsFile(server, 'new access token').scheduleValidate();
});
integration('with a malformed credentials.json, authenticates again and '
'saves credentials.json', () {
var server = new ScheduledServer();
- d.dir(cachePath, [
- d.file('credentials.json', '{bad json')
- ]).create();
+ dir(cachePath, [
+ file('credentials.json', '{bad json')
+ ]).scheduleCreate();
- var pub = startPublish(server);
+ var pub = startPubLish(server);
confirmPublish(pub);
authorizePub(pub, server, "new access token");
- server.handle('GET', '/packages/versions/new.json', (request) {
+ server.handle('GET', '/packages/versions/new.json', (request, response) {
expect(request.headers.value('authorization'),
equals('Bearer new access token'));
- request.response.close();
+ response.close();
});
+
// After we give pub an invalid response, it should crash. We wait for it to
// do so rather than killing it so it'll write out the credentials file.
pub.shouldExit(1);
- d.credentialsFile(server, 'new access token').validate();
+ credentialsFile(server, 'new access token').scheduleValidate();
});
// Regression test for issue 8849.
integration('with a server-rejected refresh token, authenticates again and '
'saves credentials.json', () {
var server = new ScheduledServer();
- d.credentialsFile(server, 'access token',
+ credentialsFile(server, 'access token',
refreshToken: 'bad refresh token',
expiration: new DateTime.now().subtract(new Duration(hours: 1)))
- .create();
+ .scheduleCreate();
- var pub = startPublish(server);
+ var pub = startPubLish(server);
confirmPublish(pub);
- server.handle('POST', '/token', (request) {
+ server.handle('POST', '/token', (request, response) {
return new ByteStream(request).toBytes().then((bytes) {
- var response = request.response;
response.statusCode = 400;
response.reasonPhrase = 'Bad request';
response.headers.contentType = new ContentType("application", "json");
@@ -178,11 +171,11 @@ main() {
authorizePub(pub, server, 'new access token');
- server.handle('GET', '/packages/versions/new.json', (request) {
+ server.handle('GET', '/packages/versions/new.json', (request, response) {
expect(request.headers.value('authorization'),
equals('Bearer new access token'));
- request.response.close();
+ response.close();
});
pub.kill();
@@ -191,13 +184,12 @@ main() {
integration('with server-rejected credentials, authenticates again and saves '
'credentials.json', () {
var server = new ScheduledServer();
- d.credentialsFile(server, 'access token').create();
- var pub = startPublish(server);
+ credentialsFile(server, 'access token').scheduleCreate();
+ var pub = startPubLish(server);
confirmPublish(pub);
- server.handle('GET', '/packages/versions/new.json', (request) {
- var response = request.response;
+ server.handle('GET', '/packages/versions/new.json', (request, response) {
response.statusCode = 401;
response.headers.set('www-authenticate', 'Bearer error="invalid_token",'
' error_description="your token sucks"');
@@ -207,14 +199,14 @@ main() {
response.close();
});
- expect(pub.nextErrLine(), completion(equals('OAuth2 authorization failed '
- '(your token sucks).')));
+ expectLater(pub.nextErrLine(), equals('OAuth2 authorization failed (your '
+ 'token sucks).'));
// TODO(rnystrom): The confirm line is run together with this one because
// in normal usage, the user will have entered a newline on stdin which
// gets echoed to the terminal. Do something better here?
- expect(pub.nextLine(), completion(equals(
+ expectLater(pub.nextLine(), equals(
'Looks great! Are you ready to upload your package (y/n)? '
- 'Pub needs your authorization to upload packages on your behalf.')));
+ 'Pub needs your authorization to upload packages on your behalf.'));
pub.kill();
});
}
@@ -224,11 +216,11 @@ void authorizePub(ScheduledProcess pub, ScheduledServer server,
// TODO(rnystrom): The confirm line is run together with this one because
// in normal usage, the user will have entered a newline on stdin which
// gets echoed to the terminal. Do something better here?
- expect(pub.nextLine(), completion(equals(
+ expectLater(pub.nextLine(), equals(
'Looks great! Are you ready to upload your package (y/n)? '
- 'Pub needs your authorization to upload packages on your behalf.')));
+ 'Pub needs your authorization to upload packages on your behalf.'));
- expect(pub.nextLine().then((line) {
+ expectLater(pub.nextLine().then((line) {
var match = new RegExp(r'[?&]redirect_uri=([0-9a-zA-Z%+-]+)[$&]')
.firstMatch(line);
expect(match, isNotNull);
@@ -240,24 +232,23 @@ void authorizePub(ScheduledProcess pub, ScheduledServer server,
}).then((response) {
expect(response.headers['location'],
equals('http://pub.dartlang.org/authorized'));
- }), completes);
+ }), anything);
handleAccessTokenRequest(server, accessToken);
}
void handleAccessTokenRequest(ScheduledServer server, String accessToken) {
- server.handle('POST', '/token', (request) {
+ server.handle('POST', '/token', (request, response) {
return new ByteStream(request).toBytes().then((bytes) {
var body = new String.fromCharCodes(bytes);
expect(body, matches(new RegExp(r'(^|&)code=access\+code(&|$)')));
- request.response.headers.contentType =
- new ContentType("application", "json");
- request.response.write(json.stringify({
+ response.headers.contentType = new ContentType("application", "json");
+ response.write(json.stringify({
"access_token": accessToken,
"token_type": "bearer"
}));
- request.response.close();
+ response.close();
});
});
}
« no previous file with comments | « utils/tests/pub/install/relative_symlink_test.dart ('k') | utils/tests/pub/pub_cache_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698