@verdaccio/api 6.0.0-6-next.23 → 6.0.0-6-next.26
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 +124 -0
- package/build/dist-tags.js +40 -35
- package/build/dist-tags.js.map +1 -1
- package/build/index.js +1 -7
- package/build/index.js.map +1 -1
- package/build/package.js +33 -28
- package/build/package.js.map +1 -1
- package/build/ping.js.map +1 -1
- package/build/publish.d.ts +79 -22
- package/build/publish.js +89 -313
- package/build/publish.js.map +1 -1
- package/build/search.js.map +1 -1
- package/build/star.js +53 -54
- package/build/star.js.map +1 -1
- package/build/stars.js +6 -6
- package/build/stars.js.map +1 -1
- package/build/user.js +19 -1
- package/build/user.js.map +1 -1
- package/build/v1/profile.js.map +1 -1
- package/build/v1/search.js +2 -4
- package/build/v1/search.js.map +1 -1
- package/build/v1/token.js.map +1 -1
- package/build/whoami.js +11 -25
- package/build/whoami.js.map +1 -1
- package/jest.config.js +8 -1
- package/package.json +71 -69
- package/src/dist-tags.ts +63 -50
- package/src/index.ts +1 -6
- package/src/package.ts +35 -44
- package/src/publish.ts +115 -336
- package/src/star.ts +53 -52
- package/src/stars.ts +9 -11
- package/src/user.ts +19 -2
- package/src/v1/search.ts +3 -3
- package/src/whoami.ts +8 -24
- package/test/integration/_helper.ts +97 -53
- package/test/integration/config/distTag.yaml +25 -0
- package/test/integration/config/package.yaml +4 -9
- package/test/integration/config/ping.yaml +3 -7
- package/test/integration/config/publish.yaml +5 -11
- package/test/integration/config/search.yaml +29 -0
- package/test/integration/config/token.jwt.yaml +27 -0
- package/test/integration/config/token.yaml +19 -0
- package/test/integration/config/user.jwt.yaml +37 -0
- package/test/integration/config/user.yaml +9 -15
- package/test/integration/config/whoami.yaml +5 -12
- package/test/integration/distTag.spec.ts +76 -0
- package/test/integration/package.spec.ts +33 -76
- package/test/integration/ping.spec.ts +4 -3
- package/test/integration/publish.spec.ts +61 -26
- package/test/integration/search.spec.ts +126 -0
- package/test/integration/token.spec.ts +124 -0
- package/test/integration/user.jwt.spec.ts +87 -0
- package/test/integration/user.spec.ts +1 -0
- package/test/integration/whoami.spec.ts +21 -39
- package/test/unit/publish.disabled.ts +252 -0
- package/tsconfig.json +1 -1
- package/__mocks__/@verdaccio/logger/index.js +0 -21
- package/build/utils.d.ts +0 -7
- package/build/utils.js +0 -36
- package/build/utils.js.map +0 -1
- package/src/utils.ts +0 -25
- package/test/unit/__snapshots__/publish.spec.ts.snap +0 -49
- package/test/unit/publish.spec.ts +0 -300
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
import { API_ERROR, HTTP_STATUS, errorUtils } from '@verdaccio/core';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
addVersion,
|
|
5
|
-
publishPackage,
|
|
6
|
-
removeTarball,
|
|
7
|
-
unPublishPackage,
|
|
8
|
-
uploadPackageTarball,
|
|
9
|
-
} from '../../src/publish';
|
|
10
|
-
|
|
11
|
-
const REVISION_MOCK = '15-e53a77096b0ee33e';
|
|
12
|
-
|
|
13
|
-
require('@verdaccio/logger').setup([{ type: 'stdout', format: 'pretty', level: 'info' }]);
|
|
14
|
-
|
|
15
|
-
describe('Publish endpoints - add a tag', () => {
|
|
16
|
-
let req;
|
|
17
|
-
let res;
|
|
18
|
-
let next;
|
|
19
|
-
|
|
20
|
-
beforeEach(() => {
|
|
21
|
-
req = {
|
|
22
|
-
params: {
|
|
23
|
-
version: '1.0.0',
|
|
24
|
-
tag: 'tag',
|
|
25
|
-
package: 'verdaccio',
|
|
26
|
-
},
|
|
27
|
-
body: '',
|
|
28
|
-
};
|
|
29
|
-
res = {
|
|
30
|
-
status: jest.fn(),
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
next = jest.fn();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test('should add a version', (done) => {
|
|
37
|
-
const storage = {
|
|
38
|
-
addVersion: (packageName, version, body, tag, cb) => {
|
|
39
|
-
expect(packageName).toEqual(req.params.package);
|
|
40
|
-
expect(version).toEqual(req.params.version);
|
|
41
|
-
expect(body).toEqual(req.body);
|
|
42
|
-
expect(tag).toEqual(req.params.tag);
|
|
43
|
-
cb();
|
|
44
|
-
done();
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
// @ts-ignore
|
|
49
|
-
addVersion(storage)(req, res, next);
|
|
50
|
-
|
|
51
|
-
expect(res.status).toHaveBeenLastCalledWith(HTTP_STATUS.CREATED);
|
|
52
|
-
expect(next).toHaveBeenLastCalledWith({ ok: 'package published' });
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test('when failed to add a version', (done) => {
|
|
56
|
-
const storage = {
|
|
57
|
-
addVersion: (packageName, version, body, tag, cb) => {
|
|
58
|
-
const error = {
|
|
59
|
-
message: 'failure',
|
|
60
|
-
};
|
|
61
|
-
cb(error);
|
|
62
|
-
done();
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
// @ts-ignore
|
|
67
|
-
addVersion(storage)(req, res, next);
|
|
68
|
-
|
|
69
|
-
expect(next).toHaveBeenLastCalledWith({ message: 'failure' });
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* upload package: '/:package/-/:filename/*'
|
|
75
|
-
*/
|
|
76
|
-
describe('Publish endpoints - upload package tarball', () => {
|
|
77
|
-
let req;
|
|
78
|
-
let res;
|
|
79
|
-
let next;
|
|
80
|
-
|
|
81
|
-
beforeEach(() => {
|
|
82
|
-
req = {
|
|
83
|
-
params: {
|
|
84
|
-
filename: 'verdaccio.gzip',
|
|
85
|
-
package: 'verdaccio',
|
|
86
|
-
},
|
|
87
|
-
pipe: jest.fn(),
|
|
88
|
-
on: jest.fn(),
|
|
89
|
-
};
|
|
90
|
-
res = { status: jest.fn(), locals: { report_error: jest.fn() } };
|
|
91
|
-
next = jest.fn();
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
test('should upload package tarball successfully', () => {
|
|
95
|
-
const stream = {
|
|
96
|
-
done: jest.fn(),
|
|
97
|
-
abort: jest.fn(),
|
|
98
|
-
on: jest.fn(() => (status, cb) => cb()),
|
|
99
|
-
};
|
|
100
|
-
const storage = {
|
|
101
|
-
addTarball(packageName, filename) {
|
|
102
|
-
expect(packageName).toEqual(req.params.package);
|
|
103
|
-
expect(filename).toEqual(req.params.filename);
|
|
104
|
-
return stream;
|
|
105
|
-
},
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
// @ts-ignore
|
|
109
|
-
uploadPackageTarball(storage)(req, res, next);
|
|
110
|
-
expect(req.pipe).toHaveBeenCalled();
|
|
111
|
-
expect(req.on).toHaveBeenCalled();
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Delete tarball: '/:package/-/:filename/-rev/:revision'
|
|
117
|
-
*/
|
|
118
|
-
describe('Publish endpoints - delete tarball', () => {
|
|
119
|
-
let req;
|
|
120
|
-
let res;
|
|
121
|
-
let next;
|
|
122
|
-
|
|
123
|
-
beforeEach(() => {
|
|
124
|
-
req = {
|
|
125
|
-
params: {
|
|
126
|
-
filename: 'verdaccio.gzip',
|
|
127
|
-
package: 'verdaccio',
|
|
128
|
-
revision: REVISION_MOCK,
|
|
129
|
-
},
|
|
130
|
-
};
|
|
131
|
-
res = { status: jest.fn() };
|
|
132
|
-
next = jest.fn();
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
test('should delete tarball successfully', (done) => {
|
|
136
|
-
const storage = {
|
|
137
|
-
removeTarball(packageName, filename, revision, cb) {
|
|
138
|
-
expect(packageName).toEqual(req.params.package);
|
|
139
|
-
expect(filename).toEqual(req.params.filename);
|
|
140
|
-
expect(revision).toEqual(req.params.revision);
|
|
141
|
-
cb();
|
|
142
|
-
done();
|
|
143
|
-
},
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
// @ts-ignore
|
|
147
|
-
removeTarball(storage)(req, res, next);
|
|
148
|
-
expect(res.status).toHaveBeenCalledWith(HTTP_STATUS.CREATED);
|
|
149
|
-
expect(next).toHaveBeenCalledWith({ ok: 'tarball removed' });
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
test('failed while deleting the tarball', (done) => {
|
|
153
|
-
const error = {
|
|
154
|
-
message: 'deletion failed',
|
|
155
|
-
};
|
|
156
|
-
const storage = {
|
|
157
|
-
removeTarball(packageName, filename, revision, cb) {
|
|
158
|
-
cb(error);
|
|
159
|
-
done();
|
|
160
|
-
},
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
// @ts-ignore
|
|
164
|
-
removeTarball(storage)(req, res, next);
|
|
165
|
-
expect(next).toHaveBeenCalledWith(error);
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Un-publish package: '/:package/-rev/*'
|
|
171
|
-
*/
|
|
172
|
-
describe('Publish endpoints - un-publish package', () => {
|
|
173
|
-
let req;
|
|
174
|
-
let res;
|
|
175
|
-
let next;
|
|
176
|
-
|
|
177
|
-
beforeEach(() => {
|
|
178
|
-
req = {
|
|
179
|
-
params: {
|
|
180
|
-
package: 'verdaccio',
|
|
181
|
-
},
|
|
182
|
-
};
|
|
183
|
-
res = { status: jest.fn() };
|
|
184
|
-
next = jest.fn();
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
test('should un-publish package successfully', async () => {
|
|
188
|
-
const storage = {
|
|
189
|
-
removePackage(packageName) {
|
|
190
|
-
expect(packageName).toEqual(req.params.package);
|
|
191
|
-
return Promise.resolve();
|
|
192
|
-
},
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
// @ts-ignore
|
|
196
|
-
await unPublishPackage(storage)(req, res, next);
|
|
197
|
-
expect(res.status).toHaveBeenCalledWith(HTTP_STATUS.CREATED);
|
|
198
|
-
expect(next).toHaveBeenCalledWith({ ok: 'package removed' });
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
test('un-publish failed', async () => {
|
|
202
|
-
const storage = {
|
|
203
|
-
removePackage(packageName) {
|
|
204
|
-
expect(packageName).toEqual(req.params.package);
|
|
205
|
-
return Promise.reject(errorUtils.getInternalError());
|
|
206
|
-
},
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
// @ts-ignore
|
|
210
|
-
await unPublishPackage(storage)(req, res, next);
|
|
211
|
-
expect(next).toHaveBeenCalledWith(errorUtils.getInternalError());
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Publish package: '/:package/:_rev?/:revision?'
|
|
217
|
-
*/
|
|
218
|
-
describe('Publish endpoints - publish package', () => {
|
|
219
|
-
let req;
|
|
220
|
-
let res;
|
|
221
|
-
let next;
|
|
222
|
-
|
|
223
|
-
beforeEach(() => {
|
|
224
|
-
req = {
|
|
225
|
-
body: {
|
|
226
|
-
name: 'verdaccio',
|
|
227
|
-
},
|
|
228
|
-
params: {
|
|
229
|
-
package: 'verdaccio',
|
|
230
|
-
},
|
|
231
|
-
};
|
|
232
|
-
res = { status: jest.fn() };
|
|
233
|
-
next = jest.fn();
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
test('should change the existing package', () => {
|
|
237
|
-
const storage = {
|
|
238
|
-
changePackage: jest.fn(),
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
req.params._rev = REVISION_MOCK;
|
|
242
|
-
|
|
243
|
-
// @ts-ignore
|
|
244
|
-
publishPackage(storage)(req, res, next);
|
|
245
|
-
expect(storage.changePackage).toMatchSnapshot();
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
test('should publish a new a new package', () => {
|
|
249
|
-
const storage = {
|
|
250
|
-
addPackage: jest.fn(),
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
// @ts-ignore
|
|
254
|
-
publishPackage(storage)(req, res, next);
|
|
255
|
-
expect(storage.addPackage).toMatchSnapshot();
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
test('should throw an error while publishing package', () => {
|
|
259
|
-
const storage = {
|
|
260
|
-
addPackage() {
|
|
261
|
-
throw new Error();
|
|
262
|
-
},
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
// @ts-ignore
|
|
266
|
-
publishPackage(storage)(req, res, next);
|
|
267
|
-
expect(next).toHaveBeenCalledWith(new Error(API_ERROR.BAD_PACKAGE_DATA));
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
describe('test start', () => {
|
|
271
|
-
test('should star a package', () => {
|
|
272
|
-
const storage = {
|
|
273
|
-
changePackage: jest.fn(),
|
|
274
|
-
getPackage({ callback }) {
|
|
275
|
-
callback(null, {
|
|
276
|
-
users: {},
|
|
277
|
-
});
|
|
278
|
-
},
|
|
279
|
-
};
|
|
280
|
-
req = {
|
|
281
|
-
params: {
|
|
282
|
-
package: 'verdaccio',
|
|
283
|
-
},
|
|
284
|
-
body: {
|
|
285
|
-
_rev: REVISION_MOCK,
|
|
286
|
-
users: {
|
|
287
|
-
verdaccio: true,
|
|
288
|
-
},
|
|
289
|
-
},
|
|
290
|
-
remote_user: {
|
|
291
|
-
name: 'verdaccio',
|
|
292
|
-
},
|
|
293
|
-
};
|
|
294
|
-
|
|
295
|
-
// @ts-ignore
|
|
296
|
-
publishPackage(storage)(req, res, next);
|
|
297
|
-
expect(storage.changePackage).toMatchSnapshot();
|
|
298
|
-
});
|
|
299
|
-
});
|
|
300
|
-
});
|