@verdaccio/proxy 6.0.0-6-next.52 → 6.0.0-6-next.53
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 +14 -0
- package/build/agent.d.ts +1 -1
- package/build/agent.js.map +1 -1
- package/build/proxy.d.ts +12 -13
- package/build/proxy.js +49 -41
- package/build/proxy.js.map +1 -1
- package/package.json +9 -12
- package/src/agent.ts +1 -1
- package/src/proxy.ts +60 -47
- package/test/headers.auth.spec.ts +16 -4
- package/test/noProxy.spec.ts +4 -2
- package/test/proxy.metadata.spec.ts +147 -31
- package/test/proxy.search.spec.ts +37 -53
- package/test/proxy.tarball.spec.ts +2 -2
|
@@ -2,37 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
/* global AbortController */
|
|
4
4
|
import getStream from 'get-stream';
|
|
5
|
+
import nock from 'nock';
|
|
5
6
|
import path from 'path';
|
|
6
|
-
import { MockAgent, setGlobalDispatcher } from 'undici';
|
|
7
7
|
|
|
8
8
|
import { Config, parseConfigFile } from '@verdaccio/config';
|
|
9
9
|
import { streamUtils } from '@verdaccio/core';
|
|
10
|
+
import { Logger } from '@verdaccio/types';
|
|
10
11
|
|
|
11
12
|
import { ProxyStorage } from '../src';
|
|
12
13
|
|
|
13
14
|
const getConf = (name) => path.join(__dirname, '/conf', name);
|
|
14
15
|
|
|
15
|
-
// TODO: we can mock this globally maybe
|
|
16
16
|
const mockDebug = jest.fn();
|
|
17
17
|
const mockInfo = jest.fn();
|
|
18
18
|
const mockHttp = jest.fn();
|
|
19
19
|
const mockError = jest.fn();
|
|
20
20
|
const mockWarn = jest.fn();
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
http: (arg) => mockHttp(arg),
|
|
30
|
-
error: (arg) => mockError(arg),
|
|
31
|
-
warn: (arg) => mockWarn(arg),
|
|
32
|
-
}),
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
});
|
|
21
|
+
|
|
22
|
+
const logger = {
|
|
23
|
+
debug: mockDebug,
|
|
24
|
+
info: mockInfo,
|
|
25
|
+
http: mockHttp,
|
|
26
|
+
error: mockError,
|
|
27
|
+
warn: mockWarn,
|
|
28
|
+
} as unknown as Logger;
|
|
36
29
|
|
|
37
30
|
const domain = 'https://registry.npmjs.org';
|
|
38
31
|
|
|
@@ -44,20 +37,13 @@ describe('proxy', () => {
|
|
|
44
37
|
const proxyPath = getConf('proxy1.yaml');
|
|
45
38
|
const conf = new Config(parseConfigFile(proxyPath));
|
|
46
39
|
|
|
47
|
-
const options = {
|
|
48
|
-
path: '/-/v1/search?maintenance=1&popularity=1&quality=1&size=10&text=verdaccio',
|
|
49
|
-
method: 'GET',
|
|
50
|
-
};
|
|
51
|
-
|
|
52
40
|
describe('search', () => {
|
|
53
41
|
test('get response from endpoint', async () => {
|
|
54
42
|
const response = require('./partials/search-v1.json');
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
mockClient.intercept(options).reply(200, JSON.stringify(response));
|
|
60
|
-
const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
43
|
+
nock(domain)
|
|
44
|
+
.get('/-/v1/search?maintenance=1&popularity=1&quality=1&size=10&text=verdaccio')
|
|
45
|
+
.reply(200, response);
|
|
46
|
+
const prox1 = new ProxyStorage(defaultRequestOptions, conf, logger);
|
|
61
47
|
const abort = new AbortController();
|
|
62
48
|
const stream = await prox1.search({
|
|
63
49
|
abort,
|
|
@@ -69,13 +55,11 @@ describe('proxy', () => {
|
|
|
69
55
|
});
|
|
70
56
|
|
|
71
57
|
test('handle bad response 409', async () => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const mockClient = mockAgent.get(domain);
|
|
76
|
-
mockClient.intercept(options).reply(409, {});
|
|
58
|
+
nock(domain)
|
|
59
|
+
.get('/-/v1/search?maintenance=1&popularity=1&quality=1&size=10&text=verdaccio')
|
|
60
|
+
.reply(409);
|
|
77
61
|
const abort = new AbortController();
|
|
78
|
-
const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
62
|
+
const prox1 = new ProxyStorage(defaultRequestOptions, conf, logger);
|
|
79
63
|
await expect(
|
|
80
64
|
prox1.search({
|
|
81
65
|
abort,
|
|
@@ -84,26 +68,26 @@ describe('proxy', () => {
|
|
|
84
68
|
).rejects.toThrow('bad status code 409 from uplink');
|
|
85
69
|
});
|
|
86
70
|
|
|
87
|
-
test.todo('abort search from endpoint');
|
|
71
|
+
// test.todo('abort search from endpoint');
|
|
88
72
|
|
|
89
|
-
// TODO: we should test the gzip deflate here, but is hard to test
|
|
90
|
-
// fix me if you can deal with Incorrect Header Check issue
|
|
91
|
-
test.todo('get file from endpoint with gzip headers');
|
|
73
|
+
// // TODO: we should test the gzip deflate here, but is hard to test
|
|
74
|
+
// // fix me if you can deal with Incorrect Header Check issue
|
|
75
|
+
// test.todo('get file from endpoint with gzip headers');
|
|
92
76
|
|
|
93
|
-
test('search endpoint fails', async () => {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
});
|
|
77
|
+
// test('search endpoint fails', async () => {
|
|
78
|
+
// const mockAgent = new MockAgent({ connections: 1 });
|
|
79
|
+
// mockAgent.disableNetConnect();
|
|
80
|
+
// setGlobalDispatcher(mockAgent);
|
|
81
|
+
// const mockClient = mockAgent.get(domain);
|
|
82
|
+
// mockClient.intercept(options).reply(500, {});
|
|
83
|
+
// const abort = new AbortController();
|
|
84
|
+
// const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
85
|
+
// await expect(
|
|
86
|
+
// prox1.search({
|
|
87
|
+
// abort,
|
|
88
|
+
// url: queryUrl,
|
|
89
|
+
// })
|
|
90
|
+
// ).rejects.toThrow('bad status code 500 from uplink');
|
|
91
|
+
// });
|
|
108
92
|
});
|
|
109
93
|
});
|
|
@@ -2,7 +2,7 @@ import nock from 'nock';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
|
|
4
4
|
import { Config, parseConfigFile } from '@verdaccio/config';
|
|
5
|
-
import { setup } from '@verdaccio/logger';
|
|
5
|
+
import { logger, setup } from '@verdaccio/logger';
|
|
6
6
|
|
|
7
7
|
import { ProxyStorage } from '../src';
|
|
8
8
|
|
|
@@ -44,7 +44,7 @@ describe('tarball proxy', () => {
|
|
|
44
44
|
nock('https://registry.verdaccio.org')
|
|
45
45
|
.get('/jquery/-/jquery-0.0.1.tgz')
|
|
46
46
|
.replyWithFile(201, path.join(__dirname, 'partials/jquery-0.0.1.tgz'));
|
|
47
|
-
const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
47
|
+
const prox1 = new ProxyStorage(defaultRequestOptions, conf, logger);
|
|
48
48
|
const stream = prox1.fetchTarball(
|
|
49
49
|
'https://registry.verdaccio.org/jquery/-/jquery-0.0.1.tgz',
|
|
50
50
|
{}
|