@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,139 +0,0 @@
1
- import MockDate from 'mockdate';
2
- import supertest from 'supertest';
3
- import { beforeEach, describe, expect, test } from 'vitest';
4
-
5
- import { HEADERS, HEADER_TYPE, HTTP_STATUS } from '@verdaccio/core';
6
-
7
- import { createUser, initializeServer, publishVersionWithToken } from './_helper';
8
-
9
- describe('search', () => {
10
- let app;
11
- beforeEach(async () => {
12
- app = await initializeServer('search.yaml');
13
- });
14
-
15
- describe('search authenticated', () => {
16
- test.each([['foo']])('should return a foo private package', async (pkg) => {
17
- const mockDate = '2018-01-14T11:17:40.712Z';
18
- MockDate.set(mockDate);
19
- const res = await createUser(app, 'test', 'test');
20
- await publishVersionWithToken(app, pkg, '1.0.0', res.body.token);
21
- // this should not be displayed as part of the search
22
- await publishVersionWithToken(app, 'private-auth', '1.0.0', res.body.token);
23
- const response = await supertest(app)
24
- .get(
25
- `/-/v1/search?text=${encodeURIComponent(
26
- pkg
27
- )}&size=2000&from=0&quality=1&popularity=0.1&maintenance=0.1`
28
- )
29
- .set(HEADERS.ACCEPT, HEADERS.JSON)
30
- .set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
31
- .expect(HEADERS.CONTENT_TYPE, HEADERS.JSON_CHARSET)
32
- .expect(HTTP_STATUS.OK);
33
- expect(response.body).toEqual({
34
- objects: [
35
- {
36
- package: {
37
- author: {
38
- email: 'user@domain.com',
39
- name: 'User NPM',
40
- },
41
- date: mockDate,
42
- description: 'package generated',
43
- keywords: [],
44
- links: {
45
- npm: '',
46
- },
47
- maintainers: [
48
- {
49
- email: '',
50
- name: 'test',
51
- },
52
- ],
53
- name: pkg,
54
- publisher: {},
55
- scope: '',
56
- version: '1.0.0',
57
- },
58
- score: {
59
- detail: {
60
- maintenance: 0,
61
- popularity: 1,
62
- quality: 1,
63
- },
64
- final: 1,
65
- },
66
- searchScore: 1,
67
- verdaccioPkgCached: false,
68
- verdaccioPrivate: true,
69
- },
70
- ],
71
- time: 'Sun, 14 Jan 2018 11:17:40 GMT',
72
- total: 1,
73
- });
74
- });
75
-
76
- test.each([['@scope/foo']])('should return a scoped foo private package', async (pkg) => {
77
- const mockDate = '2018-01-14T11:17:40.712Z';
78
- MockDate.set(mockDate);
79
- const res = await createUser(app, 'test', 'test');
80
- await publishVersionWithToken(app, pkg, '1.0.0', res.body.token);
81
- // this should not be displayed as part of the search
82
- await publishVersionWithToken(app, '@private/auth', '1.0.0', res.body.token);
83
- const response = await supertest(app)
84
- .get(
85
- `/-/v1/search?text=${encodeURIComponent(
86
- pkg
87
- )}&size=2000&from=0&quality=1&popularity=0.1&maintenance=0.1`
88
- )
89
- .set(HEADERS.ACCEPT, HEADERS.JSON)
90
- .set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
91
- .expect(HEADERS.CONTENT_TYPE, HEADERS.JSON_CHARSET)
92
- .expect(HTTP_STATUS.OK);
93
- expect(response.body).toEqual({
94
- objects: [
95
- {
96
- package: {
97
- author: {
98
- email: 'user@domain.com',
99
- name: 'User NPM',
100
- },
101
- date: mockDate,
102
- description: 'package generated',
103
- keywords: [],
104
- links: {
105
- npm: '',
106
- },
107
- maintainers: [
108
- {
109
- email: '',
110
- name: 'test',
111
- },
112
- ],
113
- name: pkg,
114
- publisher: {},
115
- scope: '@scope',
116
- version: '1.0.0',
117
- },
118
- score: {
119
- detail: {
120
- maintenance: 0,
121
- popularity: 1,
122
- quality: 1,
123
- },
124
- final: 1,
125
- },
126
- searchScore: 1,
127
- verdaccioPkgCached: false,
128
- verdaccioPrivate: true,
129
- },
130
- ],
131
- time: 'Sun, 14 Jan 2018 11:17:40 GMT',
132
- total: 1,
133
- });
134
- });
135
- });
136
- describe('error handling', () => {
137
- test.todo('should able to abort the request');
138
- });
139
- });
@@ -1,74 +0,0 @@
1
- import nock from 'nock';
2
- import supertest from 'supertest';
3
- import { describe, expect, test } from 'vitest';
4
-
5
- import { HTTP_STATUS } from '@verdaccio/core';
6
- import { HEADERS, HEADER_TYPE } from '@verdaccio/core';
7
-
8
- import { getNewToken, getPackage, initializeServer, publishVersion, starPackage } from './_helper';
9
-
10
- describe('star', () => {
11
- test.each([['foo', '@scope%2Ffoo']])(
12
- 'should list stared packages for an user',
13
- async (pkgName) => {
14
- const userLogged = 'jota_token';
15
- nock('https://registry.npmjs.org').get(`/${pkgName}`).reply(404);
16
- const app = await initializeServer('star.yaml');
17
- const token = await getNewToken(app, { name: userLogged, password: 'secretPass' });
18
- await publishVersion(app, pkgName, '1.0.0', undefined, token).expect(HTTP_STATUS.CREATED);
19
- await publishVersion(app, 'pkg-1', '1.0.0', undefined, token).expect(HTTP_STATUS.CREATED);
20
- await publishVersion(app, 'pkg-2', '1.0.0', undefined, token).expect(HTTP_STATUS.CREATED);
21
- const manifest = await getPackage(app, '', decodeURIComponent(pkgName));
22
- await starPackage(
23
- app,
24
- {
25
- _rev: manifest.body._rev,
26
- _id: manifest.body.id,
27
- name: pkgName,
28
- users: { [userLogged]: true },
29
- },
30
- token
31
- ).expect(HTTP_STATUS.CREATED);
32
- await starPackage(
33
- app,
34
- {
35
- _rev: manifest.body._rev,
36
- _id: manifest.body.id,
37
- name: 'pkg-1',
38
- users: { [userLogged]: true },
39
- },
40
- token
41
- ).expect(HTTP_STATUS.CREATED);
42
- await starPackage(
43
- app,
44
- {
45
- _rev: manifest.body._rev,
46
- _id: manifest.body.id,
47
- name: 'pkg-2',
48
- users: { [userLogged]: true },
49
- },
50
- token
51
- ).expect(HTTP_STATUS.CREATED);
52
- const resp = await supertest(app)
53
- .get(`/-/_view/starredByUser?key=%22jota_token%22`)
54
- .set('Accept', HEADERS.JSON)
55
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
56
- .expect(HTTP_STATUS.OK);
57
- expect(resp.body.rows).toHaveLength(3);
58
- expect(resp.body.rows).toEqual([{ value: 'foo' }, { value: 'pkg-1' }, { value: 'pkg-2' }]);
59
- }
60
- );
61
-
62
- test.each([['foo']])('should requires parameters', async (pkgName) => {
63
- const userLogged = 'jota_token';
64
- nock('https://registry.npmjs.org').get(`/${pkgName}`).reply(404);
65
- const app = await initializeServer('star.yaml');
66
- const token = await getNewToken(app, { name: userLogged, password: 'secretPass' });
67
- await publishVersion(app, pkgName, '1.0.0', undefined, token).expect(HTTP_STATUS.CREATED);
68
- await supertest(app)
69
- .get(`/-/_view/starredByUser?key_xxxxx=other`)
70
- .set('Accept', HEADERS.JSON)
71
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
72
- .expect(HTTP_STATUS.BAD_REQUEST);
73
- });
74
- });
@@ -1,125 +0,0 @@
1
- import _ from 'lodash';
2
- import supertest from 'supertest';
3
- import { describe, expect, test } from 'vitest';
4
-
5
- import {
6
- API_ERROR,
7
- HEADERS,
8
- HEADER_TYPE,
9
- HTTP_STATUS,
10
- SUPPORT_ERRORS,
11
- TOKEN_BEARER,
12
- } from '@verdaccio/core';
13
- import { buildToken } from '@verdaccio/utils';
14
-
15
- import { deleteTokenCLI, generateTokenCLI, getNewToken, initializeServer } from './_helper';
16
-
17
- describe('token', () => {
18
- describe('basics', () => {
19
- test.each([['token.yaml'], ['token.jwt.yaml']])('should list empty tokens', async (conf) => {
20
- const app = await initializeServer(conf);
21
- const token = await getNewToken(app, { name: 'jota_token', password: 'secretPass' });
22
- const response = await supertest(app)
23
- .get('/-/npm/v1/tokens')
24
- .set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
25
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
26
- .expect(HTTP_STATUS.OK);
27
- expect(response.body.objects).toHaveLength(0);
28
- });
29
-
30
- test.each([['token.yaml'], ['token.jwt.yaml']])('should generate one token', async (conf) => {
31
- const app = await initializeServer(conf);
32
- const credentials = { name: 'jota_token', password: 'secretPass' };
33
- const token = await getNewToken(app, credentials);
34
- await generateTokenCLI(app, token, {
35
- password: credentials.password,
36
- readonly: false,
37
- cidr_whitelist: [],
38
- });
39
- const response = await supertest(app)
40
- .get('/-/npm/v1/tokens')
41
- .set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
42
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
43
- .expect(HTTP_STATUS.OK);
44
- const { objects, urls } = response.body;
45
-
46
- expect(objects).toHaveLength(1);
47
- const [tokenGenerated] = objects;
48
- expect(tokenGenerated.user).toEqual(credentials.name);
49
- expect(tokenGenerated.readonly).toBeFalsy();
50
- expect(tokenGenerated.token).toMatch(/.../);
51
- expect(_.isString(tokenGenerated.created)).toBeTruthy();
52
-
53
- // we don't support pagination yet
54
- expect(urls.next).toEqual('');
55
- });
56
-
57
- test.each([['token.yaml'], ['token.jwt.yaml']])('should delete a token', async (conf) => {
58
- const app = await initializeServer(conf);
59
- const credentials = { name: 'jota_token', password: 'secretPass' };
60
- const token = await getNewToken(app, credentials);
61
- const response = await generateTokenCLI(app, token, {
62
- password: credentials.password,
63
- readonly: false,
64
- cidr_whitelist: [],
65
- });
66
-
67
- const key = response.body.key;
68
- await deleteTokenCLI(app, token, key);
69
- const response2 = await supertest(app)
70
- .get('/-/npm/v1/tokens')
71
- .set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
72
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
73
- .expect(HTTP_STATUS.OK);
74
- const { objects } = response2.body;
75
- expect(objects).toHaveLength(0);
76
- });
77
- });
78
-
79
- describe('handle errors', () => {
80
- test.each([['token.yaml'], ['token.jwt.yaml']])('should delete a token', async (conf) => {
81
- const app = await initializeServer(conf);
82
- const credentials = { name: 'jota_token', password: 'secretPass' };
83
- const token = await getNewToken(app, credentials);
84
- const resp = await generateTokenCLI(app, token, {
85
- password: 'wrongPassword',
86
- readonly: false,
87
- cidr_whitelist: [],
88
- });
89
- expect(resp.body.error).toEqual(API_ERROR.BAD_USERNAME_PASSWORD);
90
- });
91
-
92
- test.each([['token.yaml'], ['token.jwt.yaml']])(
93
- 'should fail if readonly is missing',
94
- async (conf) => {
95
- const app = await initializeServer(conf);
96
- const credentials = { name: 'jota_token', password: 'secretPass' };
97
- const token = await getNewToken(app, credentials);
98
- const resp = await generateTokenCLI(app, token, {
99
- password: credentials.password,
100
- cidr_whitelist: [],
101
- });
102
- expect(resp.body.error).toEqual(SUPPORT_ERRORS.PARAMETERS_NOT_VALID);
103
- }
104
- );
105
- });
106
-
107
- test.each([['token.yaml'], ['token.jwt.yaml']])(
108
- 'should fail if cidr_whitelist is missing',
109
- async (conf) => {
110
- const app = await initializeServer(conf);
111
- const credentials = { name: 'jota_token', password: 'secretPass' };
112
- const token = await getNewToken(app, credentials);
113
- const resp = await generateTokenCLI(app, token, {
114
- password: credentials.password,
115
- readonly: false,
116
- });
117
- expect(resp.body.error).toEqual(SUPPORT_ERRORS.PARAMETERS_NOT_VALID);
118
- }
119
- );
120
-
121
- test.todo('handle failure if delete token');
122
- test.todo('handle failure if getApiToken fails');
123
- test.todo('handle failure if token creating fails');
124
- test.todo('handle failure if token list fails');
125
- });
@@ -1,222 +0,0 @@
1
- import supertest from 'supertest';
2
- import { describe, expect, test, vi } from 'vitest';
3
-
4
- import { API_ERROR, HEADERS, HEADER_TYPE, HTTP_STATUS, TOKEN_BEARER } from '@verdaccio/core';
5
- import { buildToken } from '@verdaccio/utils';
6
-
7
- import { createUser, getPackage, initializeServer } from './_helper';
8
-
9
- const FORBIDDEN_VUE = 'authorization required to access package vue';
10
-
11
- vi.setConfig({ testTimeout: 20000 });
12
-
13
- describe('token', () => {
14
- describe('basics', () => {
15
- const FAKE_TOKEN: string = buildToken(TOKEN_BEARER, 'fake');
16
- test.each([['user.yaml'], ['user.jwt.yaml']])('should test add a new user', async (conf) => {
17
- const app = await initializeServer(conf);
18
- const credentials = { name: 'JotaJWT', password: 'secretPass' };
19
- const response = await createUser(app, credentials.name, credentials.password);
20
- expect(response.body.ok).toMatch(`user '${credentials.name}' created`);
21
-
22
- const vueResponse = await getPackage(app, response.body.token, 'vue');
23
- expect(vueResponse.body).toBeDefined();
24
- expect(vueResponse.body.name).toMatch('vue');
25
-
26
- const vueFailResp = await getPackage(app, FAKE_TOKEN, 'vue', HTTP_STATUS.UNAUTHORIZED);
27
- expect(vueFailResp.body.error).toMatch(FORBIDDEN_VUE);
28
- });
29
-
30
- test.each([['user.yaml'], ['user.jwt.yaml']])('should login an user', async (conf) => {
31
- const app = await initializeServer(conf);
32
- const credentials = { name: 'test', password: 'test' };
33
- const response = await createUser(app, credentials.name, credentials.password);
34
- expect(response.body.ok).toMatch(`user '${credentials.name}' created`);
35
-
36
- await supertest(app)
37
- .put(`/-/user/org.couchdb.user:${credentials.name}`)
38
- .send({
39
- name: credentials.name,
40
- password: credentials.password,
41
- })
42
- .set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, response.body.token))
43
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
44
- .expect(HTTP_STATUS.CREATED);
45
- });
46
-
47
- test.each([['user.yaml'], ['user.jwt.yaml']])(
48
- 'should fails login a valid user',
49
- async (conf) => {
50
- const app = await initializeServer(conf);
51
- const credentials = { name: 'test', password: 'test' };
52
- const response = await createUser(app, credentials.name, credentials.password);
53
- expect(response.body.ok).toMatch(`user '${credentials.name}' created`);
54
-
55
- await supertest(app)
56
- .put(`/-/user/org.couchdb.user:${credentials.name}`)
57
- .send({
58
- name: credentials.name,
59
- password: 'failPassword',
60
- })
61
- .set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, response.body.token))
62
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
63
- .expect(HTTP_STATUS.UNAUTHORIZED);
64
- }
65
- );
66
-
67
- test.each([['user.yaml'], ['user.jwt.yaml']])(
68
- 'should test conflict create new user',
69
- async (conf) => {
70
- const app = await initializeServer(conf);
71
- const credentials = { name: 'JotaJWT', password: 'secretPass' };
72
- const response = await createUser(app, credentials.name, credentials.password);
73
- expect(response.body.ok).toMatch(`user '${credentials.name}' created`);
74
- const response2 = await supertest(app)
75
- .put(`/-/user/org.couchdb.user:${credentials.name}`)
76
- .send({
77
- name: credentials.name,
78
- password: credentials.password,
79
- })
80
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
81
- .expect(HTTP_STATUS.CONFLICT);
82
- expect(response2.body.error).toBe(API_ERROR.USERNAME_ALREADY_REGISTERED);
83
- }
84
- );
85
-
86
- test.each([['user.yaml'], ['user.jwt.yaml']])(
87
- 'should fails on login if user credentials are invalid',
88
- async (conf) => {
89
- const app = await initializeServer(conf);
90
- const credentials = { name: 'newFailsUser', password: 'secretPass' };
91
- const response = await createUser(app, credentials.name, credentials.password);
92
- expect(response.body.ok).toMatch(`user '${credentials.name}' created`);
93
- const response2 = await supertest(app)
94
- .put(`/-/user/org.couchdb.user:${credentials.name}`)
95
- .send({
96
- name: credentials.name,
97
- password: 'BAD_PASSWORD',
98
- })
99
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
100
- .expect(HTTP_STATUS.UNAUTHORIZED);
101
- expect(response2.body.error).toBe(API_ERROR.UNAUTHORIZED_ACCESS);
102
- }
103
- );
104
-
105
- test.each([['user.yaml'], ['user.jwt.yaml']])(
106
- 'should fails password validation',
107
- async (conf) => {
108
- const credentials = { name: 'test', password: '12' };
109
- const app = await initializeServer(conf);
110
- const response = await supertest(app)
111
- .put(`/-/user/org.couchdb.user:${credentials.name}`)
112
- .send({
113
- name: credentials.name,
114
- password: credentials.password,
115
- })
116
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
117
- .expect(HTTP_STATUS.BAD_REQUEST);
118
- expect(response.body.error).toBe(API_ERROR.PASSWORD_SHORT);
119
- }
120
- );
121
-
122
- test.each([['user.yaml'], ['user.jwt.yaml']])(
123
- 'should fails missing password validation',
124
- async (conf) => {
125
- const credentials = { name: 'test' };
126
- const app = await initializeServer(conf);
127
- const response = await supertest(app)
128
- .put(`/-/user/org.couchdb.user:${credentials.name}`)
129
- .send({
130
- name: credentials.name,
131
- password: undefined,
132
- })
133
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
134
- .expect(HTTP_STATUS.BAD_REQUEST);
135
- expect(response.body.error).toBe(API_ERROR.PASSWORD_SHORT);
136
- }
137
- );
138
-
139
- test.each([['user.yaml'], ['user.jwt.yaml']])(
140
- 'should verify if user is logged',
141
- async (conf) => {
142
- const app = await initializeServer(conf);
143
- const credentials = { name: 'jota', password: 'secretPass' };
144
- const response = await createUser(app, credentials.name, credentials.password);
145
- expect(response.body.ok).toMatch(`user '${credentials.name}' created`);
146
- const response2 = await supertest(app)
147
- .get(`/-/user/org.couchdb.user:${credentials.name}`)
148
- .set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, response.body.token))
149
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
150
- .expect(HTTP_STATUS.OK);
151
- expect(response2.body.ok).toBe(`you are authenticated as '${credentials.name}'`);
152
- expect(response2.body.name).toBe(credentials.name);
153
- }
154
- );
155
-
156
- test.each([['user.yaml'], ['user.jwt.yaml']])(
157
- 'should return name of requested user',
158
- async (conf) => {
159
- const app = await initializeServer(conf);
160
- const username = 'yeti';
161
- const credentials = { name: 'jota', password: 'secretPass' };
162
- const response = await createUser(app, credentials.name, credentials.password);
163
- expect(response.body.ok).toMatch(`user '${credentials.name}' created`);
164
- const response3 = await supertest(app)
165
- .get(`/-/user/org.couchdb.user:${username}`)
166
- .set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, response.body.token))
167
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
168
- .expect(HTTP_STATUS.OK);
169
- expect(response3.body.ok).toBe(`you are authenticated as '${credentials.name}'`);
170
- expect(response3.body.name).toBe(username);
171
- }
172
- );
173
-
174
- test.each([['user.yaml'], ['user.jwt.yaml']])('should logout user', async (conf) => {
175
- const app = await initializeServer(conf);
176
- const credentials = { name: 'jota', password: 'secretPass' };
177
- const response = await createUser(app, credentials.name, credentials.password);
178
- await supertest(app)
179
- .get(`/-/user/org.couchdb.user:${credentials.name}`)
180
- .set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, response.body.token))
181
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
182
- .expect(HTTP_STATUS.OK);
183
- await supertest(app)
184
- .delete(`/-/user/token/someSecretToken:${response.body.token}`)
185
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
186
- .expect(HTTP_STATUS.OK);
187
- });
188
-
189
- test.each([['user.yaml'], ['user.jwt.yaml']])(
190
- 'should return "false" if user is not logged in',
191
- async (conf) => {
192
- const app = await initializeServer(conf);
193
- const credentials = { name: 'jota', password: '' };
194
- const response = await supertest(app)
195
- .get(`/-/user/org.couchdb.user:${credentials.name}`)
196
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
197
- .expect(HTTP_STATUS.OK);
198
- expect(response.body.ok).toBe(false);
199
- }
200
- );
201
-
202
- test.each([['user.yaml'], ['user.jwt.yaml']])(
203
- 'should fail if URL does not match user in request body',
204
- async (conf) => {
205
- const app = await initializeServer(conf);
206
- const credentials = { name: 'jota', password: 'secretPass' };
207
- const response = await createUser(app, credentials.name, credentials.password);
208
- expect(response.body.ok).toMatch(`user '${credentials.name}' created`);
209
- const response2 = await supertest(app)
210
- .put('/-/user/org.couchdb.user:yeti') // different user
211
- .set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, response.body.token))
212
- .send({
213
- name: credentials.name,
214
- password: credentials.password,
215
- })
216
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
217
- .expect(HTTP_STATUS.BAD_REQUEST);
218
- expect(response2.body.error).toBe(API_ERROR.USERNAME_MISMATCH);
219
- }
220
- );
221
- });
222
- });
@@ -1,36 +0,0 @@
1
- import supertest from 'supertest';
2
- import { describe, expect, test } from 'vitest';
3
-
4
- import { HEADERS, HTTP_STATUS, TOKEN_BEARER } from '@verdaccio/core';
5
- import { buildToken } from '@verdaccio/utils';
6
-
7
- import { createUser, initializeServer } from './_helper';
8
-
9
- describe('whoami', () => {
10
- test('should return the logged username', async () => {
11
- const app = await initializeServer('whoami.yaml');
12
- // @ts-expect-error internal property
13
- const { _body } = await createUser(app, 'test', 'test');
14
- return supertest(app)
15
- .get('/-/whoami')
16
- .set('Accept', HEADERS.JSON)
17
- .set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, _body.token))
18
- .expect('Content-Type', HEADERS.JSON_CHARSET)
19
- .expect(HTTP_STATUS.OK)
20
- .then((response) => {
21
- expect(response.body.username).toEqual('test');
22
- });
23
- });
24
-
25
- test('should fails with 401 if is not logged in', async () => {
26
- const app = await initializeServer('whoami.yaml');
27
- // @ts-expect-error internal property
28
- const { _body } = await createUser(app, 'test', 'test');
29
- return supertest(app)
30
- .get('/-/whoami')
31
- .set('Accept', HEADERS.JSON)
32
- .set(HEADERS.AUTHORIZATION, buildToken('invalid-token', _body.token))
33
- .expect('Content-Type', HEADERS.JSON_CHARSET)
34
- .expect(HTTP_STATUS.UNAUTHORIZED);
35
- });
36
- });