@verdaccio/proxy 6.0.0-6-next.20 → 6.0.0-6-next.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -0
- package/build/agent.d.ts +17 -0
- package/build/agent.js +63 -0
- package/build/agent.js.map +1 -0
- package/build/index.d.ts +1 -1
- package/build/index.js +4 -4
- package/build/index.js.map +1 -1
- package/build/proxy-utils.js.map +1 -1
- package/build/{up-storage.d.ts → proxy.d.ts} +28 -54
- package/build/proxy.js +565 -0
- package/build/proxy.js.map +1 -0
- package/jest.config.js +4 -5
- package/package.json +66 -67
- package/src/agent.ts +54 -0
- package/src/index.ts +1 -1
- package/src/{up-storage.ts → proxy.ts} +248 -352
- package/test/headers.auth.spec.ts +15 -18
- package/test/noProxy.spec.ts +215 -76
- package/test/partials/ssl-cert-snakeoil.key +15 -0
- package/test/partials/ssl-cert-snakeoil.pem +12 -0
- package/test/proxy.error.___.ts +126 -0
- package/test/proxy.metadata.spec.ts +354 -0
- package/test/proxy.search.spec.ts +1 -7
- package/test/proxy.tarball.spec.ts +142 -204
- package/tsconfig.json +0 -6
- package/build/up-storage.js +0 -691
- package/build/up-storage.js.map +0 -1
- package/test/proxy.error.spec.ts +0 -126
- package/test/proxy.metadata.ts +0 -133
|
@@ -3,9 +3,9 @@ import { HEADERS, TOKEN_BASIC, TOKEN_BEARER, constants } from '@verdaccio/core';
|
|
|
3
3
|
import { setup } from '@verdaccio/logger';
|
|
4
4
|
import { buildToken } from '@verdaccio/utils';
|
|
5
5
|
|
|
6
|
-
import { ProxyStorage } from '../src
|
|
6
|
+
import { ProxyStorage } from '../src';
|
|
7
7
|
|
|
8
|
-
setup(
|
|
8
|
+
setup();
|
|
9
9
|
|
|
10
10
|
function createUplink(config) {
|
|
11
11
|
const defaultConfig = {
|
|
@@ -16,17 +16,14 @@ function createUplink(config) {
|
|
|
16
16
|
return new ProxyStorage(mergeConfig, {});
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
function
|
|
19
|
+
function setHeadersNext(config: unknown = {}, headers: any = {}) {
|
|
20
20
|
const uplink = createUplink(config);
|
|
21
|
-
|
|
22
|
-
return uplink._setHeaders({
|
|
23
|
-
headers,
|
|
24
|
-
});
|
|
21
|
+
return uplink.getHeadersNext({ ...headers });
|
|
25
22
|
}
|
|
26
23
|
|
|
27
|
-
describe('
|
|
24
|
+
describe('setHeadersNext', () => {
|
|
28
25
|
test('if set headers empty should return default headers', () => {
|
|
29
|
-
const headers =
|
|
26
|
+
const headers = setHeadersNext();
|
|
30
27
|
const keys = Object.keys(headers);
|
|
31
28
|
const keysExpected = [HEADERS.ACCEPT, HEADERS.ACCEPT_ENCODING, HEADERS.USER_AGENT];
|
|
32
29
|
|
|
@@ -36,7 +33,7 @@ describe('uplink headers auth test', () => {
|
|
|
36
33
|
|
|
37
34
|
test('if assigns value invalid to attribute auth', () => {
|
|
38
35
|
const fnError = function () {
|
|
39
|
-
|
|
36
|
+
setHeadersNext({
|
|
40
37
|
auth: '',
|
|
41
38
|
});
|
|
42
39
|
};
|
|
@@ -47,7 +44,7 @@ describe('uplink headers auth test', () => {
|
|
|
47
44
|
});
|
|
48
45
|
|
|
49
46
|
test('if assigns the header authorization', () => {
|
|
50
|
-
const headers =
|
|
47
|
+
const headers = setHeadersNext(
|
|
51
48
|
{},
|
|
52
49
|
{
|
|
53
50
|
[HEADERS.AUTHORIZATION]: buildToken(TOKEN_BASIC, 'Zm9vX2Jhcg=='),
|
|
@@ -59,7 +56,7 @@ describe('uplink headers auth test', () => {
|
|
|
59
56
|
});
|
|
60
57
|
|
|
61
58
|
test('if assigns headers authorization and token the header precedes', () => {
|
|
62
|
-
const headers =
|
|
59
|
+
const headers = setHeadersNext(
|
|
63
60
|
{
|
|
64
61
|
auth: {
|
|
65
62
|
type: TOKEN_BEARER,
|
|
@@ -75,7 +72,7 @@ describe('uplink headers auth test', () => {
|
|
|
75
72
|
});
|
|
76
73
|
|
|
77
74
|
test('set type auth basic', () => {
|
|
78
|
-
const headers =
|
|
75
|
+
const headers = setHeadersNext({
|
|
79
76
|
auth: {
|
|
80
77
|
type: TOKEN_BASIC,
|
|
81
78
|
token: 'Zm9vX2Jhcg==',
|
|
@@ -87,7 +84,7 @@ describe('uplink headers auth test', () => {
|
|
|
87
84
|
});
|
|
88
85
|
|
|
89
86
|
test('set type auth bearer', () => {
|
|
90
|
-
const headers =
|
|
87
|
+
const headers = setHeadersNext({
|
|
91
88
|
auth: {
|
|
92
89
|
type: TOKEN_BEARER,
|
|
93
90
|
token: 'Zm9vX2Jhcf===',
|
|
@@ -100,7 +97,7 @@ describe('uplink headers auth test', () => {
|
|
|
100
97
|
|
|
101
98
|
test('set auth type invalid', () => {
|
|
102
99
|
const fnError = function () {
|
|
103
|
-
|
|
100
|
+
setHeadersNext({
|
|
104
101
|
auth: {
|
|
105
102
|
type: 'null',
|
|
106
103
|
token: 'Zm9vX2Jhcf===',
|
|
@@ -115,7 +112,7 @@ describe('uplink headers auth test', () => {
|
|
|
115
112
|
|
|
116
113
|
test('set auth with NPM_TOKEN', () => {
|
|
117
114
|
process.env.NPM_TOKEN = 'myToken';
|
|
118
|
-
const headers =
|
|
115
|
+
const headers = setHeadersNext({
|
|
119
116
|
auth: {
|
|
120
117
|
type: TOKEN_BEARER,
|
|
121
118
|
},
|
|
@@ -127,7 +124,7 @@ describe('uplink headers auth test', () => {
|
|
|
127
124
|
|
|
128
125
|
test('set auth with token name and assigns in env', () => {
|
|
129
126
|
process.env.NPM_TOKEN_TEST = 'myTokenTest';
|
|
130
|
-
const headers =
|
|
127
|
+
const headers = setHeadersNext({
|
|
131
128
|
auth: {
|
|
132
129
|
type: TOKEN_BASIC,
|
|
133
130
|
token_env: 'NPM_TOKEN_TEST',
|
|
@@ -140,7 +137,7 @@ describe('uplink headers auth test', () => {
|
|
|
140
137
|
|
|
141
138
|
test('if token not set', () => {
|
|
142
139
|
const fnError = function () {
|
|
143
|
-
|
|
140
|
+
setHeadersNext({
|
|
144
141
|
auth: {
|
|
145
142
|
type: TOKEN_BASIC,
|
|
146
143
|
},
|
package/test/noProxy.spec.ts
CHANGED
|
@@ -1,96 +1,235 @@
|
|
|
1
|
-
import { ProxyStorage } from '../src
|
|
1
|
+
import { ProxyStorage } from '../src';
|
|
2
2
|
|
|
3
3
|
require('@verdaccio/logger').setup([]);
|
|
4
4
|
|
|
5
|
-
function
|
|
5
|
+
function getProxyInstance(host, uplinkConf, appConfig) {
|
|
6
6
|
uplinkConf.url = host;
|
|
7
7
|
|
|
8
8
|
return new ProxyStorage(uplinkConf, appConfig);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
describe('Use proxy', () => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
describe('basic tets', () => {
|
|
13
|
+
test('should do not define proxy', () => {
|
|
14
|
+
const x = getProxyInstance('http://registry.domain.org', {}, {});
|
|
15
|
+
|
|
16
|
+
expect(x.proxy).toEqual(undefined);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('uplink configuration should take priority', () => {
|
|
20
|
+
expect(
|
|
21
|
+
getProxyInstance(
|
|
22
|
+
'http://registry.domain.org',
|
|
23
|
+
{ http_proxy: 'http:\\registry.local.org' },
|
|
24
|
+
{ http_proxy: 'registry.domain.org' }
|
|
25
|
+
).proxy
|
|
26
|
+
).toEqual('http:\\registry.local.org');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('global configuration should be used', () => {
|
|
30
|
+
expect(
|
|
31
|
+
getProxyInstance(
|
|
32
|
+
'http://registry.some.org',
|
|
33
|
+
{},
|
|
34
|
+
{ http_proxy: 'http://registry.domain.org' }
|
|
35
|
+
).proxy
|
|
36
|
+
).toEqual('http://registry.domain.org');
|
|
37
|
+
});
|
|
16
38
|
});
|
|
17
39
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
40
|
+
describe('no_proxy invalid cases', () => {
|
|
41
|
+
test('no_proxy is null', () => {
|
|
42
|
+
let x = getProxyInstance(
|
|
43
|
+
'http://x/x',
|
|
44
|
+
{ http_proxy: 'http:\\registry.local.org', no_proxy: null },
|
|
45
|
+
{}
|
|
46
|
+
);
|
|
47
|
+
expect(x.proxy).toEqual('http:\\registry.local.org');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('no_proxy is empty array', () => {
|
|
51
|
+
let x = getProxyInstance(
|
|
52
|
+
'http://x/x',
|
|
53
|
+
{ http_proxy: 'http:\\registry.local.org', no_proxy: [] },
|
|
54
|
+
{}
|
|
55
|
+
);
|
|
56
|
+
expect(x.proxy).toEqual('http:\\registry.local.org');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('no_proxy is empty object', () => {
|
|
60
|
+
let x = getProxyInstance(
|
|
61
|
+
'http://x/x',
|
|
62
|
+
{ http_proxy: 'http:\\registry.local.org', no_proxy: '' },
|
|
63
|
+
{}
|
|
64
|
+
);
|
|
65
|
+
expect(x.proxy).toEqual('http:\\registry.local.org');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('no_proxy - simple/include', () => {
|
|
69
|
+
let x = getProxyInstance(
|
|
70
|
+
'http://localhost',
|
|
71
|
+
{ http_proxy: 'http:\\registry.local.org' },
|
|
72
|
+
{ no_proxy: 'localhost' }
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
expect(x.proxy).toEqual(undefined);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('no_proxy - simple/not', () => {
|
|
79
|
+
let x = getProxyInstance(
|
|
80
|
+
'http://localhost',
|
|
81
|
+
{ http_proxy: 'http:\\registry.local.org' },
|
|
82
|
+
{ no_proxy: 'blah' }
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
expect(x.proxy).toEqual('http:\\registry.local.org');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('no_proxy is boolean', () => {
|
|
89
|
+
let x = getProxyInstance(
|
|
90
|
+
'http://registry.some.domain',
|
|
91
|
+
{ http_proxy: 'http:\\registry.local.org', no_proxy: false },
|
|
92
|
+
{}
|
|
93
|
+
);
|
|
94
|
+
expect(x.proxy).toEqual('http:\\registry.local.org');
|
|
95
|
+
});
|
|
21
96
|
});
|
|
22
97
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
98
|
+
describe('no_proxy override http_proxy use cases', () => {
|
|
99
|
+
test('no_proxy - various, single string', () => {
|
|
100
|
+
let x = getProxyInstance(
|
|
101
|
+
'http://blahblah',
|
|
102
|
+
{ http_proxy: 'http:\\registry.local.org' },
|
|
103
|
+
{ no_proxy: 'blah' }
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
expect(x.proxy).toEqual('http:\\registry.local.org');
|
|
107
|
+
});
|
|
108
|
+
test('should disable proxy if match hostname', () => {
|
|
109
|
+
let x = getProxyInstance(
|
|
110
|
+
'http://registry.local.org',
|
|
111
|
+
{},
|
|
112
|
+
{ http_proxy: 'http:\\registry.local.org', no_proxy: 'registry.local.org' }
|
|
113
|
+
);
|
|
114
|
+
expect(x.proxy).toEqual(undefined);
|
|
115
|
+
});
|
|
116
|
+
test('should not override http_proxy if domain does not match', () => {
|
|
117
|
+
let x = getProxyInstance(
|
|
118
|
+
'http://blahblah',
|
|
119
|
+
{},
|
|
120
|
+
{ http_proxy: 'http://registry.local.org', no_proxy: '.blah' }
|
|
121
|
+
);
|
|
122
|
+
expect(x.proxy).toEqual('http://registry.local.org');
|
|
123
|
+
});
|
|
124
|
+
test('should override http_proxy if match domain no_proxy', () => {
|
|
125
|
+
let x = getProxyInstance('http://blah.blah', { http_proxy: '123', no_proxy: '.blah' }, {});
|
|
126
|
+
expect(x.proxy).toEqual(undefined);
|
|
127
|
+
});
|
|
128
|
+
test('should override http_proxy due no_proxy match with hostname', () => {
|
|
129
|
+
let x = getProxyInstance('http://blah', { http_proxy: '123', no_proxy: '.blah' }, {});
|
|
130
|
+
expect(x.proxy).toEqual(undefined);
|
|
131
|
+
});
|
|
132
|
+
test('should not override http_proxy if no_proxy does not match', () => {
|
|
133
|
+
let x = getProxyInstance(
|
|
134
|
+
'http://blahh',
|
|
135
|
+
{ http_proxy: 'http://registry.local.org', no_proxy: 'blah' },
|
|
136
|
+
{}
|
|
137
|
+
);
|
|
138
|
+
expect(x.proxy).toEqual('http://registry.local.org');
|
|
139
|
+
});
|
|
33
140
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
141
|
+
describe('no_proxy as array of domains', () => {
|
|
142
|
+
test('should not override http_proxy if not match domain', () => {
|
|
143
|
+
let x = getProxyInstance(
|
|
144
|
+
'http://blahblah',
|
|
145
|
+
{ http_proxy: 'http:\\registry.local.org' },
|
|
146
|
+
{ no_proxy: 'foo,bar,blah' }
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
expect(x.proxy).toEqual('http:\\registry.local.org');
|
|
150
|
+
});
|
|
151
|
+
test('should disable proxy if match domain', () => {
|
|
152
|
+
let x = getProxyInstance(
|
|
153
|
+
'http://blah.blah',
|
|
154
|
+
{ http_proxy: 'http:\\registry.local.org' },
|
|
155
|
+
{ no_proxy: 'foo,bar,blah' }
|
|
156
|
+
);
|
|
157
|
+
expect(x.proxy).toEqual(undefined);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test('disable proxy if match domain .foo', () => {
|
|
161
|
+
let x = getProxyInstance(
|
|
162
|
+
'http://blah.foo',
|
|
163
|
+
{ http_proxy: 'http:\\registry.local.org' },
|
|
164
|
+
{ no_proxy: 'foo,bar,blah' }
|
|
165
|
+
);
|
|
166
|
+
expect(x.proxy).toEqual(undefined);
|
|
167
|
+
});
|
|
168
|
+
test('should not disable http_proxy if not match domain', () => {
|
|
169
|
+
let x = getProxyInstance(
|
|
170
|
+
'http://foo.baz',
|
|
171
|
+
{ http_proxy: 'http:\\registry.local.org' },
|
|
172
|
+
{ no_proxy: 'foo,bar,blah' }
|
|
173
|
+
);
|
|
174
|
+
expect(x.proxy).toEqual('http:\\registry.local.org');
|
|
175
|
+
});
|
|
176
|
+
test('no_proxy should not find match no_proxy as array invalid domains', () => {
|
|
177
|
+
let x = getProxyInstance(
|
|
178
|
+
'http://blahblah',
|
|
179
|
+
{ http_proxy: 'http:\\registry.local.org' },
|
|
180
|
+
{ no_proxy: ['foo', 'bar', 'blah'] }
|
|
181
|
+
);
|
|
182
|
+
expect(x.proxy).toEqual('http:\\registry.local.org');
|
|
183
|
+
});
|
|
184
|
+
test('no_proxy should find match no_proxy as array valid domains', () => {
|
|
185
|
+
let x = getProxyInstance(
|
|
186
|
+
'http://blah.blah',
|
|
187
|
+
{ http_proxy: 'http:\\registry.local.org' },
|
|
188
|
+
{ no_proxy: ['foo', 'bar', 'blah'] }
|
|
189
|
+
);
|
|
190
|
+
expect(x.proxy).toEqual(undefined);
|
|
191
|
+
});
|
|
45
192
|
});
|
|
46
193
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
194
|
+
describe('no_proxy with ports', () => {
|
|
195
|
+
test('no_proxy - hostport', () => {
|
|
196
|
+
let x = getProxyInstance(
|
|
197
|
+
'http://localhost:80',
|
|
198
|
+
{ http_proxy: '123' },
|
|
199
|
+
{ no_proxy: 'localhost' }
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
expect(x.proxy).toEqual(undefined);
|
|
203
|
+
x = getProxyInstance(
|
|
204
|
+
'http://localhost:8080',
|
|
205
|
+
{ http_proxy: '123' },
|
|
206
|
+
{ no_proxy: 'localhost' }
|
|
207
|
+
);
|
|
208
|
+
expect(x.proxy).toEqual(undefined);
|
|
209
|
+
});
|
|
61
210
|
});
|
|
62
211
|
|
|
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
|
-
test('no_proxy - secure', () => {
|
|
88
|
-
let x = setupProxy('https://something', { http_proxy: '123' }, {});
|
|
89
|
-
|
|
90
|
-
expect(x.proxy).toEqual(undefined);
|
|
91
|
-
x = setupProxy('https://something', { https_proxy: '123' }, {});
|
|
92
|
-
expect(x.proxy).toEqual('123');
|
|
93
|
-
x = setupProxy('https://something', { http_proxy: '456', https_proxy: '123' }, {});
|
|
94
|
-
expect(x.proxy).toEqual('123');
|
|
212
|
+
describe('no_proxy with https match', () => {
|
|
213
|
+
test('should not override if https_proxy is defined', () => {
|
|
214
|
+
let x = getProxyInstance('https://something', { http_proxy: '123' }, {});
|
|
215
|
+
|
|
216
|
+
expect(x.proxy).toEqual(undefined);
|
|
217
|
+
});
|
|
218
|
+
test('should define proxy if https_proxy match', () => {
|
|
219
|
+
let x = getProxyInstance(
|
|
220
|
+
'https://something',
|
|
221
|
+
{ https_proxy: 'https://registry.local.org' },
|
|
222
|
+
{}
|
|
223
|
+
);
|
|
224
|
+
expect(x.proxy).toEqual('https://registry.local.org');
|
|
225
|
+
});
|
|
226
|
+
test('should match https_proxy if https protocol match', () => {
|
|
227
|
+
let x = getProxyInstance(
|
|
228
|
+
'https://something',
|
|
229
|
+
{ http_proxy: 'http://registry.local.org', https_proxy: 'https://registry.local.org' },
|
|
230
|
+
{}
|
|
231
|
+
);
|
|
232
|
+
expect(x.proxy).toEqual('https://registry.local.org');
|
|
233
|
+
});
|
|
95
234
|
});
|
|
96
235
|
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
-----BEGIN RSA PRIVATE KEY-----
|
|
2
|
+
MIICWwIBAAKBgQCzURxIqzer0ACAbX/lHdsn4Gd9PLKrf7EeDYfIdV0HZKPD8WDr
|
|
3
|
+
bBx2/fBu0OW2sjnzv/SVZbJ0DAuPE/p0+eT0qb2qC10iz9iTD7ribd7gxhirVb8y
|
|
4
|
+
b3fBjXsxc8V8p4Ny1LcvNSqCjwUbJqdRogfoJeTiqPM58z5sNzuv5iq7iwIDAQAB
|
|
5
|
+
AoGAPMQy4olrP0UotlzlJ36bowLP70ffgHCwU+/f4NWs5fF78c3du0oSx1w820Dd
|
|
6
|
+
Z7E0JF8bgnlJJTxjumPZz0RUCugrEHBKJmzEz3cxF5E3+7NvteZcjKn9D67RrM5x
|
|
7
|
+
1/uSZ9cqKE9cYvY4fSuHx18diyZ4axR/wB1Pea2utjjDM+ECQQDb9ZbmmaWMiRpQ
|
|
8
|
+
5Up+loxP7BZNPsEVsm+DVJmEFbaFgGfncWBqSIqnPNjMwTwj0OigTwCAEGPkfRVW
|
|
9
|
+
T0pbYWCxAkEA0LK7SCTwzyDmhASUalk0x+3uCAA6ryFdwJf/wd8TRAvVOmkTEldX
|
|
10
|
+
uJ7ldLvfrONYO3v56uKTU/SoNdZYzKtO+wJAX2KM4ctXYy5BXztPpr2acz4qHa1N
|
|
11
|
+
Bh+vBAC34fOYhyQ76r3b1btHhWZ5jbFuZwm9F2erC94Ps5IaoqcX07DSwQJAPKGw
|
|
12
|
+
h2U0EPkd/3zVIZCJJQya+vgWFIs9EZcXVtvYXQyTBkVApTN66MhBIYjzkub5205J
|
|
13
|
+
bVQmOV37AKklY1DhwQJAA1wos0cYxro02edzatxd0DIR2r4qqOqLkw6BhYHhq6HJ
|
|
14
|
+
ZvIcQkHqdSXzdETFc01I1znDGGIrJHcnvKWgBPoEUg==
|
|
15
|
+
-----END RSA PRIVATE KEY-----
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
|
2
|
+
MIIB1TCCAT4CCQDV5mPlzm9+izANBgkqhkiG9w0BAQUFADAvMS0wKwYDVQQDEyQ3
|
|
3
|
+
NTI3YmQ3Ny1hYjNlLTQ3NGItYWNlNy1lZWQ2MDUzOTMxZTcwHhcNMTUwNzA2MjI0
|
|
4
|
+
NTA3WhcNMjUwNzAzMjI0NTA3WjAvMS0wKwYDVQQDEyQ3NTI3YmQ3Ny1hYjNlLTQ3
|
|
5
|
+
NGItYWNlNy1lZWQ2MDUzOTMxZTcwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGB
|
|
6
|
+
ALNRHEirN6vQAIBtf+Ud2yfgZ308sqt/sR4Nh8h1XQdko8PxYOtsHHb98G7Q5bay
|
|
7
|
+
OfO/9JVlsnQMC48T+nT55PSpvaoLXSLP2JMPuuJt3uDGGKtVvzJvd8GNezFzxXyn
|
|
8
|
+
g3LUty81KoKPBRsmp1GiB+gl5OKo8znzPmw3O6/mKruLAgMBAAEwDQYJKoZIhvcN
|
|
9
|
+
AQEFBQADgYEACzoHUF8UV2Z6541Q2wKEA0UFUzmUjf/E1XwBO+1P15ZZ64uw34B4
|
|
10
|
+
1RwMPtAo9RY/PmICTWtNxWGxkzwb2JtDWtnxVER/lF8k2XcXPE76fxTHJF/BKk9J
|
|
11
|
+
QU8OTD1dd9gHCBviQB9TqntRZ5X7axjtuWjb2umY+owBYzAHZkp1HKI=
|
|
12
|
+
-----END CERTIFICATE-----
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// import nock from 'nock';
|
|
2
|
+
// import path from 'path';
|
|
3
|
+
|
|
4
|
+
// import { Config, parseConfigFile } from '@verdaccio/config';
|
|
5
|
+
// import { API_ERROR, HEADER_TYPE, HTTP_STATUS, VerdaccioError, errorUtils } from '@verdaccio/core';
|
|
6
|
+
|
|
7
|
+
// import { ProxyStorage } from '../src';
|
|
8
|
+
|
|
9
|
+
// const getConf = (name) => path.join(__dirname, '/conf', name);
|
|
10
|
+
|
|
11
|
+
// const mockDebug = jest.fn();
|
|
12
|
+
// const mockInfo = jest.fn();
|
|
13
|
+
// const mockHttp = jest.fn();
|
|
14
|
+
// const mockError = jest.fn();
|
|
15
|
+
// const mockWarn = jest.fn();
|
|
16
|
+
// jest.mock('@verdaccio/logger', () => {
|
|
17
|
+
// const originalLogger = jest.requireActual('@verdaccio/logger');
|
|
18
|
+
// return {
|
|
19
|
+
// ...originalLogger,
|
|
20
|
+
// logger: {
|
|
21
|
+
// child: () => ({
|
|
22
|
+
// debug: (arg) => mockDebug(arg),
|
|
23
|
+
// info: (arg) => mockInfo(arg),
|
|
24
|
+
// http: (arg) => mockHttp(arg),
|
|
25
|
+
// error: (arg) => mockError(arg),
|
|
26
|
+
// warn: (arg) => mockWarn(arg),
|
|
27
|
+
// }),
|
|
28
|
+
// },
|
|
29
|
+
// };
|
|
30
|
+
// });
|
|
31
|
+
|
|
32
|
+
// const domain = 'https://registry.npmjs.org';
|
|
33
|
+
|
|
34
|
+
// describe('proxy', () => {
|
|
35
|
+
// beforeEach(() => {
|
|
36
|
+
// nock.cleanAll();
|
|
37
|
+
// });
|
|
38
|
+
// const defaultRequestOptions = {
|
|
39
|
+
// url: 'https://registry.npmjs.org',
|
|
40
|
+
// };
|
|
41
|
+
// const proxyPath = getConf('proxy1.yaml');
|
|
42
|
+
// const conf = new Config(parseConfigFile(proxyPath));
|
|
43
|
+
|
|
44
|
+
// describe('error handling', () => {
|
|
45
|
+
// test('should be offline uplink', (done) => {
|
|
46
|
+
// const tarball = 'https://registry.npmjs.org/jquery/-/jquery-0.0.1.tgz';
|
|
47
|
+
// nock(domain).get('/jquery/-/jquery-0.0.1.tgz').times(100).replyWithError('some error');
|
|
48
|
+
// const proxy = new ProxyStorage(defaultRequestOptions, conf);
|
|
49
|
+
// const stream = proxy.fetchTarball(tarball);
|
|
50
|
+
// // to test a uplink is offline we have to be try 3 times
|
|
51
|
+
// // the default failed request are set to 2
|
|
52
|
+
// process.nextTick(function () {
|
|
53
|
+
// stream.on('error', function (err) {
|
|
54
|
+
// expect(err).not.toBeNull();
|
|
55
|
+
// // expect(err.statusCode).toBe(404);
|
|
56
|
+
// expect(proxy.failed_requests).toBe(1);
|
|
57
|
+
|
|
58
|
+
// const streamSecondTry = proxy.fetchTarball(tarball);
|
|
59
|
+
// streamSecondTry.on('error', function (err) {
|
|
60
|
+
// expect(err).not.toBeNull();
|
|
61
|
+
// /*
|
|
62
|
+
// code: 'ENOTFOUND',
|
|
63
|
+
// errno: 'ENOTFOUND',
|
|
64
|
+
// */
|
|
65
|
+
// // expect(err.statusCode).toBe(404);
|
|
66
|
+
// expect(proxy.failed_requests).toBe(2);
|
|
67
|
+
// const streamThirdTry = proxy.fetchTarball(tarball);
|
|
68
|
+
// streamThirdTry.on('error', function (err: VerdaccioError) {
|
|
69
|
+
// expect(err).not.toBeNull();
|
|
70
|
+
// expect(err.statusCode).toBe(HTTP_STATUS.INTERNAL_ERROR);
|
|
71
|
+
// expect(proxy.failed_requests).toBe(2);
|
|
72
|
+
// expect(err.message).toMatch(API_ERROR.UPLINK_OFFLINE);
|
|
73
|
+
// done();
|
|
74
|
+
// });
|
|
75
|
+
// });
|
|
76
|
+
// });
|
|
77
|
+
// });
|
|
78
|
+
// });
|
|
79
|
+
|
|
80
|
+
// test('not found tarball', (done) => {
|
|
81
|
+
// nock(domain).get('/jquery/-/jquery-0.0.1.tgz').reply(404);
|
|
82
|
+
// const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
83
|
+
// const stream = prox1.fetchTarball('https://registry.npmjs.org/jquery/-/jquery-0.0.1.tgz');
|
|
84
|
+
// stream.on('error', (response) => {
|
|
85
|
+
// expect(response).toEqual(errorUtils.getNotFound(API_ERROR.NOT_FILE_UPLINK));
|
|
86
|
+
// done();
|
|
87
|
+
// });
|
|
88
|
+
// });
|
|
89
|
+
|
|
90
|
+
// test('fail tarball request', (done) => {
|
|
91
|
+
// nock(domain).get('/jquery/-/jquery-0.0.1.tgz').replyWithError('boom file');
|
|
92
|
+
// const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
93
|
+
// const stream = prox1.fetchTarball('https://registry.npmjs.org/jquery/-/jquery-0.0.1.tgz');
|
|
94
|
+
// stream.on('error', (response) => {
|
|
95
|
+
// expect(response).toEqual(Error('boom file'));
|
|
96
|
+
// done();
|
|
97
|
+
// });
|
|
98
|
+
// });
|
|
99
|
+
|
|
100
|
+
// test('bad uplink request', (done) => {
|
|
101
|
+
// nock(domain).get('/jquery/-/jquery-0.0.1.tgz').reply(409);
|
|
102
|
+
// const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
103
|
+
// const stream = prox1.fetchTarball('https://registry.npmjs.org/jquery/-/jquery-0.0.1.tgz');
|
|
104
|
+
// stream.on('error', (response) => {
|
|
105
|
+
// expect(response).toEqual(errorUtils.getInternalError(`bad uplink status code: 409`));
|
|
106
|
+
// done();
|
|
107
|
+
// });
|
|
108
|
+
// });
|
|
109
|
+
|
|
110
|
+
// test('content length header mismatch', (done) => {
|
|
111
|
+
// nock(domain)
|
|
112
|
+
// .get('/jquery/-/jquery-0.0.1.tgz')
|
|
113
|
+
// // types does not match here with documentation
|
|
114
|
+
// // @ts-expect-error
|
|
115
|
+
// .replyWithFile(201, path.join(__dirname, 'partials/jquery-0.0.1.tgz'), {
|
|
116
|
+
// [HEADER_TYPE.CONTENT_LENGTH]: 0,
|
|
117
|
+
// });
|
|
118
|
+
// const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
119
|
+
// const stream = prox1.fetchTarball('https://registry.npmjs.org/jquery/-/jquery-0.0.1.tgz');
|
|
120
|
+
// stream.on('error', (response) => {
|
|
121
|
+
// expect(response).toEqual(errorUtils.getInternalError(API_ERROR.CONTENT_MISMATCH));
|
|
122
|
+
// done();
|
|
123
|
+
// });
|
|
124
|
+
// });
|
|
125
|
+
// });
|
|
126
|
+
// });
|