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

Side by Side Diff: pkg/oauth2/test/client_test.dart

Issue 187843006: pkg/oauth2 bringing tests into 2014 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: cl tweaks Created 6 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
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 client_test; 5 library client_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 9
10 import 'package:http/http.dart' as http; 10 import 'package:http/http.dart' as http;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 setUp(createHttpClient); 74 setUp(createHttpClient);
75 75
76 test("sends a request with bearer authorization", () { 76 test("sends a request with bearer authorization", () {
77 var credentials = new oauth2.Credentials('access token'); 77 var credentials = new oauth2.Credentials('access token');
78 var client = new oauth2.Client('identifier', 'secret', credentials, 78 var client = new oauth2.Client('identifier', 'secret', credentials,
79 httpClient: httpClient); 79 httpClient: httpClient);
80 80
81 httpClient.expectRequest((request) { 81 httpClient.expectRequest((request) {
82 expect(request.method, equals('GET')); 82 expect(request.method, equals('GET'));
83 expect(request.url.toString(), equals(requestUri.toString())); 83 expect(request.url.toString(), equals(requestUri.toString()));
84 expect(request.headers['authorization'], 84 expect(request.headers['authorization'], equals('Bearer access token'));
85 equals('Bearer access token'));
86 85
87 return new Future.value(new http.Response('good job', 200)); 86 return new Future.value(new http.Response('good job', 200));
88 }); 87 });
89 88
90 expect(client.read(requestUri), completion(equals('good job'))); 89 expect(client.read(requestUri), completion(equals('good job')));
91 }); 90 });
92 91
93 test("can manually refresh the credentials", () { 92 test("can manually refresh the credentials", () {
94 var credentials = new oauth2.Credentials( 93 var credentials = new oauth2.Credentials(
95 'access token', 'refresh token', tokenEndpoint); 94 'access token', 'refresh token', tokenEndpoint);
(...skipping 27 matching lines...) Expand all
123 setUp(createHttpClient); 122 setUp(createHttpClient);
124 123
125 test('throws an AuthorizationException for a 401 response', () { 124 test('throws an AuthorizationException for a 401 response', () {
126 var credentials = new oauth2.Credentials('access token'); 125 var credentials = new oauth2.Credentials('access token');
127 var client = new oauth2.Client('identifier', 'secret', credentials, 126 var client = new oauth2.Client('identifier', 'secret', credentials,
128 httpClient: httpClient); 127 httpClient: httpClient);
129 128
130 httpClient.expectRequest((request) { 129 httpClient.expectRequest((request) {
131 expect(request.method, equals('GET')); 130 expect(request.method, equals('GET'));
132 expect(request.url.toString(), equals(requestUri.toString())); 131 expect(request.url.toString(), equals(requestUri.toString()));
133 expect(request.headers['authorization'], 132 expect(request.headers['authorization'], equals('Bearer access token'));
134 equals('Bearer access token'));
135 133
136 var authenticate = 'Bearer error="invalid_token", error_description=' 134 var authenticate = 'Bearer error="invalid_token", error_description='
137 '"Something is terribly wrong."'; 135 '"Something is terribly wrong."';
138 return new Future.value(new http.Response('bad job', 401, 136 return new Future.value(new http.Response('bad job', 401,
139 headers: {'www-authenticate': authenticate})); 137 headers: {'www-authenticate': authenticate}));
140 }); 138 });
141 139
142 expect(client.read(requestUri), 140 expect(client.read(requestUri),
143 throwsA(new isInstanceOf<oauth2.AuthorizationException>())); 141 throwsA(new isInstanceOf<oauth2.AuthorizationException>()));
144 }); 142 });
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 return new Future.value(new http.Response('bad job', 401, 216 return new Future.value(new http.Response('bad job', 401,
219 headers: {'www-authenticate': 'Bearer'})); 217 headers: {'www-authenticate': 'Bearer'}));
220 }); 218 });
221 219
222 expect( 220 expect(
223 client.get(requestUri).then((response) => response.statusCode), 221 client.get(requestUri).then((response) => response.statusCode),
224 completion(equals(401))); 222 completion(equals(401)));
225 }); 223 });
226 }); 224 });
227 } 225 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698