@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.
@@ -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: IAuth = new Auth(config);
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: IAuth = new Auth(config);
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 _ from 'lodash';
1
+ import path from 'path';
2
2
 
3
- import { IAuth } from '@verdaccio/auth';
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 be defined', () => {
16
- const config: Config = new AppConfig(_.cloneDeep(authProfileConf));
14
+ test('should init correctly', async () => {
15
+ const config: Config = new AppConfig({ ...authProfileConf });
17
16
  config.checkSecretKey('12345');
18
17
 
19
- const auth: IAuth = new Auth(config);
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(_.cloneDeep(authProfileConf));
34
+ test('should be a success login', async () => {
35
+ const config: Config = new AppConfig({ ...authProfileConf });
28
36
  config.checkSecretKey('12345');
29
- const auth: IAuth = new Auth(config);
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: IAuth = new Auth(config);
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(_.cloneDeep(authPluginPassThrougConf));
80
+ test('should skip falsy values', async () => {
81
+ const config: Config = new AppConfig({ ...authPluginPassThrougConf });
74
82
  config.checkSecretKey('12345');
75
- const auth: IAuth = new Auth(config);
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(_.cloneDeep(authPluginPassThrougConf));
100
+ test('should error truthy non-array', async () => {
101
+ const config: Config = new AppConfig({ ...authPluginPassThrougConf });
94
102
  config.checkSecretKey('12345');
95
- const auth: IAuth = new Auth(config);
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(_.cloneDeep(authPluginPassThrougConf));
118
+ test('should skip empty array', async () => {
119
+ const config: Config = new AppConfig({ ...authPluginPassThrougConf });
112
120
  config.checkSecretKey('12345');
113
- const auth: IAuth = new Auth(config);
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(_.cloneDeep(authPluginPassThrougConf));
135
+ test('should accept valid array', async () => {
136
+ const config: Config = new AppConfig({ ...authPluginPassThrougConf });
129
137
  config.checkSecretKey('12345');
130
- const auth: IAuth = new Auth(config);
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
  });
@@ -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
- [`${path.join(__dirname, '../partials/plugin/authenticate.success')}`]: {},
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
- [`${path.join(__dirname, '../partials/plugin/authenticate.fail.js')}`]: {},
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
- [`${path.join(__dirname, '../partials/plugin/authenticate.passthroug')}`]: {},
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,5 @@
1
+ {
2
+ "name": "verdaccio-fail",
3
+ "main": "fail.js",
4
+ "version": "1.0.0"
5
+ }
@@ -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
+ };
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "verdaccio-fail",
3
+ "main": "fail.js",
4
+ "version": "1.0.0"
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "verdaccio-passthroug",
3
+ "main": "passthroug.js",
4
+ "version": "1.0.0"
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "verdaccio-success",
3
+ "main": "success.js",
4
+ "version": "1.0.0"
5
+ }
@@ -2,8 +2,8 @@
2
2
  "extends": "../../tsconfig.base.json",
3
3
  "compilerOptions": {
4
4
  "rootDir": "./src",
5
- "outDir": "./build"
5
+ "outDir": "./build",
6
+ "noImplicitAny": false
6
7
  },
7
- "include": ["src/**/*"],
8
- "exclude": ["src/**/*.test.ts"]
8
+ "include": ["src/**/*"]
9
9
  }
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": "../core/htpasswd"
14
+ "path": "../plugins/htpasswd"
15
15
  },
16
16
  {
17
- "path": "../loaders"
17
+ "path": "../core/core"
18
18
  },
19
19
  {
20
- "path": "../logger"
20
+ "path": "../loaders"
21
21
  },
22
22
  {
23
- "path": "../mock"
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
- };