@verdaccio/proxy 8.0.0-next-8.12 → 8.0.0-next-8.13
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/README.md +30 -24
- package/build/proxy.d.ts +9 -5
- package/build/proxy.js +23 -27
- package/build/proxy.js.map +1 -1
- package/build/uplink-util.js +5 -9
- package/build/uplink-util.js.map +1 -1
- package/package.json +12 -8
- package/.babelrc +0 -3
- package/CHANGELOG.md +0 -1390
- package/src/agent.ts +0 -50
- package/src/index.ts +0 -2
- package/src/proxy-utils.ts +0 -41
- package/src/proxy.ts +0 -650
- package/src/uplink-util.ts +0 -42
- package/test/conf/proxy1.yaml +0 -31
- package/test/headers.auth.spec.ts +0 -165
- package/test/noProxy.spec.ts +0 -239
- package/test/partials/jquery-0.0.1.tgz +0 -0
- package/test/partials/search-v1.json +0 -157
- package/test/partials/ssl-cert-snakeoil.key +0 -15
- package/test/partials/ssl-cert-snakeoil.pem +0 -12
- package/test/proxy-utils.spec.ts +0 -36
- package/test/proxy.error.___.ts +0 -126
- package/test/proxy.metadata.spec.ts +0 -451
- package/test/proxy.protocol.spec.ts +0 -87
- package/test/proxy.search.spec.ts +0 -110
- package/test/proxy.tarball.spec.ts +0 -183
- package/tsconfig.build.json +0 -9
- package/tsconfig.json +0 -23
- package/types/patch.d.ts +0 -10
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2
|
-
|
|
3
|
-
/* global AbortController */
|
|
4
|
-
import getStream from 'get-stream';
|
|
5
|
-
import nock from 'nock';
|
|
6
|
-
import path from 'path';
|
|
7
|
-
import { describe, expect, test, vi } from 'vitest';
|
|
8
|
-
|
|
9
|
-
import { Config, parseConfigFile } from '@verdaccio/config';
|
|
10
|
-
import { streamUtils } from '@verdaccio/core';
|
|
11
|
-
import { Logger } from '@verdaccio/types';
|
|
12
|
-
|
|
13
|
-
import { ProxyStorage } from '../src';
|
|
14
|
-
|
|
15
|
-
const getConf = (name) => path.join(__dirname, '/conf', name);
|
|
16
|
-
|
|
17
|
-
const mockDebug = vi.fn();
|
|
18
|
-
const mockInfo = vi.fn();
|
|
19
|
-
const mockHttp = vi.fn();
|
|
20
|
-
const mockError = vi.fn();
|
|
21
|
-
const mockWarn = vi.fn();
|
|
22
|
-
|
|
23
|
-
const logger = {
|
|
24
|
-
debug: mockDebug,
|
|
25
|
-
info: mockInfo,
|
|
26
|
-
http: mockHttp,
|
|
27
|
-
error: mockError,
|
|
28
|
-
warn: mockWarn,
|
|
29
|
-
} as unknown as Logger;
|
|
30
|
-
|
|
31
|
-
const domain = 'https://registry.npmjs.org';
|
|
32
|
-
|
|
33
|
-
describe('proxy', () => {
|
|
34
|
-
const queryUrl = '/-/v1/search?maintenance=1&popularity=1&quality=1&size=10&text=verdaccio';
|
|
35
|
-
const defaultRequestOptions = {
|
|
36
|
-
url: domain,
|
|
37
|
-
};
|
|
38
|
-
const proxyPath = getConf('proxy1.yaml');
|
|
39
|
-
const conf = new Config(parseConfigFile(proxyPath));
|
|
40
|
-
|
|
41
|
-
describe('search', () => {
|
|
42
|
-
test('get response from endpoint', async () => {
|
|
43
|
-
const response = require('./partials/search-v1.json');
|
|
44
|
-
nock(domain)
|
|
45
|
-
.get('/-/v1/search?maintenance=1&popularity=1&quality=1&size=10&text=verdaccio')
|
|
46
|
-
.reply(200, response);
|
|
47
|
-
const prox1 = new ProxyStorage(defaultRequestOptions, conf, logger);
|
|
48
|
-
const abort = new AbortController();
|
|
49
|
-
const stream = await prox1.search({
|
|
50
|
-
abort,
|
|
51
|
-
url: queryUrl,
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
const searchResponse = await getStream(stream.pipe(streamUtils.transformObjectToString()));
|
|
55
|
-
expect(searchResponse).toEqual(searchResponse);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test('get response from uplink with trailing slash', async () => {
|
|
59
|
-
const response = require('./partials/search-v1.json');
|
|
60
|
-
nock(domain + '/')
|
|
61
|
-
.get('/-/v1/search?maintenance=1&popularity=1&quality=1&size=10&text=verdaccio')
|
|
62
|
-
.reply(200, response);
|
|
63
|
-
const prox1 = new ProxyStorage(defaultRequestOptions, conf, logger);
|
|
64
|
-
const abort = new AbortController();
|
|
65
|
-
const stream = await prox1.search({
|
|
66
|
-
abort,
|
|
67
|
-
url: queryUrl,
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
const searchResponse = await getStream(stream.pipe(streamUtils.transformObjectToString()));
|
|
71
|
-
expect(searchResponse).toEqual(searchResponse);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
test('handle bad response 409', async () => {
|
|
75
|
-
nock(domain)
|
|
76
|
-
.get('/-/v1/search?maintenance=1&popularity=1&quality=1&size=10&text=verdaccio')
|
|
77
|
-
.reply(409);
|
|
78
|
-
const abort = new AbortController();
|
|
79
|
-
const prox1 = new ProxyStorage(defaultRequestOptions, conf, logger);
|
|
80
|
-
await expect(
|
|
81
|
-
prox1.search({
|
|
82
|
-
abort,
|
|
83
|
-
url: queryUrl,
|
|
84
|
-
})
|
|
85
|
-
).rejects.toThrow('bad status code 409 from uplink');
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
// test.todo('abort search from endpoint');
|
|
89
|
-
|
|
90
|
-
// // TODO: we should test the gzip deflate here, but is hard to test
|
|
91
|
-
// // fix me if you can deal with Incorrect Header Check issue
|
|
92
|
-
// test.todo('get file from endpoint with gzip headers');
|
|
93
|
-
|
|
94
|
-
// test('search endpoint fails', async () => {
|
|
95
|
-
// const mockAgent = new MockAgent({ connections: 1 });
|
|
96
|
-
// mockAgent.disableNetConnect();
|
|
97
|
-
// setGlobalDispatcher(mockAgent);
|
|
98
|
-
// const mockClient = mockAgent.get(domain);
|
|
99
|
-
// mockClient.intercept(options).reply(500, {});
|
|
100
|
-
// const abort = new AbortController();
|
|
101
|
-
// const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
102
|
-
// await expect(
|
|
103
|
-
// prox1.search({
|
|
104
|
-
// abort,
|
|
105
|
-
// url: queryUrl,
|
|
106
|
-
// })
|
|
107
|
-
// ).rejects.toThrow('bad status code 500 from uplink');
|
|
108
|
-
// });
|
|
109
|
-
});
|
|
110
|
-
});
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import nock from 'nock';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { beforeEach, describe, test, vi } from 'vitest';
|
|
4
|
-
|
|
5
|
-
import { Config, parseConfigFile } from '@verdaccio/config';
|
|
6
|
-
import { logger, setup } from '@verdaccio/logger';
|
|
7
|
-
|
|
8
|
-
import { ProxyStorage } from '../src';
|
|
9
|
-
|
|
10
|
-
setup({});
|
|
11
|
-
|
|
12
|
-
const getConf = (name) => path.join(__dirname, '/conf', name);
|
|
13
|
-
|
|
14
|
-
// // mock to get the headers fixed value
|
|
15
|
-
vi.mock('crypto', () => {
|
|
16
|
-
return {
|
|
17
|
-
randomBytes: (): { toString: () => string } => {
|
|
18
|
-
return {
|
|
19
|
-
toString: (): string => 'foo-random-bytes',
|
|
20
|
-
};
|
|
21
|
-
},
|
|
22
|
-
pseudoRandomBytes: (): { toString: () => string } => {
|
|
23
|
-
return {
|
|
24
|
-
toString: (): string => 'foo-phseudo-bytes',
|
|
25
|
-
};
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe('tarball proxy', () => {
|
|
31
|
-
beforeEach(() => {
|
|
32
|
-
nock.cleanAll();
|
|
33
|
-
nock.abortPendingRequests();
|
|
34
|
-
vi.clearAllMocks();
|
|
35
|
-
});
|
|
36
|
-
const defaultRequestOptions = {
|
|
37
|
-
url: 'https://registry.verdaccio.org',
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const proxyPath = getConf('proxy1.yaml');
|
|
41
|
-
const conf = new Config(parseConfigFile(proxyPath));
|
|
42
|
-
|
|
43
|
-
describe('fetchTarball', () => {
|
|
44
|
-
test('get file tarball fetch', () =>
|
|
45
|
-
new Promise((done) => {
|
|
46
|
-
nock('https://registry.verdaccio.org')
|
|
47
|
-
.get('/jquery/-/jquery-0.0.1.tgz')
|
|
48
|
-
.replyWithFile(201, path.join(__dirname, 'partials/jquery-0.0.1.tgz'));
|
|
49
|
-
const prox1 = new ProxyStorage(defaultRequestOptions, conf, logger);
|
|
50
|
-
const stream = prox1.fetchTarball(
|
|
51
|
-
'https://registry.verdaccio.org/jquery/-/jquery-0.0.1.tgz',
|
|
52
|
-
// @ts-expect-error
|
|
53
|
-
{}
|
|
54
|
-
);
|
|
55
|
-
stream.on('response', () => {
|
|
56
|
-
done(true);
|
|
57
|
-
});
|
|
58
|
-
stream.on('error', (err) => {
|
|
59
|
-
done(err);
|
|
60
|
-
});
|
|
61
|
-
}));
|
|
62
|
-
|
|
63
|
-
test.skip('get file tarball handle retries', () =>
|
|
64
|
-
new Promise((done) => {
|
|
65
|
-
nock('https://registry.verdaccio.org')
|
|
66
|
-
.get('/jquery/-/jquery-0.0.1.tgz')
|
|
67
|
-
.twice()
|
|
68
|
-
.reply(500, 'some-text')
|
|
69
|
-
.get('/jquery/-/jquery-0.0.1.tgz')
|
|
70
|
-
.once()
|
|
71
|
-
.replyWithFile(201, path.join(__dirname, 'partials/jquery-0.0.1.tgz'));
|
|
72
|
-
const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
73
|
-
const stream = prox1.fetchTarball(
|
|
74
|
-
'https://registry.verdaccio.org/jquery/-/jquery-0.0.1.tgz',
|
|
75
|
-
{ retry: { limit: 2 } }
|
|
76
|
-
);
|
|
77
|
-
stream.on('error', () => {
|
|
78
|
-
// FIXME: stream should have handle 2 retry
|
|
79
|
-
done();
|
|
80
|
-
});
|
|
81
|
-
}));
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
// test('get file tarball correct content-length', (done) => {
|
|
85
|
-
// nock(domain)
|
|
86
|
-
// .get('/jquery/-/jquery-0.0.1.tgz')
|
|
87
|
-
// // types does not match here with documentation
|
|
88
|
-
// // @ts-expect-error
|
|
89
|
-
// .replyWithFile(201, path.join(__dirname, 'partials/jquery-0.0.1.tgz'), {
|
|
90
|
-
// [HEADER_TYPE.CONTENT_LENGTH]: 277,
|
|
91
|
-
// });
|
|
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(HEADER_TYPE.CONTENT_LENGTH, (data) => {
|
|
95
|
-
// expect(data).toEqual('277');
|
|
96
|
-
// done();
|
|
97
|
-
// });
|
|
98
|
-
// });
|
|
99
|
-
|
|
100
|
-
// describe('error handling', () => {
|
|
101
|
-
// test('should be offline uplink', (done) => {
|
|
102
|
-
// const tarball = 'https://registry.npmjs.org/jquery/-/jquery-0.0.1.tgz';
|
|
103
|
-
// nock(domain).get('/jquery/-/jquery-0.0.1.tgz').times(100).replyWithError('some error');
|
|
104
|
-
// const proxy = new ProxyStorage(defaultRequestOptions, conf);
|
|
105
|
-
// const stream = proxy.fetchTarball(tarball);
|
|
106
|
-
// // to test a uplink is offline we have to be try 3 times
|
|
107
|
-
// // the default failed request are set to 2
|
|
108
|
-
// process.nextTick(function () {
|
|
109
|
-
// stream.on('error', function (err) {
|
|
110
|
-
// expect(err).not.toBeNull();
|
|
111
|
-
// // expect(err.statusCode).toBe(404);
|
|
112
|
-
// expect(proxy.failed_requests).toBe(1);
|
|
113
|
-
|
|
114
|
-
// const streamSecondTry = proxy.fetchTarball(tarball);
|
|
115
|
-
// streamSecondTry.on('error', function (err) {
|
|
116
|
-
// expect(err).not.toBeNull();
|
|
117
|
-
// /*
|
|
118
|
-
// code: 'ENOTFOUND',
|
|
119
|
-
// errno: 'ENOTFOUND',
|
|
120
|
-
// */
|
|
121
|
-
// // expect(err.statusCode).toBe(404);
|
|
122
|
-
// expect(proxy.failed_requests).toBe(2);
|
|
123
|
-
// const streamThirdTry = proxy.fetchTarball(tarball);
|
|
124
|
-
// streamThirdTry.on('error', function (err: VerdaccioError) {
|
|
125
|
-
// expect(err).not.toBeNull();
|
|
126
|
-
// expect(err.statusCode).toBe(HTTP_STATUS.INTERNAL_ERROR);
|
|
127
|
-
// expect(proxy.failed_requests).toBe(2);
|
|
128
|
-
// expect(err.message).toMatch(API_ERROR.UPLINK_OFFLINE);
|
|
129
|
-
// done();
|
|
130
|
-
// });
|
|
131
|
-
// });
|
|
132
|
-
// });
|
|
133
|
-
// });
|
|
134
|
-
// });
|
|
135
|
-
|
|
136
|
-
// test('not found tarball', (done) => {
|
|
137
|
-
// nock(domain).get('/jquery/-/jquery-0.0.1.tgz').reply(404);
|
|
138
|
-
// const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
139
|
-
// const stream = prox1.fetchTarball('https://registry.npmjs.org/jquery/-/jquery-0.0.1.tgz');
|
|
140
|
-
// stream.on('error', (response) => {
|
|
141
|
-
// expect(response).toEqual(errorUtils.getNotFound(API_ERROR.NOT_FILE_UPLINK));
|
|
142
|
-
// done();
|
|
143
|
-
// });
|
|
144
|
-
// });
|
|
145
|
-
|
|
146
|
-
// test('fail tarball request', (done) => {
|
|
147
|
-
// nock(domain).get('/jquery/-/jquery-0.0.1.tgz').replyWithError('boom file');
|
|
148
|
-
// const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
149
|
-
// const stream = prox1.fetchTarball('https://registry.npmjs.org/jquery/-/jquery-0.0.1.tgz');
|
|
150
|
-
// stream.on('error', (response) => {
|
|
151
|
-
// expect(response).toEqual(Error('boom file'));
|
|
152
|
-
// done();
|
|
153
|
-
// });
|
|
154
|
-
// });
|
|
155
|
-
|
|
156
|
-
// test('bad uplink request', (done) => {
|
|
157
|
-
// nock(domain).get('/jquery/-/jquery-0.0.1.tgz').reply(409);
|
|
158
|
-
// const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
159
|
-
// const stream = prox1.fetchTarball('https://registry.npmjs.org/jquery/-/jquery-0.0.1.tgz');
|
|
160
|
-
// stream.on('error', (response) => {
|
|
161
|
-
// expect(response).toEqual(errorUtils.getInternalError(`bad uplink status code: 409`));
|
|
162
|
-
// done();
|
|
163
|
-
// });
|
|
164
|
-
// });
|
|
165
|
-
|
|
166
|
-
// test('content length header mismatch', (done) => {
|
|
167
|
-
// nock(domain)
|
|
168
|
-
// .get('/jquery/-/jquery-0.0.1.tgz')
|
|
169
|
-
// // types does not match here with documentation
|
|
170
|
-
// // @ts-expect-error
|
|
171
|
-
// .replyWithFile(201, path.join(__dirname, 'partials/jquery-0.0.1.tgz'), {
|
|
172
|
-
// [HEADER_TYPE.CONTENT_LENGTH]: 0,
|
|
173
|
-
// });
|
|
174
|
-
// const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
175
|
-
// const stream = prox1.fetchTarball('https://registry.npmjs.org/jquery/-/jquery-0.0.1.tgz');
|
|
176
|
-
// stream.on('error', (response) => {
|
|
177
|
-
// expect(response).toEqual(errorUtils.getInternalError(API_ERROR.CONTENT_MISMATCH));
|
|
178
|
-
// done();
|
|
179
|
-
// });
|
|
180
|
-
// });
|
|
181
|
-
// });
|
|
182
|
-
// });
|
|
183
|
-
// });
|
package/tsconfig.build.json
DELETED
package/tsconfig.json
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.reference.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"rootDir": "./src",
|
|
5
|
-
"outDir": "./build",
|
|
6
|
-
"noImplicitAny": false
|
|
7
|
-
},
|
|
8
|
-
"include": ["src/**/*.ts", "types/*.d.ts"],
|
|
9
|
-
"references": [
|
|
10
|
-
{
|
|
11
|
-
"path": "../config"
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
"path": "../core/core"
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
"path": "../logger/logger"
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
"path": "../utils"
|
|
21
|
-
}
|
|
22
|
-
]
|
|
23
|
-
}
|
package/types/patch.d.ts
DELETED