-
-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathparse.spec.ts
More file actions
98 lines (85 loc) · 2.98 KB
/
Copy pathparse.spec.ts
File metadata and controls
98 lines (85 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { describe, it, assert } from 'vitest';
import { parse } from './index';
describe('parse(string)', function () {
describe('with undefined string', function () {
it('should return undefined', function () {
assert.strictEqual((parse as any)(), undefined);
});
});
describe('with malformed string', function () {
it('should return undefined', function () {
assert.strictEqual(parse('Something'), undefined);
});
});
describe('with malformed scheme', function () {
it('should return undefined', function () {
assert.strictEqual(parse('basic_Zm9vOmJhcg=='), undefined);
});
});
describe('with malformed credentials', function () {
it('should return undefined', function () {
assert.strictEqual(parse('basic Zm9vcgo='), undefined);
});
});
describe('with invalid base64 credentials', function () {
it('should return undefined', function () {
assert.strictEqual(parse('basic invalidbase64'), undefined);
});
});
describe('with valid credentials', function () {
it('should return .name and .pass', function () {
var creds = parse('basic Zm9vOmJhcg==');
assert.strictEqual(creds?.name, 'foo');
assert.strictEqual(creds?.pass, 'bar');
});
});
describe('with empty password', function () {
it('should return .name and .pass', function () {
var creds = parse('basic Zm9vOg==');
assert.strictEqual(creds?.name, 'foo');
assert.strictEqual(creds?.pass, '');
});
});
describe('with empty userid', function () {
it('should return .name and .pass', function () {
var creds = parse('basic OnBhc3M=');
assert.strictEqual(creds?.name, '');
assert.strictEqual(creds?.pass, 'pass');
});
});
describe('with empty userid and pass', function () {
it('should return .name and .pass', function () {
var creds = parse('basic Og==');
assert.strictEqual(creds?.name, '');
assert.strictEqual(creds?.pass, '');
});
});
describe('with colon in pass', function () {
it('should return .name and .pass', function () {
var creds = parse('basic Zm9vOnBhc3M6d29yZA==');
assert.strictEqual(creds?.name, 'foo');
assert.strictEqual(creds?.pass, 'pass:word');
});
});
describe('with scheme "Basic"', function () {
it('should return .name and .pass', function () {
var creds = parse('Basic Zm9vOmJhcg==');
assert.strictEqual(creds?.name, 'foo');
assert.strictEqual(creds?.pass, 'bar');
});
});
describe('with scheme "BASIC"', function () {
it('should return .name and .pass', function () {
var creds = parse('BASIC Zm9vOmJhcg==');
assert.strictEqual(creds?.name, 'foo');
assert.strictEqual(creds?.pass, 'bar');
});
});
describe('with scheme "BaSiC"', function () {
it('should return .name and .pass', function () {
var creds = parse('BaSiC Zm9vOmJhcg==');
assert.strictEqual(creds?.name, 'foo');
assert.strictEqual(creds?.pass, 'bar');
});
});
});