@verdaccio/server 6.0.0-6-next.29 → 6.0.0-6-next.32

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 (73) hide show
  1. package/.babelrc +1 -1
  2. package/CHANGELOG.md +91 -0
  3. package/build/debug/index.d.ts +1 -1
  4. package/build/debug/index.js +1 -1
  5. package/build/debug/index.js.map +1 -1
  6. package/build/env.js.map +1 -1
  7. package/build/index.js.map +1 -1
  8. package/build/server.d.ts +2 -2
  9. package/build/server.js +5 -3
  10. package/build/server.js.map +1 -1
  11. package/build/utils.d.ts +1 -0
  12. package/build/utils.js +19 -0
  13. package/build/utils.js.map +1 -0
  14. package/jest.config.js +7 -2
  15. package/package.json +70 -71
  16. package/src/debug/index.ts +2 -2
  17. package/src/server.ts +8 -7
  18. package/src/utils.ts +11 -0
  19. package/test/_helper.ts +29 -0
  20. package/test/config/conf.yaml +28 -0
  21. package/test/config/no_debug.yaml +26 -0
  22. package/test/config/powered-custom.yaml +29 -0
  23. package/test/config/powered-disabled.yaml +29 -0
  24. package/test/config/web-disabled.yaml +27 -0
  25. package/test/server.spec.ts +113 -0
  26. package/tsconfig.build.json +1 -1
  27. package/tsconfig.json +14 -14
  28. package/jest.setup.js +0 -1
  29. package/test/.eslintrc +0 -8
  30. package/test/README.md +0 -12
  31. package/test/api/api.spec.yaml +0 -87
  32. package/test/api/helpers/publish-api.js +0 -60
  33. package/test/api/helpers/utils.ts +0 -149
  34. package/test/api/htpasswd +0 -10
  35. package/test/api/index.spec.ts +0 -862
  36. package/test/api/mock/store/@jquery/jquery/jquery-1.5.1.tgz +0 -0
  37. package/test/api/mock/store/@jquery/jquery/package.json +0 -76
  38. package/test/api/mock/store/corrupted-package/package.json +0 -12
  39. package/test/api/mock/store/jquery/jquery-1.5.1.tgz +0 -0
  40. package/test/api/mock/store/jquery/package.json +0 -4919
  41. package/test/api/mock/store/npm_test/package.json +0 -75
  42. package/test/api/mock/store/vue/package.json +0 -25169
  43. package/test/api/plugin/filter.ts +0 -25
  44. package/test/basic/basic.yaml +0 -14
  45. package/test/basic/index.spec.ts +0 -64
  46. package/test/jwt/index.spec.ts +0 -163
  47. package/test/jwt/jwt.yaml +0 -35
  48. package/test/jwt/mock/store/vue/package.json +0 -25169
  49. package/test/package-access/index.spec.ts +0 -100
  50. package/test/package-access/mock/store/.gitkeep +0 -0
  51. package/test/package-access/mock/store/jquery/jquery-1.5.1.tgz +0 -0
  52. package/test/package-access/mock/store/jquery/package.json +0 -4919
  53. package/test/package-access/mock/store/vue/package.json +0 -25169
  54. package/test/package-access/pkg.access.yaml +0 -12
  55. package/test/profile/index.spec.ts +0 -129
  56. package/test/profile/mock/store/.gitkeep +0 -0
  57. package/test/profile/profile.yaml +0 -21
  58. package/test/storage/index.spec.ts +0 -219
  59. package/test/storage/mock/store/@jquery/jquery/jquery-1.5.1.tgz +0 -0
  60. package/test/storage/mock/store/@jquery/jquery/package.json +0 -76
  61. package/test/storage/mock/store/corrupted-package/package.json +0 -12
  62. package/test/storage/mock/store/jquery/jquery-1.5.1.tgz +0 -0
  63. package/test/storage/mock/store/jquery/package.json +0 -4919
  64. package/test/storage/mock/store/npm_test/package.json +0 -75
  65. package/test/storage/store.spec.yaml +0 -24
  66. package/test/token/index.spec.ts +0 -227
  67. package/test/token/mock/store/.gitkeep +0 -0
  68. package/test/token/token.spec.yaml +0 -26
  69. package/test/web/index.spec.ts +0 -157
  70. package/test/web/mock/store/.gitkeep +0 -0
  71. package/test/web/partials/forbidden-place.js +0 -50
  72. package/test/web/partials/publish-api.js +0 -50
  73. package/test/web/web.yaml +0 -20
@@ -1,25 +0,0 @@
1
- class FilterPlugin {
2
- private _config;
3
- public constructor(config) {
4
- this._config = config;
5
- }
6
-
7
- public filter_metadata(pkg) {
8
- return new Promise((resolve, reject) => {
9
- // We use this to test what happens when a filter rejects
10
- if (pkg.name === 'trigger-filter-failure') {
11
- reject(new Error('Example filter failure'));
12
- return;
13
- }
14
- // Example filter that removes a single blocked package
15
- if (this._config.pkg === pkg.name) {
16
- // In reality, we also want to remove references in attachments and dist-tags,
17
- // etc. This is just a POC
18
- delete pkg.versions[this._config.version];
19
- }
20
- resolve(pkg);
21
- });
22
- }
23
- }
24
-
25
- exports.default = FilterPlugin;
@@ -1,14 +0,0 @@
1
- store:
2
- memory:
3
- limit: 1000
4
- uplinks:
5
- npmjs:
6
- url: http://localhost:4873/
7
- packages:
8
- '@*/*':
9
- access: $all
10
- publish: $all
11
- '*':
12
- access: $all
13
- publish: $all
14
- log: { type: stdout, format: pretty, level: warn }
@@ -1,64 +0,0 @@
1
- import express from 'express';
2
- import path from 'path';
3
- import request from 'request';
4
-
5
- import { parseConfigFile } from '@verdaccio/config';
6
- import { API_ERROR } from '@verdaccio/core';
7
- import { setup } from '@verdaccio/logger';
8
-
9
- import endPointAPI from '../../src';
10
-
11
- setup([{ type: 'stdout', format: 'pretty', level: 'trace' }]);
12
-
13
- const app = express();
14
- const server = require('http').createServer(app);
15
-
16
- const parseConfigurationFile = (conf) => {
17
- return path.join(__dirname, `./${conf}`);
18
- };
19
-
20
- // TODO: restore when web module is ready
21
- describe.skip('basic system test', () => {
22
- let port;
23
- jest.setTimeout(20000);
24
-
25
- beforeAll(async function (done) {
26
- const config = parseConfigFile(parseConfigurationFile('basic.yaml'));
27
- app.use(await endPointAPI(config));
28
- server.listen(0, function () {
29
- port = server.address().port;
30
- done();
31
- });
32
- });
33
-
34
- afterAll((done) => {
35
- server.close(done);
36
- });
37
-
38
- test('server should respond on /', (done) => {
39
- request(
40
- {
41
- url: 'http://localhost:' + port + '/',
42
- },
43
- function (err, res, body) {
44
- expect(err).toBeNull();
45
- expect(body).toMatch(/Verdaccio/);
46
- done();
47
- }
48
- );
49
- });
50
-
51
- test('server should respond on /___not_found_package', (done) => {
52
- request(
53
- {
54
- json: true,
55
- url: `http://localhost:${port}/___not_found_package`,
56
- },
57
- function (err, res, body) {
58
- expect(err).toBeNull();
59
- expect(body.error).toMatch(API_ERROR.NO_PACKAGE);
60
- done();
61
- }
62
- );
63
- });
64
- });
@@ -1,163 +0,0 @@
1
- import path from 'path';
2
- import request from 'supertest';
3
-
4
- import {
5
- API_ERROR,
6
- HEADERS,
7
- HEADER_TYPE,
8
- HTTP_STATUS,
9
- TOKEN_BASIC,
10
- TOKEN_BEARER,
11
- } from '@verdaccio/core';
12
- import { logger, setup } from '@verdaccio/logger';
13
- import { generateRamdonStorage, mockServer } from '@verdaccio/mock';
14
- import {
15
- DOMAIN_SERVERS,
16
- addUser,
17
- configExample,
18
- getPackage,
19
- loginUserToken,
20
- } from '@verdaccio/mock';
21
- import { buildToken, buildUserBuffer } from '@verdaccio/utils';
22
-
23
- import endPointAPI from '../../src';
24
-
25
- setup([]);
26
-
27
- const credentials = { name: 'JotaJWT', password: 'secretPass' };
28
-
29
- const FORBIDDEN_VUE = 'authorization required to access package vue';
30
-
31
- describe('endpoint user auth JWT unit test', () => {
32
- jest.setTimeout(20000);
33
- let app;
34
- let mockRegistry;
35
- const FAKE_TOKEN: string = buildToken(TOKEN_BEARER, 'fake');
36
-
37
- beforeAll(async function () {
38
- const mockServerPort = 55546;
39
- const store = generateRamdonStorage();
40
- const configForTest = configExample(
41
- {
42
- storage: store,
43
- uplinks: {
44
- remote: {
45
- url: `http://${DOMAIN_SERVERS}:${mockServerPort}`,
46
- },
47
- },
48
- config_path: store,
49
- },
50
- 'jwt.yaml',
51
- __dirname
52
- );
53
-
54
- app = await endPointAPI(configForTest);
55
- const binPath = require.resolve('verdaccio/bin/verdaccio');
56
- const storePath = path.join(__dirname, '/mock/store');
57
- mockRegistry = await mockServer(mockServerPort, { storePath, silence: true }).init(binPath);
58
- });
59
-
60
- afterAll(function () {
61
- const [registry, pid] = mockRegistry;
62
- registry.stop();
63
- logger.info(`registry ${pid} has been stopped`);
64
- });
65
-
66
- test('should test add a new user with JWT enabled', async () => {
67
- const [err, res] = await addUser(request(app), credentials.name, credentials);
68
- expect(err).toBeNull();
69
- expect(res.body.ok).toBeDefined();
70
- expect(res.body.token).toBeDefined();
71
-
72
- const { token } = res.body;
73
- expect(typeof token).toBe('string');
74
- expect(res.body.ok).toMatch(`user '${credentials.name}' created`);
75
-
76
- // testing JWT auth headers with token
77
- // we need it here, because token is required
78
- const [err1, resp1] = await getPackage(request(app), token, 'vue');
79
-
80
- expect(err1).toBeNull();
81
- expect(resp1.body).toBeDefined();
82
- expect(resp1.body.name).toMatch('vue');
83
-
84
- const [err2, resp2] = await getPackage(
85
- request(app),
86
- FAKE_TOKEN,
87
- 'vue',
88
- HTTP_STATUS.UNAUTHORIZED
89
- );
90
- expect(err2).toBeNull();
91
- expect(resp2.statusCode).toBe(HTTP_STATUS.UNAUTHORIZED);
92
- expect(resp2.body.error).toMatch(FORBIDDEN_VUE);
93
- });
94
-
95
- test('should emulate npm login when user already exist', async () => {
96
- const credentials = { name: 'jwtUser2', password: 'secretPass' };
97
- // creates an user
98
- await addUser(request(app), credentials.name, credentials);
99
- // it should fails conflict 409
100
- await addUser(request(app), credentials.name, credentials, HTTP_STATUS.CONFLICT);
101
-
102
- // npm will try to sign in sending credentials via basic auth header
103
- const token = buildUserBuffer(credentials.name, credentials.password).toString('base64');
104
- // put should exist in request
105
- return new Promise((resolve) => {
106
- // @ts-ignore
107
- request(app)
108
- .put(`/-/user/org.couchdb.user:${credentials.name}/-rev/undefined`)
109
- .send(credentials)
110
- .set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BASIC, token))
111
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
112
- .expect(HTTP_STATUS.CREATED)
113
- .end(function (err, res) {
114
- expect(err).toBeNull();
115
- expect(res.body.ok).toBeDefined();
116
- expect(res.body.token).toBeDefined();
117
-
118
- resolve(res);
119
- });
120
- });
121
- });
122
-
123
- test('should fails on try to access with corrupted token', async () => {
124
- const [err2, resp2] = await getPackage(
125
- request(app),
126
- FAKE_TOKEN,
127
- 'vue',
128
- HTTP_STATUS.UNAUTHORIZED
129
- );
130
- expect(err2).toBeNull();
131
- expect(resp2.statusCode).toBe(HTTP_STATUS.UNAUTHORIZED);
132
- expect(resp2.body.error).toMatch(FORBIDDEN_VUE);
133
- });
134
-
135
- test(
136
- 'should fails on login if user credentials are invalid even if jwt' +
137
- ' valid token is provided',
138
- async () => {
139
- const credentials = { name: 'newFailsUser', password: 'secretPass' };
140
- const [err, res] = await addUser(request(app), credentials.name, credentials);
141
- expect(err).toBeNull();
142
- expect(res.body.ok).toBeDefined();
143
- expect(res.body.token).toBeDefined();
144
-
145
- const { token } = res.body;
146
- expect(typeof token).toBe('string');
147
- expect(res.body.ok).toMatch(`user '${credentials.name}' created`);
148
-
149
- // we login when token is valid
150
- const newCredentials = { name: 'newFailsUser', password: 'BAD_PASSWORD' };
151
- const [err2, resp2] = await loginUserToken(
152
- request(app),
153
- newCredentials.name,
154
- newCredentials,
155
- token,
156
- HTTP_STATUS.UNAUTHORIZED
157
- );
158
- expect(err2).toBeNull();
159
- expect(resp2.statusCode).toBe(HTTP_STATUS.UNAUTHORIZED);
160
- expect(resp2.body.error).toMatch(API_ERROR.BAD_USERNAME_PASSWORD);
161
- }
162
- );
163
- });
package/test/jwt/jwt.yaml DELETED
@@ -1,35 +0,0 @@
1
- storage: ./storage
2
- plugins: ./plugins
3
-
4
- web:
5
- title: Verdaccio
6
-
7
- auth:
8
- htpasswd:
9
- file: ./htpasswd
10
-
11
- security:
12
- api:
13
- jwt:
14
- sign:
15
- expiresIn: 10m
16
- notBefore: 0
17
- packages:
18
- '@*/*':
19
- access: $all
20
- publish: $authenticated
21
- proxy: remote
22
- 'vue':
23
- access: $authenticated
24
- publish: $authenticated
25
- proxy: remote
26
- '**':
27
- access: $all
28
- publish: $authenticated
29
- proxy: remote
30
-
31
- middlewares:
32
- audit:
33
- enabled: true
34
-
35
- log: { type: stdout, format: pretty, level: warn }