OLD | NEW |
| (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 import 'package:oauth2/src/utils.dart'; | |
6 import 'package:test/test.dart'; | |
7 | |
8 void main() { | |
9 group('AuthenticateHeader', () { | |
10 test("parses a scheme", () { | |
11 var header = new AuthenticateHeader.parse('bearer'); | |
12 expect(header.scheme, equals('bearer')); | |
13 expect(header.parameters, equals({})); | |
14 }); | |
15 | |
16 test("lower-cases the scheme", () { | |
17 var header = new AuthenticateHeader.parse('BeaRer'); | |
18 expect(header.scheme, equals('bearer')); | |
19 expect(header.parameters, equals({})); | |
20 }); | |
21 | |
22 test("parses a scheme with trailing whitespace", () { | |
23 var header = new AuthenticateHeader.parse('bearer '); | |
24 expect(header.scheme, equals('bearer')); | |
25 expect(header.parameters, equals({})); | |
26 }); | |
27 | |
28 test("parses a scheme with one param", () { | |
29 var header = new AuthenticateHeader.parse('bearer foo="bar"'); | |
30 expect(header.scheme, equals('bearer')); | |
31 expect(header.parameters, equals({'foo': 'bar'})); | |
32 }); | |
33 | |
34 test("parses a scheme with several params", () { | |
35 var header = new AuthenticateHeader.parse( | |
36 'bearer foo="bar", bar="baz" ,baz="qux"'); | |
37 expect(header.scheme, equals('bearer')); | |
38 expect(header.parameters, equals({ | |
39 'foo': 'bar', | |
40 'bar': 'baz', | |
41 'baz': 'qux' | |
42 })); | |
43 }); | |
44 | |
45 test("lower-cases parameter names but not values", () { | |
46 var header = new AuthenticateHeader.parse('bearer FoO="bAr"'); | |
47 expect(header.scheme, equals('bearer')); | |
48 expect(header.parameters, equals({'foo': 'bAr'})); | |
49 }); | |
50 | |
51 test("allows empty values", () { | |
52 var header = new AuthenticateHeader.parse('bearer foo=""'); | |
53 expect(header.scheme, equals('bearer')); | |
54 expect(header.parameters, equals({'foo': ''})); | |
55 }); | |
56 | |
57 test("won't parse an empty string", () { | |
58 expect(() => new AuthenticateHeader.parse(''), | |
59 throwsFormatException); | |
60 }); | |
61 | |
62 test("won't parse a token without a value", () { | |
63 expect(() => new AuthenticateHeader.parse('bearer foo'), | |
64 throwsFormatException); | |
65 | |
66 expect(() => new AuthenticateHeader.parse('bearer foo='), | |
67 throwsFormatException); | |
68 }); | |
69 | |
70 test("won't parse a token without a value", () { | |
71 expect(() => new AuthenticateHeader.parse('bearer foo'), | |
72 throwsFormatException); | |
73 | |
74 expect(() => new AuthenticateHeader.parse('bearer foo='), | |
75 throwsFormatException); | |
76 }); | |
77 | |
78 test("won't parse a trailing comma", () { | |
79 expect(() => new AuthenticateHeader.parse('bearer foo="bar",'), | |
80 throwsFormatException); | |
81 }); | |
82 | |
83 test("won't parse a multiple params without a comma", () { | |
84 expect(() => new AuthenticateHeader.parse('bearer foo="bar" bar="baz"'), | |
85 throwsFormatException); | |
86 }); | |
87 }); | |
88 } | |
OLD | NEW |