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

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

Issue 11316325: Make the oauth2 lib handle OAuth2 401 errors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library utils_test;
6
7 import '../../unittest/lib/unittest.dart';
8 import '../lib/src/utils.dart';
9
10
11 // A matcher that matches a Pair.
12 Matcher pairOf(Matcher firstMatcher, Matcher lastMatcher) =>
13 new _PairMatcher(firstMatcher, lastMatcher);
14
15 class _PairMatcher extends BaseMatcher {
16 final Matcher _firstMatcher;
17 final Matcher _lastMatcher;
18
19 _PairMatcher(this._firstMatcher, this._lastMatcher);
20
21 bool matches(item, MatchState matchState) {
22 if (item is! Pair) return false;
23 return _firstMatcher.matches(item.first, matchState) &&
24 _lastMatcher.matches(item.last, matchState);
25 }
26
27 Description describe(Description description) {
28 description.addAll("(", ", ", ")", [_firstMatcher, _lastMatcher]);
29 }
30 }
31
32
33 void main() {
34 group('parseAuthenticateHeader', () {
35 test("parses a scheme", () {
36 expect(parseAuthenticateHeader('bearer'),
37 pairOf(equals('bearer'), equals({})));
38 });
39
40 test("lower-cases the scheme", () {
41 expect(parseAuthenticateHeader('BeaRer'),
42 pairOf(equals('bearer'), equals({})));
43 });
44
45 test("parses a scheme with trailing whitespace", () {
46 expect(parseAuthenticateHeader('bearer '),
47 pairOf(equals('bearer'), equals({})));
48 });
49
50 test("parses a scheme with one param", () {
51 expect(parseAuthenticateHeader('bearer foo="bar"'),
52 pairOf(equals('bearer'), equals({'foo': 'bar'})));
53 });
54
55 test("parses a scheme with several params", () {
56 var header = 'bearer foo="bar", bar="baz" ,baz="qux"';
57 expect(parseAuthenticateHeader(header),
58 pairOf(equals('bearer'), equals({
59 'foo': 'bar',
60 'bar': 'baz',
61 'baz': 'qux'
62 })));
63 });
64
65 test("lower-cases parameter names but not values", () {
66 expect(parseAuthenticateHeader('bearer FoO="bAr"'),
67 pairOf(equals('bearer'), equals({'foo': 'bAr'})));
68 });
69
70 test("allows empty values", () {
71 expect(parseAuthenticateHeader('bearer foo=""'),
72 pairOf(equals('bearer'), equals({'foo': ''})));
73 });
74
75 test("won't parse an empty string", () {
76 expect(() => parseAuthenticateHeader(''),
77 throwsFormatException);
78 });
79
80 test("won't parse a token without a value", () {
81 expect(() => parseAuthenticateHeader('bearer foo'),
82 throwsFormatException);
83
84 expect(() => parseAuthenticateHeader('bearer foo='),
85 throwsFormatException);
86 });
87
88 test("won't parse a token without a value", () {
89 expect(() => parseAuthenticateHeader('bearer foo'),
90 throwsFormatException);
91
92 expect(() => parseAuthenticateHeader('bearer foo='),
93 throwsFormatException);
94 });
95
96 test("won't parse a trailing comma", () {
97 expect(() => parseAuthenticateHeader('bearer foo="bar",'),
98 throwsFormatException);
99 });
100
101 test("won't parse a multiple params without a comma", () {
102 expect(() => parseAuthenticateHeader('bearer foo="bar" bar="baz"'),
103 throwsFormatException);
104 });
105 });
106 }
OLDNEW
« pkg/oauth2/test/client_test.dart ('K') | « pkg/oauth2/test/client_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698