|
1 | 1 | import { describe, it, assert } from 'vitest'; |
2 | | -import auth from './index'; |
| 2 | +import { parse } from './index'; |
3 | 3 |
|
4 | | -function request(authorization: string) { |
5 | | - return { |
6 | | - headers: { |
7 | | - authorization: authorization, |
8 | | - }, |
9 | | - }; |
10 | | -} |
11 | | - |
12 | | -describe('auth.parse(string)', function () { |
| 4 | +describe('parse(string)', function () { |
13 | 5 | describe('with undefined string', function () { |
14 | 6 | it('should return undefined', function () { |
15 | | - assert.strictEqual((auth as any).parse(), undefined); |
| 7 | + assert.strictEqual((parse as any)(), undefined); |
16 | 8 | }); |
17 | 9 | }); |
18 | 10 |
|
19 | 11 | describe('with malformed string', function () { |
20 | 12 | it('should return undefined', function () { |
21 | | - assert.strictEqual(auth.parse('Something'), undefined); |
| 13 | + assert.strictEqual(parse('Something'), undefined); |
22 | 14 | }); |
23 | 15 | }); |
24 | 16 |
|
25 | 17 | describe('with malformed scheme', function () { |
26 | 18 | it('should return undefined', function () { |
27 | | - assert.strictEqual(auth.parse('basic_Zm9vOmJhcg=='), undefined); |
| 19 | + assert.strictEqual(parse('basic_Zm9vOmJhcg=='), undefined); |
28 | 20 | }); |
29 | 21 | }); |
30 | 22 |
|
31 | 23 | describe('with malformed credentials', function () { |
32 | 24 | it('should return undefined', function () { |
33 | | - assert.strictEqual(auth.parse('basic Zm9vcgo='), undefined); |
| 25 | + assert.strictEqual(parse('basic Zm9vcgo='), undefined); |
34 | 26 | }); |
35 | 27 | }); |
36 | 28 |
|
37 | 29 | describe('with valid credentials', function () { |
38 | 30 | it('should return .name and .pass', function () { |
39 | | - var creds = auth.parse('basic Zm9vOmJhcg=='); |
| 31 | + var creds = parse('basic Zm9vOmJhcg=='); |
40 | 32 | assert.strictEqual(creds?.name, 'foo'); |
41 | 33 | assert.strictEqual(creds?.pass, 'bar'); |
42 | 34 | }); |
43 | 35 | }); |
44 | 36 |
|
45 | 37 | describe('with empty password', function () { |
46 | 38 | it('should return .name and .pass', function () { |
47 | | - var creds = auth.parse('basic Zm9vOg=='); |
| 39 | + var creds = parse('basic Zm9vOg=='); |
48 | 40 | assert.strictEqual(creds?.name, 'foo'); |
49 | 41 | assert.strictEqual(creds?.pass, ''); |
50 | 42 | }); |
51 | 43 | }); |
52 | 44 |
|
53 | 45 | describe('with empty userid', function () { |
54 | 46 | it('should return .name and .pass', function () { |
55 | | - var creds = auth.parse('basic OnBhc3M='); |
| 47 | + var creds = parse('basic OnBhc3M='); |
56 | 48 | assert.strictEqual(creds?.name, ''); |
57 | 49 | assert.strictEqual(creds?.pass, 'pass'); |
58 | 50 | }); |
59 | 51 | }); |
60 | 52 |
|
61 | 53 | describe('with empty userid and pass', function () { |
62 | 54 | it('should return .name and .pass', function () { |
63 | | - var creds = auth.parse('basic Og=='); |
| 55 | + var creds = parse('basic Og=='); |
64 | 56 | assert.strictEqual(creds?.name, ''); |
65 | 57 | assert.strictEqual(creds?.pass, ''); |
66 | 58 | }); |
67 | 59 | }); |
68 | 60 |
|
69 | 61 | describe('with colon in pass', function () { |
70 | 62 | it('should return .name and .pass', function () { |
71 | | - var creds = auth.parse('basic Zm9vOnBhc3M6d29yZA=='); |
| 63 | + var creds = parse('basic Zm9vOnBhc3M6d29yZA=='); |
72 | 64 | assert.strictEqual(creds?.name, 'foo'); |
73 | 65 | assert.strictEqual(creds?.pass, 'pass:word'); |
74 | 66 | }); |
75 | 67 | }); |
76 | 68 |
|
77 | 69 | describe('with scheme "Basic"', function () { |
78 | 70 | it('should return .name and .pass', function () { |
79 | | - var req = request('Basic Zm9vOmJhcg=='); |
80 | | - var creds = auth(req); |
| 71 | + var creds = parse('Basic Zm9vOmJhcg=='); |
81 | 72 | assert.strictEqual(creds?.name, 'foo'); |
82 | 73 | assert.strictEqual(creds?.pass, 'bar'); |
83 | 74 | }); |
84 | 75 | }); |
85 | 76 |
|
86 | 77 | describe('with scheme "BASIC"', function () { |
87 | 78 | it('should return .name and .pass', function () { |
88 | | - var req = request('BASIC Zm9vOmJhcg=='); |
89 | | - var creds = auth(req); |
| 79 | + var creds = parse('BASIC Zm9vOmJhcg=='); |
90 | 80 | assert.strictEqual(creds?.name, 'foo'); |
91 | 81 | assert.strictEqual(creds?.pass, 'bar'); |
92 | 82 | }); |
93 | 83 | }); |
94 | 84 |
|
95 | 85 | describe('with scheme "BaSiC"', function () { |
96 | 86 | it('should return .name and .pass', function () { |
97 | | - var req = request('BaSiC Zm9vOmJhcg=='); |
98 | | - var creds = auth(req); |
| 87 | + var creds = parse('BaSiC Zm9vOmJhcg=='); |
99 | 88 | assert.strictEqual(creds?.name, 'foo'); |
100 | 89 | assert.strictEqual(creds?.pass, 'bar'); |
101 | 90 | }); |
|
0 commit comments