Skip to content

Commit d81439d

Browse files
committed
chore: misc corrections
- refactor static configuration object used for testing into a common source file - remove duplicated info in readme
1 parent 37c46e6 commit d81439d

File tree

5 files changed

+77
-69
lines changed

5 files changed

+77
-69
lines changed

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ the following:
2222
- If `legacy_mode: false` or undefined (default mode): Gitlab 11.2+
2323
- If `legacy_mode: true`: Gitlab 9.0+
2424

25-
## Node Compatibility
26-
27-
verdaccio-gitlab requires node 8+
28-
2925
## Use it
3026

3127
You need at least node version 8.x.x, codename **carbon**.

test/unit/authcache.spec.js

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
// @flow
22

3-
import type { UserDataGroups } from '../../src/authcache.js';
4-
53
import { AuthCache, UserData } from '../../src/authcache.js';
64
import logger from './partials/logger.js';
7-
8-
9-
const TEST_USER: string = 'myUser';
10-
const TEST_PASS: string = 'myPass';
11-
const TEST_DATA_GROUPS: UserDataGroups = {
12-
publish: ['fooGroup1', 'fooGroup2']
13-
};
14-
const TEST_USER_DATA: UserData = new UserData(TEST_USER, TEST_DATA_GROUPS);
5+
import config from './partials/config';
156

167

178
describe('AuthCache Unit Tests', () => {
@@ -31,19 +22,19 @@ describe('AuthCache Unit Tests', () => {
3122
test('should store and find some user data', () => {
3223
const authCache: AuthCache = new AuthCache(logger);
3324

34-
authCache.storeUser(TEST_USER, TEST_PASS, TEST_USER_DATA);
35-
const returnedData: UserData = authCache.findUser(TEST_USER, TEST_PASS);
25+
authCache.storeUser(config.user, config.pass, config.userData);
26+
const returnedData: UserData = authCache.findUser(config.user, config.pass);
3627

37-
expect(returnedData).toEqual(TEST_USER_DATA);
28+
expect(returnedData).toEqual(config.userData);
3829
});
3930

4031
test('should store and find some user data when ttl is unlimited', () => {
4132
const UNLIMITED_TTL: number = 0;
4233
const authCache: AuthCache = new AuthCache(logger, UNLIMITED_TTL);
4334

44-
authCache.storeUser(TEST_USER, TEST_PASS, TEST_USER_DATA);
45-
const returnedData: UserData = authCache.findUser(TEST_USER, TEST_PASS);
35+
authCache.storeUser(config.user, config.pass, config.userData);
36+
const returnedData: UserData = authCache.findUser(config.user, config.pass);
4637

47-
expect(returnedData).toEqual(TEST_USER_DATA);
38+
expect(returnedData).toEqual(config.userData);
4839
});
4940
});

test/unit/gitlab.spec.js

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,60 @@ import type { Callback, RemoteUser } from '@verdaccio/types';
44
import type { VerdaccioGitlabPackageAccess } from "../../src/gitlab";
55

66
import VerdaccioGitlab from '../../src/gitlab.js';
7-
import { defaultConfig } from './partials/config.js';
8-
import logger from './partials/logger.js';
7+
import config from './partials/config';
98

109
// Do not remove, this mocks the gitlab library
1110
import Gitlab from 'gitlab'; // eslint-disable-line no-unused-vars
1211

1312

14-
const TEST_OPTIONS = {
15-
// $FlowFixMe
16-
config: {},
17-
logger: logger
18-
};
19-
const TEST_USER: string = 'myUser';
20-
const TEST_PASS: string = 'myPass';
21-
const TEST_REMOTE_USER: RemoteUser = {
22-
real_groups: ['myGroup', TEST_USER],
23-
groups: ['myGroup', TEST_USER],
24-
name: TEST_USER
25-
};
26-
2713

2814
describe('Gitlab Auth Plugin Unit Tests', () => {
2915
test('should create a plugin instance', () => {
30-
const verdaccioGitlab: VerdaccioGitlab = new VerdaccioGitlab(defaultConfig, TEST_OPTIONS);
16+
const verdaccioGitlab: VerdaccioGitlab = new VerdaccioGitlab(config.verdaccioGitlabConfig, config.options);
3117

3218
expect(verdaccioGitlab).toBeDefined();
3319
});
3420

3521
test('should authenticate a user', done => {
36-
const verdaccioGitlab: VerdaccioGitlab = new VerdaccioGitlab(defaultConfig, TEST_OPTIONS);
22+
const verdaccioGitlab: VerdaccioGitlab = new VerdaccioGitlab(config.verdaccioGitlabConfig, config.options);
3723

3824
const cb: Callback = (err, data) => {
3925
expect(err).toBeFalsy();
4026
expect(data.sort()).toEqual(['myGroup', 'myUser'].sort());
4127
done();
4228
};
4329

44-
verdaccioGitlab.authenticate(TEST_USER, TEST_PASS, cb);
30+
verdaccioGitlab.authenticate(config.user, config.pass, cb);
4531
});
4632

4733
test('should fail authentication with wrong pass', done => {
48-
const verdaccioGitlab: VerdaccioGitlab = new VerdaccioGitlab(defaultConfig, TEST_OPTIONS);
49-
const wrongPass: string = TEST_PASS + '_wrong';
34+
const verdaccioGitlab: VerdaccioGitlab = new VerdaccioGitlab(config.verdaccioGitlabConfig, config.options);
35+
const wrongPass: string = config.pass + '_wrong';
5036

5137
const cb: Callback = (err, data) => {
5238
expect(err).toBeTruthy();
5339
expect(data).toBeFalsy();
5440
done();
5541
};
5642

57-
verdaccioGitlab.authenticate(TEST_USER, wrongPass, cb);
43+
verdaccioGitlab.authenticate(config.user, wrongPass, cb);
5844
});
5945

6046
test('should fail authentication with non-existing user', done => {
61-
const verdaccioGitlab: VerdaccioGitlab = new VerdaccioGitlab(defaultConfig, TEST_OPTIONS);
62-
const wrongUser: string = TEST_USER + '_wrong';
47+
const verdaccioGitlab: VerdaccioGitlab = new VerdaccioGitlab(config.verdaccioGitlabConfig, config.options);
48+
const wrongUser: string = config.user + '_wrong';
6349

6450
const cb: Callback = (err, data) => {
6551
expect(err).toBeTruthy();
6652
expect(data).toBeFalsy();
6753
done();
6854
};
6955

70-
verdaccioGitlab.authenticate(wrongUser, TEST_PASS, cb);
56+
verdaccioGitlab.authenticate(wrongUser, config.pass, cb);
7157
});
7258

7359
test('should allow access to package based on user group', done => {
74-
const verdaccioGitlab: VerdaccioGitlab = new VerdaccioGitlab(defaultConfig, TEST_OPTIONS);
60+
const verdaccioGitlab: VerdaccioGitlab = new VerdaccioGitlab(config.verdaccioGitlabConfig, config.options);
7561
const _package: VerdaccioGitlabPackageAccess = {
7662
name: '@myGroup/myPackage',
7763
access: ['$authenticated'],
@@ -84,13 +70,13 @@ describe('Gitlab Auth Plugin Unit Tests', () => {
8470
done();
8571
};
8672

87-
verdaccioGitlab.allow_access(TEST_REMOTE_USER, _package, cb);
73+
verdaccioGitlab.allow_access(config.remoteUser, _package, cb);
8874
});
8975

9076
test('should allow access to package based on user name', done => {
91-
const verdaccioGitlab: VerdaccioGitlab = new VerdaccioGitlab(defaultConfig, TEST_OPTIONS);
77+
const verdaccioGitlab: VerdaccioGitlab = new VerdaccioGitlab(config.verdaccioGitlabConfig, config.options);
9278
const _package: VerdaccioGitlabPackageAccess = {
93-
name: TEST_USER,
79+
name: config.user,
9480
access: ['$authenticated'],
9581
gitlab: true
9682
};
@@ -101,11 +87,11 @@ describe('Gitlab Auth Plugin Unit Tests', () => {
10187
done();
10288
};
10389

104-
verdaccioGitlab.allow_access(TEST_REMOTE_USER, _package, cb);
90+
verdaccioGitlab.allow_access(config.remoteUser, _package, cb);
10591
});
10692

10793
test('should deny access to package based on unauthenticated', done => {
108-
const verdaccioGitlab: VerdaccioGitlab = new VerdaccioGitlab(defaultConfig, TEST_OPTIONS);
94+
const verdaccioGitlab: VerdaccioGitlab = new VerdaccioGitlab(config.verdaccioGitlabConfig, config.options);
10995
const unauthenticatedUser: RemoteUser = {
11096
real_groups: [],
11197
groups: [],
@@ -127,7 +113,7 @@ describe('Gitlab Auth Plugin Unit Tests', () => {
127113
});
128114

129115
test('should allow publish of package based on user group', done => {
130-
const verdaccioGitlab: VerdaccioGitlab = new VerdaccioGitlab(defaultConfig, TEST_OPTIONS);
116+
const verdaccioGitlab: VerdaccioGitlab = new VerdaccioGitlab(config.verdaccioGitlabConfig, config.options);
131117
const _package: VerdaccioGitlabPackageAccess = {
132118
name: '@myGroup/myPackage',
133119
gitlab: true
@@ -139,13 +125,13 @@ describe('Gitlab Auth Plugin Unit Tests', () => {
139125
done();
140126
};
141127

142-
verdaccioGitlab.allow_publish(TEST_REMOTE_USER, _package, cb);
128+
verdaccioGitlab.allow_publish(config.remoteUser, _package, cb);
143129
});
144130

145131
test('should allow publish of package based on user name', done => {
146-
const verdaccioGitlab: VerdaccioGitlab = new VerdaccioGitlab(defaultConfig, TEST_OPTIONS);
132+
const verdaccioGitlab: VerdaccioGitlab = new VerdaccioGitlab(config.verdaccioGitlabConfig, config.options);
147133
const _package: VerdaccioGitlabPackageAccess = {
148-
name: TEST_USER,
134+
name: config.user,
149135
gitlab: true
150136
};
151137

@@ -155,18 +141,18 @@ describe('Gitlab Auth Plugin Unit Tests', () => {
155141
done();
156142
};
157143

158-
verdaccioGitlab.allow_publish(TEST_REMOTE_USER, _package, cb);
144+
verdaccioGitlab.allow_publish(config.remoteUser, _package, cb);
159145
});
160146

161147
test('should deny publish of package based on unauthenticated', done => {
162-
const verdaccioGitlab: VerdaccioGitlab = new VerdaccioGitlab(defaultConfig, TEST_OPTIONS);
148+
const verdaccioGitlab: VerdaccioGitlab = new VerdaccioGitlab(config.verdaccioGitlabConfig, config.options);
163149
const unauthenticatedUser: RemoteUser = {
164150
real_groups: [],
165151
groups: [],
166152
name: undefined
167153
};
168154
const _package: VerdaccioGitlabPackageAccess = {
169-
name: TEST_USER,
155+
name: config.user,
170156
gitlab: true
171157
};
172158

@@ -180,7 +166,7 @@ describe('Gitlab Auth Plugin Unit Tests', () => {
180166
});
181167

182168
test('should deny publish of package based on group', done => {
183-
const verdaccioGitlab: VerdaccioGitlab = new VerdaccioGitlab(defaultConfig, TEST_OPTIONS);
169+
const verdaccioGitlab: VerdaccioGitlab = new VerdaccioGitlab(config.verdaccioGitlabConfig, config.options);
184170
const _package: VerdaccioGitlabPackageAccess = {
185171
name: '@anotherGroup/myPackage',
186172
gitlab: true
@@ -192,11 +178,11 @@ describe('Gitlab Auth Plugin Unit Tests', () => {
192178
done();
193179
};
194180

195-
verdaccioGitlab.allow_publish(TEST_REMOTE_USER, _package, cb);
181+
verdaccioGitlab.allow_publish(config.remoteUser, _package, cb);
196182
});
197183

198184
test('should deny publish of package based on user', done => {
199-
const verdaccioGitlab: VerdaccioGitlab = new VerdaccioGitlab(defaultConfig, TEST_OPTIONS);
185+
const verdaccioGitlab: VerdaccioGitlab = new VerdaccioGitlab(config.verdaccioGitlabConfig, config.options);
200186
const _package: VerdaccioGitlabPackageAccess = {
201187
name: 'anotherUser',
202188
gitlab: true
@@ -208,6 +194,6 @@ describe('Gitlab Auth Plugin Unit Tests', () => {
208194
done();
209195
};
210196

211-
verdaccioGitlab.allow_publish(TEST_REMOTE_USER, _package, cb);
197+
verdaccioGitlab.allow_publish(config.remoteUser, _package, cb);
212198
});
213199
});

test/unit/partials/config.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

test/unit/partials/config/index.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//@flow
2+
3+
import type { PluginOptions, RemoteUser } from '@verdaccio/types';
4+
import type { VerdaccioGitlabConfig } from '../../../../src/gitlab.js';
5+
import type { UserDataGroups } from '../../../../src/authcache.js';
6+
7+
import logger from '../logger.js';
8+
import { UserData } from '../../../../src/authcache.js';
9+
10+
11+
const verdaccioGitlabConfig: VerdaccioGitlabConfig = {
12+
url: 'myUrl'
13+
};
14+
15+
const options: PluginOptions = {
16+
// $FlowFixMe
17+
config: {},
18+
logger: logger
19+
};
20+
21+
const user: string = 'myUser';
22+
const pass: string = 'myPass';
23+
const remoteUser: RemoteUser = {
24+
real_groups: ['myGroup', user],
25+
groups: ['myGroup', user],
26+
name: user
27+
};
28+
29+
const userDataGroups: UserDataGroups = {
30+
publish: ['fooGroup1', 'fooGroup2']
31+
};
32+
const userData: UserData = new UserData(user, userDataGroups);
33+
34+
const config = {
35+
verdaccioGitlabConfig: verdaccioGitlabConfig,
36+
options: options,
37+
user: user,
38+
pass: pass,
39+
remoteUser: remoteUser,
40+
userData: userData
41+
}
42+
43+
export default config;

0 commit comments

Comments
 (0)