@verdaccio/auth 6.0.0-6-next.26 → 6.0.0-6-next.28
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 +87 -0
- package/build/auth.d.ts +18 -33
- package/build/auth.js +53 -47
- package/build/auth.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.js +1 -15
- package/build/index.js.map +1 -1
- package/build/utils.d.ts +10 -5
- package/build/utils.js +8 -2
- package/build/utils.js.map +1 -1
- package/package.json +9 -9
- package/src/auth.ts +117 -126
- package/src/index.ts +1 -1
- package/src/utils.ts +12 -13
- package/test/auth-utils.spec.ts +4 -3
- package/test/auth.spec.ts +65 -30
- package/test/helper/plugin.ts +14 -3
- package/test/partials/plugin/verdaccio-fail/fail.js +11 -0
- package/test/partials/plugin/verdaccio-fail/package.json +5 -0
- package/test/partials/plugin/verdaccio-fail-invalid-method/fail.js +11 -0
- package/test/partials/plugin/verdaccio-fail-invalid-method/package.json +5 -0
- package/test/partials/plugin/verdaccio-passthroug/package.json +5 -0
- package/test/partials/plugin/{authenticate.passthroug.js → verdaccio-passthroug/passthroug.js} +0 -0
- package/test/partials/plugin/verdaccio-success/package.json +5 -0
- package/test/partials/plugin/{authenticate.success.js → verdaccio-success/success.js} +0 -0
- package/tsconfig.build.json +3 -3
- package/tsconfig.json +6 -6
- package/test/partials/plugin/authenticate.fail.js +0 -11
package/test/auth-utils.spec.ts
CHANGED
|
@@ -24,7 +24,6 @@ import type { AllowActionCallbackResponse } from '@verdaccio/utils';
|
|
|
24
24
|
import {
|
|
25
25
|
ActionsAllowed,
|
|
26
26
|
Auth,
|
|
27
|
-
IAuth,
|
|
28
27
|
aesDecrypt,
|
|
29
28
|
allow_action,
|
|
30
29
|
getApiToken,
|
|
@@ -70,7 +69,8 @@ describe('Auth utilities', () => {
|
|
|
70
69
|
methodNotBeenCalled: string
|
|
71
70
|
): Promise<string> {
|
|
72
71
|
const config: Config = getConfig(configFileName, secret);
|
|
73
|
-
const auth:
|
|
72
|
+
const auth: Auth = new Auth(config);
|
|
73
|
+
await auth.init();
|
|
74
74
|
// @ts-ignore
|
|
75
75
|
const spy = jest.spyOn(auth, methodToSpy);
|
|
76
76
|
// @ts-ignore
|
|
@@ -408,7 +408,8 @@ describe('Auth utilities', () => {
|
|
|
408
408
|
test.concurrent('should return empty credential corrupted payload', async () => {
|
|
409
409
|
const secret = 'b2df428b9929d3ace7c598bbf4e496b2';
|
|
410
410
|
const config: Config = getConfig('security-legacy', secret);
|
|
411
|
-
const auth:
|
|
411
|
+
const auth: Auth = new Auth(config);
|
|
412
|
+
await auth.init();
|
|
412
413
|
const token = auth.aesEncrypt(null);
|
|
413
414
|
const security: Security = config.security;
|
|
414
415
|
const credentials = getMiddlewareCredentials(
|
package/test/auth.spec.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import path from 'path';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { Config as AppConfig, ROLES } from '@verdaccio/config';
|
|
3
|
+
import { Config as AppConfig, ROLES, getDefaultConfig } from '@verdaccio/config';
|
|
5
4
|
import { errorUtils } from '@verdaccio/core';
|
|
6
5
|
import { setup } from '@verdaccio/logger';
|
|
7
6
|
import { Config } from '@verdaccio/types';
|
|
@@ -9,25 +8,34 @@ import { Config } from '@verdaccio/types';
|
|
|
9
8
|
import { Auth } from '../src';
|
|
10
9
|
import { authPluginFailureConf, authPluginPassThrougConf, authProfileConf } from './helper/plugin';
|
|
11
10
|
|
|
12
|
-
setup(
|
|
11
|
+
setup({});
|
|
13
12
|
|
|
14
13
|
describe('AuthTest', () => {
|
|
15
|
-
test('should
|
|
16
|
-
const config: Config = new AppConfig(
|
|
14
|
+
test('should init correctly', async () => {
|
|
15
|
+
const config: Config = new AppConfig({ ...authProfileConf });
|
|
17
16
|
config.checkSecretKey('12345');
|
|
18
17
|
|
|
19
|
-
const auth:
|
|
18
|
+
const auth: Auth = new Auth(config);
|
|
19
|
+
await auth.init();
|
|
20
|
+
expect(auth).toBeDefined();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('should load default auth plugin', async () => {
|
|
24
|
+
const config: Config = new AppConfig({ ...authProfileConf, auth: undefined });
|
|
25
|
+
config.checkSecretKey('12345');
|
|
20
26
|
|
|
27
|
+
const auth: Auth = new Auth(config);
|
|
28
|
+
await auth.init();
|
|
21
29
|
expect(auth).toBeDefined();
|
|
22
30
|
});
|
|
23
31
|
|
|
24
32
|
describe('test authenticate method', () => {
|
|
25
33
|
describe('test authenticate states', () => {
|
|
26
|
-
test('should be a success login', () => {
|
|
27
|
-
const config: Config = new AppConfig(
|
|
34
|
+
test('should be a success login', async () => {
|
|
35
|
+
const config: Config = new AppConfig({ ...authProfileConf });
|
|
28
36
|
config.checkSecretKey('12345');
|
|
29
|
-
const auth:
|
|
30
|
-
|
|
37
|
+
const auth: Auth = new Auth(config);
|
|
38
|
+
await auth.init();
|
|
31
39
|
expect(auth).toBeDefined();
|
|
32
40
|
|
|
33
41
|
const callback = jest.fn();
|
|
@@ -50,11 +58,11 @@ describe('AuthTest', () => {
|
|
|
50
58
|
});
|
|
51
59
|
});
|
|
52
60
|
|
|
53
|
-
test('should be a fail on login', () => {
|
|
61
|
+
test('should be a fail on login', async () => {
|
|
54
62
|
const config: Config = new AppConfig(authPluginFailureConf);
|
|
55
63
|
config.checkSecretKey('12345');
|
|
56
|
-
const auth:
|
|
57
|
-
|
|
64
|
+
const auth: Auth = new Auth(config);
|
|
65
|
+
await auth.init();
|
|
58
66
|
expect(auth).toBeDefined();
|
|
59
67
|
|
|
60
68
|
const callback = jest.fn();
|
|
@@ -69,11 +77,11 @@ describe('AuthTest', () => {
|
|
|
69
77
|
// that might make break the request
|
|
70
78
|
// the @ts-ignore below are intended
|
|
71
79
|
describe('test authenticate out of control inputs from plugins', () => {
|
|
72
|
-
test('should skip falsy values', () => {
|
|
73
|
-
const config: Config = new AppConfig(
|
|
80
|
+
test('should skip falsy values', async () => {
|
|
81
|
+
const config: Config = new AppConfig({ ...authPluginPassThrougConf });
|
|
74
82
|
config.checkSecretKey('12345');
|
|
75
|
-
const auth:
|
|
76
|
-
|
|
83
|
+
const auth: Auth = new Auth(config);
|
|
84
|
+
await auth.init();
|
|
77
85
|
expect(auth).toBeDefined();
|
|
78
86
|
|
|
79
87
|
const callback = jest.fn();
|
|
@@ -89,11 +97,11 @@ describe('AuthTest', () => {
|
|
|
89
97
|
}
|
|
90
98
|
});
|
|
91
99
|
|
|
92
|
-
test('should error truthy non-array', () => {
|
|
93
|
-
const config: Config = new AppConfig(
|
|
100
|
+
test('should error truthy non-array', async () => {
|
|
101
|
+
const config: Config = new AppConfig({ ...authPluginPassThrougConf });
|
|
94
102
|
config.checkSecretKey('12345');
|
|
95
|
-
const auth:
|
|
96
|
-
|
|
103
|
+
const auth: Auth = new Auth(config);
|
|
104
|
+
await auth.init();
|
|
97
105
|
expect(auth).toBeDefined();
|
|
98
106
|
|
|
99
107
|
const callback = jest.fn();
|
|
@@ -107,11 +115,11 @@ describe('AuthTest', () => {
|
|
|
107
115
|
}
|
|
108
116
|
});
|
|
109
117
|
|
|
110
|
-
test('should skip empty array', () => {
|
|
111
|
-
const config: Config = new AppConfig(
|
|
118
|
+
test('should skip empty array', async () => {
|
|
119
|
+
const config: Config = new AppConfig({ ...authPluginPassThrougConf });
|
|
112
120
|
config.checkSecretKey('12345');
|
|
113
|
-
const auth:
|
|
114
|
-
|
|
121
|
+
const auth: Auth = new Auth(config);
|
|
122
|
+
await auth.init();
|
|
115
123
|
expect(auth).toBeDefined();
|
|
116
124
|
|
|
117
125
|
const callback = jest.fn();
|
|
@@ -124,11 +132,11 @@ describe('AuthTest', () => {
|
|
|
124
132
|
expect(callback.mock.calls[0][1]).toBeUndefined();
|
|
125
133
|
});
|
|
126
134
|
|
|
127
|
-
test('should accept valid array', () => {
|
|
128
|
-
const config: Config = new AppConfig(
|
|
135
|
+
test('should accept valid array', async () => {
|
|
136
|
+
const config: Config = new AppConfig({ ...authPluginPassThrougConf });
|
|
129
137
|
config.checkSecretKey('12345');
|
|
130
|
-
const auth:
|
|
131
|
-
|
|
138
|
+
const auth: Auth = new Auth(config);
|
|
139
|
+
await auth.init();
|
|
132
140
|
expect(auth).toBeDefined();
|
|
133
141
|
|
|
134
142
|
const callback = jest.fn();
|
|
@@ -144,4 +152,31 @@ describe('AuthTest', () => {
|
|
|
144
152
|
});
|
|
145
153
|
});
|
|
146
154
|
});
|
|
155
|
+
|
|
156
|
+
describe('test multiple authenticate methods', () => {
|
|
157
|
+
test('should skip falsy values', async () => {
|
|
158
|
+
const config: Config = new AppConfig({
|
|
159
|
+
...getDefaultConfig(),
|
|
160
|
+
plugins: path.join(__dirname, './partials/plugin'),
|
|
161
|
+
auth: {
|
|
162
|
+
success: {},
|
|
163
|
+
'fail-invalid-method': {},
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
config.checkSecretKey('12345');
|
|
167
|
+
const auth: Auth = new Auth(config);
|
|
168
|
+
await auth.init();
|
|
169
|
+
|
|
170
|
+
return new Promise((resolve) => {
|
|
171
|
+
auth.authenticate('foo', 'bar', (err, value) => {
|
|
172
|
+
expect(value).toEqual({
|
|
173
|
+
name: 'foo',
|
|
174
|
+
groups: ['test', '$all', '$authenticated', '@all', '@authenticated', 'all'],
|
|
175
|
+
real_groups: ['test'],
|
|
176
|
+
});
|
|
177
|
+
resolve(value);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
});
|
|
147
182
|
});
|
package/test/helper/plugin.ts
CHANGED
|
@@ -4,21 +4,32 @@ import { getDefaultConfig } from '@verdaccio/config';
|
|
|
4
4
|
|
|
5
5
|
export const authProfileConf = {
|
|
6
6
|
...getDefaultConfig(),
|
|
7
|
+
plugins: path.join(__dirname, '../partials/plugin'),
|
|
7
8
|
auth: {
|
|
8
|
-
|
|
9
|
+
success: {},
|
|
9
10
|
},
|
|
10
11
|
};
|
|
11
12
|
|
|
12
13
|
export const authPluginFailureConf = {
|
|
13
14
|
...getDefaultConfig(),
|
|
15
|
+
plugins: path.join(__dirname, '../partials/plugin'),
|
|
14
16
|
auth: {
|
|
15
|
-
|
|
17
|
+
fail: {},
|
|
16
18
|
},
|
|
17
19
|
};
|
|
18
20
|
|
|
19
21
|
export const authPluginPassThrougConf = {
|
|
20
22
|
...getDefaultConfig(),
|
|
23
|
+
plugins: path.join(__dirname, '../partials/plugin'),
|
|
21
24
|
auth: {
|
|
22
|
-
|
|
25
|
+
passthroug: {},
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const authFailInvalidMethod = {
|
|
30
|
+
...getDefaultConfig(),
|
|
31
|
+
plugins: path.join(__dirname, '../partials/plugin'),
|
|
32
|
+
auth: {
|
|
33
|
+
'fail-invalid-method': {},
|
|
23
34
|
},
|
|
24
35
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const { errorUtils } = require('@verdaccio/core');
|
|
2
|
+
|
|
3
|
+
module.exports = function () {
|
|
4
|
+
return {
|
|
5
|
+
authenticate(user, pass, callback) {
|
|
6
|
+
/* user and pass are used here to forward errors
|
|
7
|
+
and success types respectively for testing purposes */
|
|
8
|
+
callback(errorUtils.getInternalError(), false);
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const { errorUtils } = require('@verdaccio/core');
|
|
2
|
+
|
|
3
|
+
module.exports = function () {
|
|
4
|
+
return {
|
|
5
|
+
authenticateFake(user, pass, callback) {
|
|
6
|
+
/* user and pass are used here to forward errors
|
|
7
|
+
and success types respectively for testing purposes */
|
|
8
|
+
callback(errorUtils.getInternalError(), false);
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
};
|
package/test/partials/plugin/{authenticate.passthroug.js → verdaccio-passthroug/passthroug.js}
RENAMED
|
File without changes
|
|
File without changes
|
package/tsconfig.build.json
CHANGED
package/tsconfig.json
CHANGED
|
@@ -2,25 +2,25 @@
|
|
|
2
2
|
"extends": "../../tsconfig.reference",
|
|
3
3
|
"compilerOptions": {
|
|
4
4
|
"rootDir": "./src",
|
|
5
|
-
"outDir": "./build"
|
|
5
|
+
"outDir": "./build",
|
|
6
|
+
"noImplicitAny": true
|
|
6
7
|
},
|
|
7
8
|
"include": ["src/**/*.ts"],
|
|
8
|
-
"exclude": ["src/**/*.test.ts"],
|
|
9
9
|
"references": [
|
|
10
10
|
{
|
|
11
11
|
"path": "../config"
|
|
12
12
|
},
|
|
13
13
|
{
|
|
14
|
-
"path": "../
|
|
14
|
+
"path": "../plugins/htpasswd"
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
|
-
"path": "../
|
|
17
|
+
"path": "../core/core"
|
|
18
18
|
},
|
|
19
19
|
{
|
|
20
|
-
"path": "../
|
|
20
|
+
"path": "../loaders"
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
|
-
"path": "../
|
|
23
|
+
"path": "../logger"
|
|
24
24
|
},
|
|
25
25
|
{
|
|
26
26
|
"path": "../utils"
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { errorUtils } from '@verdaccio/core';
|
|
2
|
-
|
|
3
|
-
module.exports = function () {
|
|
4
|
-
return {
|
|
5
|
-
authenticate(user, pass, callback) {
|
|
6
|
-
// we return an 500 error, the second argument must be false.
|
|
7
|
-
// https://verdaccio.org/docs/en/dev-plugins#onerror
|
|
8
|
-
callback(errorUtils.getInternalError(), false);
|
|
9
|
-
},
|
|
10
|
-
};
|
|
11
|
-
};
|