@@ -11,7 +11,7 @@ describe('default configuration', function () {
11
11
it ( 'should use default values if no user-settings.json file exists' , function ( ) {
12
12
const config = require ( '../src/config' ) ;
13
13
config . logConfiguration ( ) ;
14
- const enabledMethods = defaultSettings . authentication . filter ( method => method . enabled ) ;
14
+ const enabledMethods = defaultSettings . authentication . filter ( ( method ) => method . enabled ) ;
15
15
16
16
expect ( config . getAuthMethods ( ) ) . to . deep . equal ( enabledMethods ) ;
17
17
expect ( config . getDatabase ( ) ) . to . be . eql ( defaultSettings . sink [ 0 ] ) ;
@@ -41,26 +41,22 @@ describe('user configuration', function () {
41
41
42
42
beforeEach ( function ( ) {
43
43
delete require . cache [ require . resolve ( '../src/config/env' ) ] ;
44
+ delete require . cache [ require . resolve ( '../src/config' ) ] ;
44
45
oldEnv = { ...process . env } ;
45
46
tempDir = fs . mkdtempSync ( 'gitproxy-test' ) ;
46
47
tempUserFile = path . join ( tempDir , 'test-settings.json' ) ;
47
- require ( '../src/config/file' ) . configFile = tempUserFile ;
48
+ require ( '../src/config/file' ) . setConfigFile ( tempUserFile ) ;
48
49
} ) ;
49
50
50
51
it ( 'should override default settings for authorisedList' , function ( ) {
51
52
const user = {
52
- authorisedList : [
53
- {
54
- project : 'foo' ,
55
- name : 'bar' ,
56
- url : 'https://github.com/foo/bar.git' ,
57
- } ,
58
- ] ,
53
+ authorisedList : [ { project : 'foo' , name : 'bar' , url : 'https://github.com/foo/bar.git' } ] ,
59
54
} ;
60
55
fs . writeFileSync ( tempUserFile , JSON . stringify ( user ) ) ;
61
56
62
57
const config = require ( '../src/config' ) ;
63
- const enabledMethods = defaultSettings . authentication . filter ( method => method . enabled ) ;
58
+ config . initUserConfig ( ) ;
59
+ const enabledMethods = defaultSettings . authentication . filter ( ( method ) => method . enabled ) ;
64
60
65
61
expect ( config . getAuthorisedList ( ) ) . to . be . eql ( user . authorisedList ) ;
66
62
expect ( config . getAuthMethods ( ) ) . to . deep . equal ( enabledMethods ) ;
@@ -69,19 +65,13 @@ describe('user configuration', function () {
69
65
} ) ;
70
66
71
67
it ( 'should override default settings for authentication' , function ( ) {
72
- const user = {
73
- authentication : [
74
- {
75
- type : 'google' ,
76
- enabled : true ,
77
- } ,
78
- ] ,
79
- } ;
68
+ const user = { authentication : [ { type : 'google' , enabled : true } ] } ;
80
69
fs . writeFileSync ( tempUserFile , JSON . stringify ( user ) ) ;
81
70
82
71
const config = require ( '../src/config' ) ;
72
+ config . initUserConfig ( ) ;
83
73
const authMethods = config . getAuthMethods ( ) ;
84
- const googleAuth = authMethods . find ( method => method . type === 'google' ) ;
74
+ const googleAuth = authMethods . find ( ( method ) => method . type === 'google' ) ;
85
75
86
76
expect ( googleAuth ) . to . not . be . undefined ;
87
77
expect ( googleAuth . enabled ) . to . be . true ;
@@ -92,18 +82,12 @@ describe('user configuration', function () {
92
82
} ) ;
93
83
94
84
it ( 'should override default settings for database' , function ( ) {
95
- const user = {
96
- sink : [
97
- {
98
- type : 'postgres' ,
99
- enabled : true ,
100
- } ,
101
- ] ,
102
- } ;
85
+ const user = { sink : [ { type : 'postgres' , enabled : true } ] } ;
103
86
fs . writeFileSync ( tempUserFile , JSON . stringify ( user ) ) ;
104
87
105
88
const config = require ( '../src/config' ) ;
106
- const enabledMethods = defaultSettings . authentication . filter ( method => method . enabled ) ;
89
+ config . initUserConfig ( ) ;
90
+ const enabledMethods = defaultSettings . authentication . filter ( ( method ) => method . enabled ) ;
107
91
108
92
expect ( config . getDatabase ( ) ) . to . be . eql ( user . sink [ 0 ] ) ;
109
93
expect ( config . getDatabase ( ) ) . to . not . be . eql ( defaultSettings . sink [ 0 ] ) ;
@@ -112,30 +96,22 @@ describe('user configuration', function () {
112
96
} ) ;
113
97
114
98
it ( 'should override default settings for SSL certificate' , function ( ) {
115
- const user = {
116
- tls : {
117
- key : 'my-key.pem' ,
118
- cert : 'my-cert.pem' ,
119
- } ,
120
- } ;
99
+ const user = { tls : { key : 'my-key.pem' , cert : 'my-cert.pem' } } ;
121
100
fs . writeFileSync ( tempUserFile , JSON . stringify ( user ) ) ;
122
101
123
102
const config = require ( '../src/config' ) ;
103
+ config . initUserConfig ( ) ;
124
104
125
105
expect ( config . getTLSKeyPemPath ( ) ) . to . be . eql ( user . tls . key ) ;
126
106
expect ( config . getTLSCertPemPath ( ) ) . to . be . eql ( user . tls . cert ) ;
127
107
} ) ;
128
108
129
109
it ( 'should override default settings for rate limiting' , function ( ) {
130
- const limitConfig = {
131
- rateLimit : {
132
- windowMs : 60000 ,
133
- limit : 1500 ,
134
- } ,
135
- } ;
110
+ const limitConfig = { rateLimit : { windowMs : 60000 , limit : 1500 } } ;
136
111
fs . writeFileSync ( tempUserFile , JSON . stringify ( limitConfig ) ) ;
137
112
138
113
const config = require ( '../src/config' ) ;
114
+ config . initUserConfig ( ) ;
139
115
140
116
expect ( config . getRateLimit ( ) . windowMs ) . to . be . eql ( limitConfig . rateLimit . windowMs ) ;
141
117
expect ( config . getRateLimit ( ) . limit ) . to . be . eql ( limitConfig . rateLimit . limit ) ;
@@ -145,68 +121,55 @@ describe('user configuration', function () {
145
121
const user = {
146
122
attestationConfig : {
147
123
questions : [
148
- {
149
- label : 'Testing Label Change' ,
150
- tooltip : {
151
- text : 'Testing Tooltip Change' ,
152
- links : [ ] ,
153
- } ,
154
- } ,
124
+ { label : 'Testing Label Change' , tooltip : { text : 'Testing Tooltip Change' , links : [ ] } } ,
155
125
] ,
156
126
} ,
157
127
} ;
158
128
fs . writeFileSync ( tempUserFile , JSON . stringify ( user ) ) ;
159
129
160
130
const config = require ( '../src/config' ) ;
131
+ config . initUserConfig ( ) ;
161
132
162
133
expect ( config . getAttestationConfig ( ) ) . to . be . eql ( user . attestationConfig ) ;
163
134
} ) ;
164
135
165
136
it ( 'should override default settings for url shortener' , function ( ) {
166
- const user = {
167
- urlShortener : 'https://url-shortener.com' ,
168
- } ;
137
+ const user = { urlShortener : 'https://url-shortener.com' } ;
169
138
fs . writeFileSync ( tempUserFile , JSON . stringify ( user ) ) ;
170
139
171
140
const config = require ( '../src/config' ) ;
141
+ config . initUserConfig ( ) ;
172
142
173
143
expect ( config . getURLShortener ( ) ) . to . be . eql ( user . urlShortener ) ;
174
144
} ) ;
175
145
176
146
it ( 'should override default settings for contact email' , function ( ) {
177
- const user = {
178
- contactEmail :
'[email protected] ' ,
179
- } ;
147
+ const user = { contactEmail :
'[email protected] ' } ;
180
148
fs . writeFileSync ( tempUserFile , JSON . stringify ( user ) ) ;
181
149
182
150
const config = require ( '../src/config' ) ;
151
+ config . initUserConfig ( ) ;
183
152
184
153
expect ( config . getContactEmail ( ) ) . to . be . eql ( user . contactEmail ) ;
185
154
} ) ;
186
155
187
156
it ( 'should override default settings for plugins' , function ( ) {
188
- const user = {
189
- plugins : [ 'plugin1' , 'plugin2' ] ,
190
- } ;
157
+ const user = { plugins : [ 'plugin1' , 'plugin2' ] } ;
191
158
fs . writeFileSync ( tempUserFile , JSON . stringify ( user ) ) ;
192
159
193
160
const config = require ( '../src/config' ) ;
161
+ config . initUserConfig ( ) ;
194
162
195
163
expect ( config . getPlugins ( ) ) . to . be . eql ( user . plugins ) ;
196
164
} ) ;
197
165
198
166
it ( 'should override default settings for sslCertPemPath' , function ( ) {
199
- const user = {
200
- tls : {
201
- enabled : true ,
202
- key : 'my-key.pem' ,
203
- cert : 'my-cert.pem' ,
204
- }
205
- } ;
167
+ const user = { tls : { enabled : true , key : 'my-key.pem' , cert : 'my-cert.pem' } } ;
206
168
207
169
fs . writeFileSync ( tempUserFile , JSON . stringify ( user ) ) ;
208
170
209
171
const config = require ( '../src/config' ) ;
172
+ config . initUserConfig ( ) ;
210
173
211
174
expect ( config . getTLSCertPemPath ( ) ) . to . be . eql ( user . tls . cert ) ;
212
175
expect ( config . getTLSKeyPemPath ( ) ) . to . be . eql ( user . tls . key ) ;
@@ -215,73 +178,58 @@ describe('user configuration', function () {
215
178
216
179
it ( 'should prioritize tls.key and tls.cert over sslKeyPemPath and sslCertPemPath' , function ( ) {
217
180
const user = {
218
- tls : {
219
- enabled : true ,
220
- key : 'good-key.pem' ,
221
- cert : 'good-cert.pem' ,
222
- } ,
181
+ tls : { enabled : true , key : 'good-key.pem' , cert : 'good-cert.pem' } ,
223
182
sslKeyPemPath : 'bad-key.pem' ,
224
183
sslCertPemPath : 'bad-cert.pem' ,
225
184
} ;
226
185
fs . writeFileSync ( tempUserFile , JSON . stringify ( user ) ) ;
227
-
186
+
228
187
const config = require ( '../src/config' ) ;
188
+ config . initUserConfig ( ) ;
229
189
230
190
expect ( config . getTLSCertPemPath ( ) ) . to . be . eql ( user . tls . cert ) ;
231
191
expect ( config . getTLSKeyPemPath ( ) ) . to . be . eql ( user . tls . key ) ;
232
192
expect ( config . getTLSEnabled ( ) ) . to . be . eql ( user . tls . enabled ) ;
233
193
} ) ;
234
194
235
195
it ( 'should use sslKeyPemPath and sslCertPemPath if tls.key and tls.cert are not present' , function ( ) {
236
- const user = {
237
- sslKeyPemPath : 'good-key.pem' ,
238
- sslCertPemPath : 'good-cert.pem' ,
239
- } ;
196
+ const user = { sslKeyPemPath : 'good-key.pem' , sslCertPemPath : 'good-cert.pem' } ;
240
197
fs . writeFileSync ( tempUserFile , JSON . stringify ( user ) ) ;
241
198
242
199
const config = require ( '../src/config' ) ;
200
+ config . initUserConfig ( ) ;
243
201
244
202
expect ( config . getTLSCertPemPath ( ) ) . to . be . eql ( user . sslCertPemPath ) ;
245
203
expect ( config . getTLSKeyPemPath ( ) ) . to . be . eql ( user . sslKeyPemPath ) ;
246
204
expect ( config . getTLSEnabled ( ) ) . to . be . eql ( false ) ;
247
205
} ) ;
248
206
249
207
it ( 'should override default settings for api' , function ( ) {
250
- const user = {
251
- api : {
252
- gitlab : {
253
- baseUrl : 'https://gitlab.com' ,
254
- } ,
255
- } ,
256
- } ;
208
+ const user = { api : { gitlab : { baseUrl : 'https://gitlab.com' } } } ;
257
209
fs . writeFileSync ( tempUserFile , JSON . stringify ( user ) ) ;
258
-
210
+
259
211
const config = require ( '../src/config' ) ;
212
+ config . initUserConfig ( ) ;
260
213
261
214
expect ( config . getAPIs ( ) ) . to . be . eql ( user . api ) ;
262
215
} ) ;
263
216
264
217
it ( 'should override default settings for cookieSecret if env var is used' , function ( ) {
265
218
fs . writeFileSync ( tempUserFile , '{}' ) ;
266
- process . env . GIT_PROXY_COOKIE_SECRET = 'test-cookie-secret'
219
+ process . env . GIT_PROXY_COOKIE_SECRET = 'test-cookie-secret' ;
267
220
268
221
const config = require ( '../src/config' ) ;
222
+ config . initUserConfig ( ) ;
269
223
expect ( config . getCookieSecret ( ) ) . to . equal ( 'test-cookie-secret' ) ;
270
224
} ) ;
271
225
272
226
it ( 'should override default settings for mongo connection string if env var is used' , function ( ) {
273
- const user = {
274
- sink : [
275
- {
276
- type : 'mongo' ,
277
- enabled : true ,
278
- }
279
- ]
280
- } ;
227
+ const user = { sink : [ { type : 'mongo' , enabled : true } ] } ;
281
228
fs . writeFileSync ( tempUserFile , JSON . stringify ( user ) ) ;
282
229
process . env . GIT_PROXY_MONGO_CONNECTION_STRING = 'mongodb://example.com:27017/test' ;
283
230
284
231
const config = require ( '../src/config' ) ;
232
+ config . initUserConfig ( ) ;
285
233
expect ( config . getDatabase ( ) . connectionString ) . to . equal ( 'mongodb://example.com:27017/test' ) ;
286
234
} ) ;
287
235
0 commit comments