@verdaccio/api 8.1.0-next-8.12 → 8.1.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.
Files changed (49) hide show
  1. package/README.md +17 -10
  2. package/package.json +16 -12
  3. package/.babelrc +0 -3
  4. package/.eslintrc +0 -5
  5. package/CHANGELOG.md +0 -2152
  6. package/src/dist-tags.ts +0 -106
  7. package/src/index.ts +0 -65
  8. package/src/package.ts +0 -117
  9. package/src/ping.ts +0 -14
  10. package/src/publish.ts +0 -262
  11. package/src/search.ts +0 -12
  12. package/src/stars.ts +0 -37
  13. package/src/user.ts +0 -179
  14. package/src/v1/profile.ts +0 -113
  15. package/src/v1/search.ts +0 -85
  16. package/src/v1/token.ts +0 -157
  17. package/src/whoami.ts +0 -26
  18. package/test/.eslintrc +0 -8
  19. package/test/integration/_helper.ts +0 -198
  20. package/test/integration/config/distTag.yaml +0 -25
  21. package/test/integration/config/owner.yaml +0 -24
  22. package/test/integration/config/package.yaml +0 -25
  23. package/test/integration/config/ping.yaml +0 -26
  24. package/test/integration/config/profile.yaml +0 -27
  25. package/test/integration/config/publish-proxy.yaml +0 -26
  26. package/test/integration/config/publish.yaml +0 -24
  27. package/test/integration/config/search.yaml +0 -29
  28. package/test/integration/config/star.yaml +0 -26
  29. package/test/integration/config/token.jwt.yaml +0 -27
  30. package/test/integration/config/token.yaml +0 -19
  31. package/test/integration/config/user.jwt.yaml +0 -37
  32. package/test/integration/config/user.yaml +0 -30
  33. package/test/integration/config/whoami.yaml +0 -29
  34. package/test/integration/distTag.spec.ts +0 -80
  35. package/test/integration/owner.spec.ts +0 -119
  36. package/test/integration/package.spec.ts +0 -107
  37. package/test/integration/ping.spec.ts +0 -18
  38. package/test/integration/profile.spec.ts +0 -112
  39. package/test/integration/publish.spec.ts +0 -232
  40. package/test/integration/search.spec.ts +0 -139
  41. package/test/integration/star.spec.ts +0 -74
  42. package/test/integration/token.spec.ts +0 -125
  43. package/test/integration/user.spec.ts +0 -222
  44. package/test/integration/whoami.spec.ts +0 -36
  45. package/test/unit/publish.disabled.ts +0 -252
  46. package/test/unit/validate.api.params.middleware.spec.ts +0 -44
  47. package/tsconfig.build.json +0 -9
  48. package/tsconfig.json +0 -41
  49. package/types/custom.d.ts +0 -16
@@ -1,119 +0,0 @@
1
- /* eslint-disable jest/no-commented-out-tests */
2
- import nock from 'nock';
3
- import { describe, expect, test } from 'vitest';
4
-
5
- import { HTTP_STATUS } from '@verdaccio/core';
6
-
7
- import {
8
- changeOwners,
9
- createUser,
10
- getPackage,
11
- initializeServer,
12
- publishVersionWithToken,
13
- } from './_helper';
14
-
15
- describe('owner', () => {
16
- test.each([['foo', '@scope%2Ffoo']])('should get owner of package', async (pkgName) => {
17
- nock('https://registry.npmjs.org').get(`/${pkgName}`).reply(404);
18
- const app = await initializeServer('owner.yaml');
19
- const credentials = { name: 'test', password: 'test' };
20
- const response = await createUser(app, credentials.name, credentials.password);
21
- expect(response.body.ok).toMatch(`user '${credentials.name}' created`);
22
- await publishVersionWithToken(app, pkgName, '1.0.0', response.body.token).expect(
23
- HTTP_STATUS.CREATED
24
- );
25
-
26
- // expect publish to set owner to logged in user
27
- const manifest = await getPackage(app, '', decodeURIComponent(pkgName));
28
- const maintainers = manifest.body.maintainers;
29
- expect(maintainers).toHaveLength(1);
30
- // TODO: This should eventually include the email of the user
31
- expect(maintainers).toEqual([{ name: credentials.name, email: '' }]);
32
- });
33
-
34
- test.each([['foo', '@scope%2Ffoo']])('should add/remove owner to package', async (pkgName) => {
35
- nock('https://registry.npmjs.org').get(`/${pkgName}`).reply(404);
36
- const app = await initializeServer('owner.yaml');
37
- const credentials = { name: 'test', password: 'test' };
38
- const firstOwner = { name: 'test', email: '' };
39
- const response = await createUser(app, credentials.name, credentials.password);
40
- expect(response.body.ok).toMatch(`user '${credentials.name}' created`);
41
- await publishVersionWithToken(app, pkgName, '1.0.0', response.body.token).expect(
42
- HTTP_STATUS.CREATED
43
- );
44
-
45
- // publish sets owner to logged in user
46
- const manifest = await getPackage(app, '', decodeURIComponent(pkgName));
47
- const maintainers = manifest.body.maintainers;
48
- expect(maintainers).toHaveLength(1);
49
- expect(maintainers).toEqual([firstOwner]);
50
-
51
- // add another owner
52
- const secondOwner = { name: 'tester', email: 'test@verdaccio.org' };
53
- const newOwners = [...maintainers, secondOwner];
54
- await changeOwners(
55
- app,
56
- {
57
- _rev: manifest.body._rev,
58
- _id: manifest.body._id,
59
- name: pkgName,
60
- maintainers: newOwners,
61
- },
62
- response.body.token
63
- ).expect(HTTP_STATUS.CREATED);
64
-
65
- const manifest2 = await getPackage(app, '', decodeURIComponent(pkgName));
66
- const maintainers2 = manifest2.body.maintainers;
67
- expect(maintainers2).toHaveLength(2);
68
- expect(maintainers2).toEqual([firstOwner, secondOwner]);
69
-
70
- // remove original owner
71
- await changeOwners(
72
- app,
73
- {
74
- _rev: manifest2.body._rev,
75
- _id: manifest2.body._id,
76
- name: pkgName,
77
- maintainers: [secondOwner],
78
- },
79
- response.body.token
80
- ).expect(HTTP_STATUS.CREATED);
81
-
82
- const manifest3 = await getPackage(app, '', decodeURIComponent(pkgName));
83
- const maintainers3 = manifest3.body.maintainers;
84
- expect(maintainers3).toHaveLength(1);
85
- expect(maintainers3).toEqual([secondOwner]);
86
- });
87
-
88
- test.each([['foo', '@scope%2Ffoo']])('should fail if user is not logged in', async (pkgName) => {
89
- nock('https://registry.npmjs.org').get(`/${pkgName}`).reply(404);
90
- const app = await initializeServer('owner.yaml');
91
- const credentials = { name: 'test', password: 'test' };
92
- const firstOwner = { name: 'test', email: '' };
93
- const response = await createUser(app, credentials.name, credentials.password);
94
- expect(response.body.ok).toMatch(`user '${credentials.name}' created`);
95
- await publishVersionWithToken(app, pkgName, '1.0.0', response.body.token).expect(
96
- HTTP_STATUS.CREATED
97
- );
98
-
99
- // publish sets owner to logged in user
100
- const manifest = await getPackage(app, '', decodeURIComponent(pkgName));
101
- const maintainers = manifest.body.maintainers;
102
- expect(maintainers).toHaveLength(1);
103
- expect(maintainers).toEqual([firstOwner]);
104
-
105
- // try adding another owner
106
- const secondOwner = { name: 'tester', email: 'test@verdaccio.org' };
107
- const newOwners = [...maintainers, secondOwner];
108
- await changeOwners(
109
- app,
110
- {
111
- _rev: manifest.body._rev,
112
- _id: manifest.body._id,
113
- name: pkgName,
114
- maintainers: newOwners,
115
- },
116
- '' // no token
117
- ).expect(HTTP_STATUS.UNAUTHORIZED);
118
- });
119
- });
@@ -1,107 +0,0 @@
1
- import supertest from 'supertest';
2
- import { beforeEach, describe, expect, test } from 'vitest';
3
-
4
- import { DIST_TAGS, HEADERS, HEADER_TYPE, HTTP_STATUS } from '@verdaccio/core';
5
- import { Storage } from '@verdaccio/store';
6
-
7
- import { initializeServer, publishVersion } from './_helper';
8
-
9
- describe('package', () => {
10
- describe('get tarball', () => {
11
- let app;
12
- beforeEach(async () => {
13
- app = await initializeServer('package.yaml');
14
- });
15
-
16
- test.each([
17
- ['foo', 'foo-1.0.0.tgz'],
18
- ['@scope/foo', 'foo-1.0.0.tgz'],
19
- ])('should return a file tarball', async (pkg, fileName) => {
20
- await publishVersion(app, pkg, '1.0.0');
21
- const response = await supertest(app)
22
- .get(`/${pkg}/-/${fileName}`)
23
- .set(HEADERS.ACCEPT, HEADERS.JSON)
24
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.OCTET_STREAM)
25
- .expect(HTTP_STATUS.OK);
26
- expect(Buffer.from(response.body).toString('utf8')).toBeDefined();
27
- });
28
-
29
- test.each([
30
- ['foo2', 'foo2-1.0.0.tgz'],
31
- ['@scope/foo2', 'foo2-1.0.0.tgz'],
32
- ])('should fails if tarball does not exist', async (pkg, fileName) => {
33
- await publishVersion(app, pkg, '1.0.1');
34
- await supertest(app)
35
- .get(`/${pkg}/-/${fileName}`)
36
- .set(HEADERS.ACCEPT, HEADERS.JSON)
37
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.OCTET_STREAM)
38
- .expect(HTTP_STATUS.NOT_FOUND);
39
- });
40
-
41
- test.todo('check content length file header');
42
- test.todo('fails on file was aborted');
43
- });
44
-
45
- describe('get package', () => {
46
- let app;
47
- beforeEach(async () => {
48
- app = await initializeServer('package.yaml');
49
- });
50
-
51
- test.each([['foo'], ['@scope/foo']])('should return a foo private package', async (pkg) => {
52
- await publishVersion(app, pkg, '1.0.0');
53
- const response = await supertest(app)
54
- .get(`/${pkg}`)
55
- .set(HEADERS.ACCEPT, HEADERS.JSON)
56
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
57
- .expect(HTTP_STATUS.OK);
58
- expect(response.body.name).toEqual(pkg);
59
- });
60
-
61
- test.each([['foo'], ['@scope/foo']])(
62
- 'should return a foo private package by version',
63
- async (pkg) => {
64
- await publishVersion(app, pkg, '1.0.0');
65
- const response = await supertest(app)
66
- .get(`/${pkg}`)
67
- .set(HEADERS.ACCEPT, HEADERS.JSON)
68
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
69
- .expect(HTTP_STATUS.OK);
70
- expect(response.body.name).toEqual(pkg);
71
- }
72
- );
73
-
74
- test.each([['foo'], ['@scope/foo']])(
75
- 'should return a foo private package by version',
76
- async (pkg) => {
77
- await publishVersion(app, pkg, '1.0.0');
78
- const response = await supertest(app)
79
- .get(`/${pkg}`)
80
- .set(HEADERS.ACCEPT, HEADERS.JSON)
81
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
82
- .expect(HTTP_STATUS.OK);
83
- expect(response.body.name).toEqual(pkg);
84
- }
85
- );
86
-
87
- test.each([['foo-abbreviated'], ['@scope/foo-abbreviated']])(
88
- 'should return abbreviated local manifest',
89
- async (pkg) => {
90
- await publishVersion(app, pkg, '1.0.0');
91
- const response = await supertest(app)
92
- .get(`/${pkg}`)
93
- .set(HEADERS.ACCEPT, HEADERS.JSON)
94
- .set(HEADERS.ACCEPT, Storage.ABBREVIATED_HEADER)
95
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_INSTALL_CHARSET)
96
- .expect(HTTP_STATUS.OK);
97
- expect(response.body.name).toEqual(pkg);
98
- expect(response.body.time).toBeDefined();
99
- expect(response.body.modified).toBeDefined();
100
- expect(response.body[DIST_TAGS]).toEqual({ latest: '1.0.0' });
101
- expect(response.body.readme).toBeDefined();
102
- expect(response.body._rev).toBeDefined();
103
- expect(response.body.users).not.toBeDefined();
104
- }
105
- );
106
- });
107
- });
@@ -1,18 +0,0 @@
1
- import supertest from 'supertest';
2
- import { describe, expect, test } from 'vitest';
3
-
4
- import { HEADERS, HEADER_TYPE, HTTP_STATUS } from '@verdaccio/core';
5
-
6
- import { initializeServer } from './_helper';
7
-
8
- describe('ping', () => {
9
- test('should return the reply the ping', async () => {
10
- const app = await initializeServer('ping.yaml');
11
- const response = await supertest(app)
12
- .get('/-/ping')
13
- .set('Accept', HEADERS.JSON)
14
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
15
- .expect(HTTP_STATUS.OK);
16
- expect(response.body).toEqual({});
17
- });
18
- });
@@ -1,112 +0,0 @@
1
- import supertest from 'supertest';
2
- import { describe, test } from 'vitest';
3
-
4
- import { HEADERS, HEADER_TYPE, HTTP_STATUS, TOKEN_BEARER } from '@verdaccio/core';
5
- import { buildToken } from '@verdaccio/utils';
6
-
7
- import { createUser, initializeServer } from './_helper';
8
-
9
- describe('profile ', () => {
10
- describe('get profile ', () => {
11
- test('should return Unauthorized if header token is missing', async () => {
12
- const app = await initializeServer('profile.yaml');
13
- return supertest(app)
14
- .get('/-/npm/v1/user')
15
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
16
- .expect(HTTP_STATUS.UNAUTHORIZED);
17
- });
18
-
19
- test('should return user details', async () => {
20
- const app = await initializeServer('profile.yaml');
21
- const credentials = { name: 'test', password: 'test' };
22
- const response = await createUser(app, credentials.name, credentials.password);
23
- return supertest(app)
24
- .get('/-/npm/v1/user')
25
- .set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, response.body.token))
26
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
27
- .expect(HTTP_STATUS.OK);
28
- });
29
- });
30
- describe('post profile ', () => {
31
- test('should return Unauthorized if header token is missing', async () => {
32
- const app = await initializeServer('profile.yaml');
33
- return supertest(app)
34
- .post('/-/npm/v1/user')
35
- .send({})
36
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
37
- .expect(HTTP_STATUS.UNAUTHORIZED);
38
- });
39
-
40
- test('should return handle to short new password', async () => {
41
- const app = await initializeServer('profile.yaml');
42
- const credentials = { name: 'test', password: 'test' };
43
- const response = await createUser(app, credentials.name, credentials.password);
44
- return supertest(app)
45
- .post('/-/npm/v1/user')
46
- .send({ password: { new: '_' } })
47
- .set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, response.body.token))
48
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
49
- .expect(HTTP_STATUS.UNAUTHORIZED);
50
- });
51
-
52
- test('should return handle to missing old password', async () => {
53
- const app = await initializeServer('profile.yaml');
54
- const credentials = { name: 'test', password: 'test' };
55
- const response = await createUser(app, credentials.name, credentials.password);
56
- return supertest(app)
57
- .post('/-/npm/v1/user')
58
- .send({ password: { new: 'fooooo', old: undefined } })
59
- .set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, response.body.token))
60
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
61
- .expect(HTTP_STATUS.BAD_REQUEST);
62
- });
63
-
64
- test('should return handle to missing password', async () => {
65
- const app = await initializeServer('profile.yaml');
66
- const credentials = { name: 'test', password: 'test' };
67
- const response = await createUser(app, credentials.name, credentials.password);
68
- return supertest(app)
69
- .post('/-/npm/v1/user')
70
- .send({ another: '_' })
71
- .set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, response.body.token))
72
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
73
- .expect(HTTP_STATUS.INTERNAL_ERROR);
74
- });
75
-
76
- test('should return handle change password', async () => {
77
- const app = await initializeServer('profile.yaml');
78
- const credentials = { name: 'test', password: 'test' };
79
- const response = await createUser(app, credentials.name, credentials.password);
80
- return supertest(app)
81
- .post('/-/npm/v1/user')
82
- .send({ password: { new: 'good password_.%#@$@#$@#', old: 'test' } })
83
- .set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, response.body.token))
84
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
85
- .expect(HTTP_STATUS.OK);
86
- });
87
-
88
- test('should return handle change password failure', async () => {
89
- const app = await initializeServer('profile.yaml');
90
- const credentials = { name: 'test', password: 'test' };
91
- const response = await createUser(app, credentials.name, credentials.password);
92
- return supertest(app)
93
- .post('/-/npm/v1/user')
94
- .send({ password: { new: 'good password_.%#@$@#$@#', old: 'test_do_not_match' } })
95
- .set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, response.body.token))
96
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
97
- .expect(HTTP_STATUS.FORBIDDEN);
98
- });
99
-
100
- test('should handle tfa ( two factor auth) disabled', async () => {
101
- const app = await initializeServer('profile.yaml');
102
- const credentials = { name: 'test', password: 'test' };
103
- const response = await createUser(app, credentials.name, credentials.password);
104
- return supertest(app)
105
- .post('/-/npm/v1/user')
106
- .send({ tfa: '_' })
107
- .set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, response.body.token))
108
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
109
- .expect(HTTP_STATUS.SERVICE_UNAVAILABLE);
110
- });
111
- });
112
- });
@@ -1,232 +0,0 @@
1
- import nock from 'nock';
2
- import { basename } from 'path';
3
- import supertest from 'supertest';
4
- import { describe, expect, test } from 'vitest';
5
-
6
- import { HTTP_STATUS } from '@verdaccio/core';
7
- import { API_ERROR, API_MESSAGE, HEADERS, HEADER_TYPE } from '@verdaccio/core';
8
- import { generatePackageMetadata, generateRemotePackageMetadata } from '@verdaccio/test-helper';
9
-
10
- import { getPackage, initializeServer, publishVersion } from './_helper';
11
-
12
- describe('publish', () => {
13
- describe('handle errors', () => {
14
- const pkgName = 'test';
15
- const pkgMetadata = generatePackageMetadata(pkgName, '1.0.0');
16
- test('should fail on publish a bad _attachments package', async () => {
17
- const app = await initializeServer('publish.yaml');
18
- const response = await supertest(app)
19
- .put(`/${encodeURIComponent(pkgName)}`)
20
- .set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
21
- .send(
22
- JSON.stringify(
23
- Object.assign({}, pkgMetadata, {
24
- _attachments: {},
25
- })
26
- )
27
- )
28
- .set('accept', HEADERS.GZIP)
29
- .expect(HTTP_STATUS.BAD_REQUEST);
30
- expect(response.body.error).toEqual(API_ERROR.UNSUPORTED_REGISTRY_CALL);
31
- });
32
-
33
- test('should fail on publish a bad versions package', async () => {
34
- const app = await initializeServer('publish.yaml');
35
- return new Promise((resolve) => {
36
- supertest(app)
37
- .put(`/${encodeURIComponent(pkgName)}`)
38
- .set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
39
- .send(
40
- JSON.stringify(
41
- Object.assign({}, pkgMetadata, {
42
- versions: '',
43
- })
44
- )
45
- )
46
- .set('accept', HEADERS.GZIP)
47
- .expect(HTTP_STATUS.BAD_REQUEST)
48
- .then((response) => {
49
- expect(response.body.error).toEqual(API_ERROR.UNSUPORTED_REGISTRY_CALL);
50
- resolve(response);
51
- });
52
- });
53
- });
54
-
55
- test.each([['foo', '@scope/foo']])(
56
- 'should fails on publish a duplicated package',
57
- async (pkgName) => {
58
- const app = await initializeServer('publish.yaml');
59
- await publishVersion(app, pkgName, '1.0.0');
60
- new Promise((resolve) => {
61
- publishVersion(app, pkgName, '1.0.0')
62
- .expect(HTTP_STATUS.CONFLICT)
63
- .then((response) => {
64
- expect(response.body.error).toEqual(API_ERROR.PACKAGE_EXIST);
65
- resolve(response);
66
- });
67
- });
68
- }
69
- );
70
- });
71
-
72
- describe('publish a package', () => {
73
- describe('no proxies setup', () => {
74
- test.each([['foo', '@scope/foo']])('should publish a package', async (pkgName) => {
75
- const app = await initializeServer('publish.yaml');
76
- new Promise((resolve) => {
77
- publishVersion(app, pkgName, '1.0.0')
78
- .expect(HTTP_STATUS.CREATED)
79
- .then((response) => {
80
- expect(response.body.ok).toEqual(API_MESSAGE.PKG_CREATED);
81
- resolve(response);
82
- });
83
- });
84
- });
85
-
86
- test.each([['foo', '@scope/foo']])('should publish a new package', async (pkgName) => {
87
- const pkgMetadata = generatePackageMetadata(pkgName, '1.0.0');
88
- const app = await initializeServer('publish.yaml');
89
- new Promise((resolve) => {
90
- supertest(app)
91
- .put(`/${encodeURIComponent(pkgName)}`)
92
- .set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
93
- .send(JSON.stringify(Object.assign({}, pkgMetadata)))
94
- .set('accept', HEADERS.GZIP)
95
- .expect(HTTP_STATUS.CREATED)
96
- .then((response) => {
97
- expect(response.body.ok).toEqual(API_MESSAGE.PKG_CREATED);
98
- resolve(response);
99
- });
100
- });
101
- });
102
-
103
- test('should publish a new package with no readme', async () => {
104
- const pkgName = 'test';
105
- const pkgMetadata = generatePackageMetadata(pkgName, '1.0.0');
106
- const app = await initializeServer('publish.yaml');
107
- return new Promise((resolve) => {
108
- supertest(app)
109
- .put(`/${encodeURIComponent(pkgName)}`)
110
- .set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
111
- .send(
112
- JSON.stringify(
113
- Object.assign({}, pkgMetadata, {
114
- versions: {
115
- ['1.0.0']: {
116
- readme: null,
117
- },
118
- },
119
- })
120
- )
121
- )
122
- .set('accept', HEADERS.GZIP)
123
- .expect(HTTP_STATUS.CREATED)
124
- .then((response) => {
125
- expect(response.body.ok).toEqual(API_MESSAGE.PKG_CREATED);
126
- resolve(response);
127
- });
128
- });
129
- });
130
- });
131
-
132
- describe('proxies setup', () => {
133
- test.each([['foo', '@scope%2Ffoo']])(
134
- 'should publish a a patch package that already exist on a remote',
135
- async (pkgName) => {
136
- const upstreamManifest = generateRemotePackageMetadata(
137
- pkgName,
138
- '1.0.0',
139
- 'https://registry.npmjs.org',
140
- ['1.0.1', '1.0.2', '1.0.3']
141
- );
142
- nock('https://registry.npmjs.org').get(`/${pkgName}`).reply(200, upstreamManifest);
143
- const app = await initializeServer('publish-proxy.yaml');
144
- const manifest = await getPackage(app, '', decodeURIComponent(pkgName));
145
- expect(manifest.body.name).toEqual(decodeURIComponent(pkgName));
146
- const response = await publishVersion(
147
- app,
148
- decodeURIComponent(pkgName),
149
- '1.0.1-patch'
150
- ).expect(HTTP_STATUS.CREATED);
151
- expect(response.body.ok).toEqual(API_MESSAGE.PKG_CHANGED);
152
- const response2 = await publishVersion(
153
- app,
154
- decodeURIComponent(pkgName),
155
- '1.0.2-patch'
156
- ).expect(HTTP_STATUS.CREATED);
157
- expect(response2.body.ok).toEqual(API_MESSAGE.PKG_CHANGED);
158
- }
159
- );
160
- });
161
- });
162
-
163
- describe('unpublish a package', () => {
164
- test.each([['foo', '@scope/foo']])('should unpublish entirely a package', async (pkgName) => {
165
- const app = await initializeServer('publish.yaml');
166
- await publishVersion(app, pkgName, '1.0.0');
167
- const response = await supertest(app)
168
- // FIXME: should be filtered by revision to avoid
169
- // conflicts
170
- .delete(`/${encodeURIComponent(pkgName)}/-rev/xxx`)
171
- .set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
172
- .expect(HTTP_STATUS.CREATED);
173
- expect(response.body.ok).toEqual(API_MESSAGE.PKG_REMOVED);
174
- // package should be completely un published
175
- await supertest(app)
176
- .get(`/${pkgName}`)
177
- .set('Accept', HEADERS.JSON)
178
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
179
- .expect(HTTP_STATUS.NOT_FOUND);
180
- });
181
-
182
- test.each([['foo', '@scope/foo']])(
183
- 'should fails unpublish entirely a package',
184
- async (pkgName) => {
185
- const app = await initializeServer('publish.yaml');
186
- const response = await supertest(app)
187
- .delete(`/${encodeURIComponent(pkgName)}/-rev/1cf3-fe3`)
188
- .set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
189
- .expect(HTTP_STATUS.NOT_FOUND);
190
- expect(response.body.error).toEqual(API_ERROR.NO_PACKAGE);
191
- }
192
- );
193
-
194
- test.each([['foo', '@scope/foo']])(
195
- 'should fails remove a tarball of a package does not exist',
196
- async (pkgName) => {
197
- const app = await initializeServer('publish.yaml');
198
- const response = await supertest(app)
199
- .delete(`/${pkgName}/-/${basename(pkgName)}-1.0.3.tgz/-rev/revision`)
200
- .set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
201
- .expect(HTTP_STATUS.NOT_FOUND);
202
- expect(response.body.error).toEqual(API_ERROR.NO_PACKAGE);
203
- }
204
- );
205
-
206
- test.each([['foo', '@scope/foo']])(
207
- 'should fails on try remove a tarball does not exist',
208
- async (pkgName) => {
209
- const app = await initializeServer('publish.yaml');
210
- await publishVersion(app, pkgName, '1.0.0');
211
- const response = await supertest(app)
212
- .delete(`/${pkgName}/-/${basename(pkgName)}-1.0.3.tgz/-rev/revision`)
213
- .set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
214
- .expect(HTTP_STATUS.NOT_FOUND);
215
- expect(response.body.error).toEqual(API_ERROR.NO_SUCH_FILE);
216
- }
217
- );
218
-
219
- test.each([['foo', '@scope/foo']])(
220
- 'should remove a tarball that does exist',
221
- async (pkgName) => {
222
- const app = await initializeServer('publish.yaml');
223
- await publishVersion(app, pkgName, '1.0.0');
224
- const response = await supertest(app)
225
- .delete(`/${pkgName}/-/${basename(pkgName)}-1.0.0.tgz/-rev/revision`)
226
- .set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
227
- .expect(HTTP_STATUS.CREATED);
228
- expect(response.body.ok).toEqual(API_MESSAGE.TARBALL_REMOVED);
229
- }
230
- );
231
- });
232
- });