diff options
-rw-r--r-- | server/middlewares/validators/config.ts | 18 | ||||
-rw-r--r-- | server/tests/api/check-params/config.ts | 19 | ||||
-rw-r--r-- | server/tests/api/server/config.ts | 4 |
3 files changed, 39 insertions, 2 deletions
diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts index 90108fa82..270ce66f6 100644 --- a/server/middlewares/validators/config.ts +++ b/server/middlewares/validators/config.ts | |||
@@ -2,6 +2,8 @@ import * as express from 'express' | |||
2 | import { body } from 'express-validator/check' | 2 | import { body } from 'express-validator/check' |
3 | import { isUserNSFWPolicyValid, isUserVideoQuotaValid, isUserVideoQuotaDailyValid } from '../../helpers/custom-validators/users' | 3 | import { isUserNSFWPolicyValid, isUserVideoQuotaValid, isUserVideoQuotaDailyValid } from '../../helpers/custom-validators/users' |
4 | import { logger } from '../../helpers/logger' | 4 | import { logger } from '../../helpers/logger' |
5 | import { CustomConfig } from '../../../shared/models/server/custom-config.model' | ||
6 | import { Emailer } from '../../lib/emailer' | ||
5 | import { areValidationErrors } from './utils' | 7 | import { areValidationErrors } from './utils' |
6 | 8 | ||
7 | const customConfigUpdateValidator = [ | 9 | const customConfigUpdateValidator = [ |
@@ -46,11 +48,27 @@ const customConfigUpdateValidator = [ | |||
46 | logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body }) | 48 | logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body }) |
47 | 49 | ||
48 | if (areValidationErrors(req, res)) return | 50 | if (areValidationErrors(req, res)) return |
51 | if (!checkInvalidConfigIfEmailDisabled(req.body as CustomConfig, res)) return | ||
49 | 52 | ||
50 | return next() | 53 | return next() |
51 | } | 54 | } |
52 | ] | 55 | ] |
53 | 56 | ||
57 | // --------------------------------------------------------------------------- | ||
58 | |||
54 | export { | 59 | export { |
55 | customConfigUpdateValidator | 60 | customConfigUpdateValidator |
56 | } | 61 | } |
62 | |||
63 | function checkInvalidConfigIfEmailDisabled (customConfig: CustomConfig, res: express.Response) { | ||
64 | if (Emailer.isEnabled()) return true | ||
65 | |||
66 | if (customConfig.signup.requiresEmailVerification === true) { | ||
67 | res.status(400) | ||
68 | .send({ error: 'Emailer is disabled but you require signup email verification.' }) | ||
69 | .end() | ||
70 | return false | ||
71 | } | ||
72 | |||
73 | return true | ||
74 | } | ||
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts index 07de2b5a5..3895c4f9a 100644 --- a/server/tests/api/check-params/config.ts +++ b/server/tests/api/check-params/config.ts | |||
@@ -167,6 +167,25 @@ describe('Test config API validators', function () { | |||
167 | }) | 167 | }) |
168 | }) | 168 | }) |
169 | 169 | ||
170 | it('Should fail if email disabled and signup requires email verification', async function () { | ||
171 | // opposite scenario - succcess when enable enabled - covered via tests/api/users/user-verification.ts | ||
172 | const newUpdateParams = immutableAssign(updateParams, { | ||
173 | signup: { | ||
174 | enabled: true, | ||
175 | limit: 5, | ||
176 | requiresEmailVerification: true | ||
177 | } | ||
178 | }) | ||
179 | |||
180 | await makePutBodyRequest({ | ||
181 | url: server.url, | ||
182 | path, | ||
183 | fields: newUpdateParams, | ||
184 | token: server.accessToken, | ||
185 | statusCodeExpected: 400 | ||
186 | }) | ||
187 | }) | ||
188 | |||
170 | it('Should success with the correct parameters', async function () { | 189 | it('Should success with the correct parameters', async function () { |
171 | await makePutBodyRequest({ | 190 | await makePutBodyRequest({ |
172 | url: server.url, | 191 | url: server.url, |
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index 0dfe6e4fe..3be1c9431 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts | |||
@@ -81,7 +81,7 @@ function checkUpdatedConfig (data: CustomConfig) { | |||
81 | 81 | ||
82 | expect(data.signup.enabled).to.be.false | 82 | expect(data.signup.enabled).to.be.false |
83 | expect(data.signup.limit).to.equal(5) | 83 | expect(data.signup.limit).to.equal(5) |
84 | expect(data.signup.requiresEmailVerification).to.be.true | 84 | expect(data.signup.requiresEmailVerification).to.be.false |
85 | 85 | ||
86 | expect(data.admin.email).to.equal('superadmin1@example.com') | 86 | expect(data.admin.email).to.equal('superadmin1@example.com') |
87 | expect(data.contactForm.enabled).to.be.false | 87 | expect(data.contactForm.enabled).to.be.false |
@@ -186,7 +186,7 @@ describe('Test config', function () { | |||
186 | signup: { | 186 | signup: { |
187 | enabled: false, | 187 | enabled: false, |
188 | limit: 5, | 188 | limit: 5, |
189 | requiresEmailVerification: true | 189 | requiresEmailVerification: false |
190 | }, | 190 | }, |
191 | admin: { | 191 | admin: { |
192 | email: 'superadmin1@example.com' | 192 | email: 'superadmin1@example.com' |