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

Unified Diff: test/authorization_code_grant_test.dart

Issue 1320523003: Make a bunch of API changes. (Closed) Base URL: git@github.com:dart-lang/oauth2.git@master
Patch Set: Created 5 years, 4 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
Index: test/authorization_code_grant_test.dart
diff --git a/test/authorization_code_grant_test.dart b/test/authorization_code_grant_test.dart
index deaad5c14258c0b148d4e0b4b24f1abc75649a5e..e03a607594e4c6afa985f2624dd9bcdd8584178c 100644
--- a/test/authorization_code_grant_test.dart
+++ b/test/authorization_code_grant_test.dart
@@ -20,9 +20,9 @@ void main() {
client = new ExpectClient();
grant = new oauth2.AuthorizationCodeGrant(
'identifier',
- 'secret',
Uri.parse('https://example.com/authorization'),
Uri.parse('https://example.com/token'),
+ secret: 'secret',
httpClient: client);
});
@@ -60,9 +60,9 @@ void main() {
test('merges with existing query parameters', () {
grant = new oauth2.AuthorizationCodeGrant(
'identifier',
- 'secret',
Uri.parse('https://example.com/authorization?query=value'),
Uri.parse('https://example.com/token'),
+ secret: 'secret',
httpClient: client);
var authorizationUrl = grant.getAuthorizationUrl(redirectUrl);
@@ -127,10 +127,11 @@ void main() {
expect(request.bodyFields, equals({
'grant_type': 'authorization_code',
'code': 'auth code',
- 'redirect_uri': redirectUrl.toString(),
- 'client_id': 'identifier',
- 'client_secret': 'secret'
+ 'redirect_uri': redirectUrl.toString()
}));
+ expect(request.headers, containsPair(
+ "Authorization",
+ "Basic aWRlbnRpZmllcjpzZWNyZXQ="));
return new Future.value(new http.Response(JSON.encode({
'access_token': 'access token',
@@ -163,6 +164,71 @@ void main() {
expect(request.bodyFields, equals({
'grant_type': 'authorization_code',
'code': 'auth code',
+ 'redirect_uri': redirectUrl.toString()
+ }));
+ expect(request.headers, containsPair(
+ "Authorization",
+ "Basic aWRlbnRpZmllcjpzZWNyZXQ="));
+
+ return new Future.value(new http.Response(JSON.encode({
+ 'access_token': 'access token',
+ 'token_type': 'bearer',
+ }), 200, headers: {'content-type': 'application/json'}));
+ });
+
+ expect(grant.handleAuthorizationCode('auth code'),
+ completion(predicate((client) {
+ expect(client.credentials.accessToken, equals('access token'));
+ return true;
+ })));
+ });
+ });
+
+ group("with basicAuth: false", () {
+ setUp(() {
+ client = new ExpectClient();
+ grant = new oauth2.AuthorizationCodeGrant(
+ 'identifier',
+ Uri.parse('https://example.com/authorization'),
+ Uri.parse('https://example.com/token'),
+ secret: 'secret',
+ basicAuth: false,
+ httpClient: client);
+ });
+
+ test('.handleAuthorizationResponse sends an authorization code request',
+ () {
+ grant.getAuthorizationUrl(redirectUrl);
+ client.expectRequest((request) {
+ expect(request.method, equals('POST'));
+ expect(request.url.toString(), equals(grant.tokenEndpoint.toString()));
+ expect(request.bodyFields, equals({
+ 'grant_type': 'authorization_code',
+ 'code': 'auth code',
+ 'redirect_uri': redirectUrl.toString(),
+ 'client_id': 'identifier',
+ 'client_secret': 'secret'
+ }));
+
+ return new Future.value(new http.Response(JSON.encode({
+ 'access_token': 'access token',
+ 'token_type': 'bearer',
+ }), 200, headers: {'content-type': 'application/json'}));
+ });
+
+ expect(grant.handleAuthorizationResponse({'code': 'auth code'})
+ .then((client) => client.credentials.accessToken),
+ completion(equals('access token')));
+ });
+
+ test('.handleAuthorizationCode sends an authorization code request', () {
+ grant.getAuthorizationUrl(redirectUrl);
+ client.expectRequest((request) {
+ expect(request.method, equals('POST'));
+ expect(request.url.toString(), equals(grant.tokenEndpoint.toString()));
+ expect(request.bodyFields, equals({
+ 'grant_type': 'authorization_code',
+ 'code': 'auth code',
'redirect_uri': redirectUrl.toString(),
'client_id': 'identifier',
'client_secret': 'secret'
« lib/src/client.dart ('K') | « pubspec.yaml ('k') | test/client_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698