/
auth.spec.ts
107 lines (100 loc) · 3.36 KB
/
auth.spec.ts
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
99
100
101
102
103
104
105
106
107
import { getGitAuthenticatedEnvironmentVariables } from './auth';
describe('util/git/auth', () => {
afterEach(() => {
delete process.env.GIT_CONFIG_COUNT;
});
describe('getGitAuthenticatedEnvironmentVariables()', () => {
it('returns url with token', () => {
expect(
getGitAuthenticatedEnvironmentVariables(
'https://github.com/',
'token1234'
)
).toStrictEqual({
GIT_CONFIG_KEY_0: 'url.https://token1234@github.com/.insteadOf',
GIT_CONFIG_VALUE_0: 'https://github.com/',
GIT_CONFIG_COUNT: '1',
});
});
it('returns correct url if token already contains GitHub App username', () => {
expect(
getGitAuthenticatedEnvironmentVariables(
'https://github.com/',
'x-access-token:token1234'
)
).toStrictEqual({
GIT_CONFIG_KEY_0:
'url.https://x-access-token:token1234@github.com/.insteadOf',
GIT_CONFIG_VALUE_0: 'https://github.com/',
GIT_CONFIG_COUNT: '1',
});
});
it('returns url with token and already existing GIT_CONFIG_COUNT from parameter', () => {
expect(
getGitAuthenticatedEnvironmentVariables(
'https://github.com/',
'token1234',
{ GIT_CONFIG_COUNT: '1' }
)
).toStrictEqual({
GIT_CONFIG_KEY_1: 'url.https://token1234@github.com/.insteadOf',
GIT_CONFIG_VALUE_1: 'https://github.com/',
GIT_CONFIG_COUNT: '2',
});
});
it('returns url with token and already existing GIT_CONFIG_COUNT from parameter over environment', () => {
process.env.GIT_CONFIG_COUNT = '54';
expect(
getGitAuthenticatedEnvironmentVariables(
'https://github.com/',
'token1234',
{ GIT_CONFIG_COUNT: '1' }
)
).toStrictEqual({
GIT_CONFIG_KEY_1: 'url.https://token1234@github.com/.insteadOf',
GIT_CONFIG_VALUE_1: 'https://github.com/',
GIT_CONFIG_COUNT: '2',
});
});
it('returns url with token and already existing GIT_CONFIG_COUNT from environment', () => {
process.env.GIT_CONFIG_COUNT = '1';
expect(
getGitAuthenticatedEnvironmentVariables(
'https://github.com/',
'token1234'
)
).toStrictEqual({
GIT_CONFIG_KEY_1: 'url.https://token1234@github.com/.insteadOf',
GIT_CONFIG_VALUE_1: 'https://github.com/',
GIT_CONFIG_COUNT: '2',
});
});
it('returns url with token and passthrough existing variables', () => {
expect(
getGitAuthenticatedEnvironmentVariables(
'https://github.com/',
'token1234',
{ RANDOM_VARIABLE: 'random' }
)
).toStrictEqual({
GIT_CONFIG_KEY_0: 'url.https://token1234@github.com/.insteadOf',
GIT_CONFIG_VALUE_0: 'https://github.com/',
GIT_CONFIG_COUNT: '1',
RANDOM_VARIABLE: 'random',
});
});
it('return url with token with invalid GIT_CONFIG_COUNT from environment', () => {
process.env.GIT_CONFIG_COUNT = 'notvalid';
expect(
getGitAuthenticatedEnvironmentVariables(
'https://github.com/',
'token1234'
)
).toStrictEqual({
GIT_CONFIG_KEY_0: 'url.https://token1234@github.com/.insteadOf',
GIT_CONFIG_VALUE_0: 'https://github.com/',
GIT_CONFIG_COUNT: '1',
});
});
});
});