From 291e8d3eed88fe714fb74ad897ac2c67347a85ff Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 25 Jul 2017 20:17:28 +0200 Subject: Add ability to limit user registrations --- server/tests/api/check-params/users.js | 8 ++++++- server/tests/api/config.js | 38 ++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 3 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/check-params/users.js b/server/tests/api/check-params/users.js index 2c1189f7a..9e7115da1 100644 --- a/server/tests/api/check-params/users.js +++ b/server/tests/api/check-params/users.js @@ -513,7 +513,13 @@ describe('Test users API validators', function () { password: 'my super password 4' } - requestsUtils.makePostBodyRequest(serverWithRegistrationDisabled.url, registrationPath, serverWithRegistrationDisabled.accessToken, data, done, 400) + requestsUtils.makePostBodyRequest(serverWithRegistrationDisabled.url, registrationPath, serverWithRegistrationDisabled.accessToken, data, done, 403) + }) + }) + + describe('When registering multiple users on a server with users limit', function () { + it('Should fail when after 3 registrations', function (done) { + usersUtils.registerUser(server.url, 'user42', 'super password', 403, done) }) }) diff --git a/server/tests/api/config.js b/server/tests/api/config.js index e79e12823..f2c00f85a 100644 --- a/server/tests/api/config.js +++ b/server/tests/api/config.js @@ -8,6 +8,7 @@ const series = require('async/series') const serversUtils = require('../utils/servers') const configUtils = require('../utils/config') +const usersUtils = require('../utils/users') describe('Test config', function () { let server = null @@ -28,18 +29,51 @@ describe('Test config', function () { ], done) }) - it('Should have a correct config', function (done) { + it('Should have a correct config on a server with registration enabled', function (done) { configUtils.getConfig(server.url, function (err, res) { if (err) throw err const data = res.body - expect(data.signup.enabled).to.be.truthy + expect(data.signup.allowed).to.be.truthy done() }) }) + it('Should have a correct config on a server with registration enabled and a users limit', function (done) { + series([ + function (next) { + usersUtils.registerUser(server.url, 'user1', 'super password', done) + }, + + function (next) { + usersUtils.registerUser(server.url, 'user2', 'super password', done) + }, + + function (next) { + usersUtils.registerUser(server.url, 'user3', 'super password', done) + }, + + function (next) { + usersUtils.registerUser(server.url, 'user4', 'super password', done) + } + + ], function (err) { + if (err) throw err + + configUtils.getConfig(server.url, function (err, res) { + if (err) throw err + + const data = res.body + + expect(data.signup.allowed).to.be.truthy + + done() + }) + }) + }) + after(function (done) { process.kill(-server.app.pid) -- cgit v1.2.3