Add more signup limit tests
This commit is contained in:
parent
4e4c23c5b8
commit
9436936cf6
|
@ -1,7 +1,15 @@
|
||||||
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
|
import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
|
||||||
import { omit } from '@shared/core-utils'
|
import { omit } from '@shared/core-utils'
|
||||||
import { HttpStatusCode, UserRole } from '@shared/models'
|
import { HttpStatusCode, UserRole } from '@shared/models'
|
||||||
import { cleanupTests, createSingleServer, makePostBodyRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
|
import {
|
||||||
|
cleanupTests,
|
||||||
|
createSingleServer,
|
||||||
|
makePostBodyRequest,
|
||||||
|
PeerTubeServer,
|
||||||
|
setAccessTokensToServers,
|
||||||
|
setDefaultAccountAvatar,
|
||||||
|
setDefaultChannelAvatar
|
||||||
|
} from '@shared/server-commands'
|
||||||
|
|
||||||
describe('Test registrations API validators', function () {
|
describe('Test registrations API validators', function () {
|
||||||
let server: PeerTubeServer
|
let server: PeerTubeServer
|
||||||
|
@ -16,6 +24,9 @@ describe('Test registrations API validators', function () {
|
||||||
server = await createSingleServer(1)
|
server = await createSingleServer(1)
|
||||||
|
|
||||||
await setAccessTokensToServers([ server ])
|
await setAccessTokensToServers([ server ])
|
||||||
|
await setDefaultAccountAvatar([ server ])
|
||||||
|
await setDefaultChannelAvatar([ server ])
|
||||||
|
|
||||||
await server.config.enableSignup(false);
|
await server.config.enableSignup(false);
|
||||||
|
|
||||||
({ token: moderatorToken } = await server.users.generate('moderator', UserRole.MODERATOR));
|
({ token: moderatorToken } = await server.users.generate('moderator', UserRole.MODERATOR));
|
||||||
|
@ -37,7 +48,10 @@ describe('Test registrations API validators', function () {
|
||||||
describe('When registering a new user or requesting user registration', function () {
|
describe('When registering a new user or requesting user registration', function () {
|
||||||
|
|
||||||
async function check (fields: any, expectedStatus = HttpStatusCode.BAD_REQUEST_400) {
|
async function check (fields: any, expectedStatus = HttpStatusCode.BAD_REQUEST_400) {
|
||||||
|
await server.config.enableSignup(false)
|
||||||
await makePostBodyRequest({ url: server.url, path: registrationPath, fields, expectedStatus })
|
await makePostBodyRequest({ url: server.url, path: registrationPath, fields, expectedStatus })
|
||||||
|
|
||||||
|
await server.config.enableSignup(true)
|
||||||
await makePostBodyRequest({ url: server.url, path: registrationRequestPath, fields, expectedStatus })
|
await makePostBodyRequest({ url: server.url, path: registrationRequestPath, fields, expectedStatus })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +152,7 @@ describe('Test registrations API validators', function () {
|
||||||
it('Should fail on a server with registration disabled', async function () {
|
it('Should fail on a server with registration disabled', async function () {
|
||||||
this.timeout(60000)
|
this.timeout(60000)
|
||||||
|
|
||||||
await server.config.updateCustomSubConfig({
|
await server.config.updateExistingSubConfig({
|
||||||
newConfig: {
|
newConfig: {
|
||||||
signup: {
|
signup: {
|
||||||
enabled: false
|
enabled: false
|
||||||
|
@ -159,15 +173,32 @@ describe('Test registrations API validators', function () {
|
||||||
|
|
||||||
const { total } = await server.users.list()
|
const { total } = await server.users.list()
|
||||||
|
|
||||||
await server.config.updateCustomSubConfig({ newConfig: { signup: { limit: total } } })
|
await server.config.enableSignup(false, total)
|
||||||
|
|
||||||
await server.registrations.register({ username: 'user42', expectedStatus: HttpStatusCode.FORBIDDEN_403 })
|
await server.registrations.register({ username: 'user42', expectedStatus: HttpStatusCode.FORBIDDEN_403 })
|
||||||
|
|
||||||
|
await server.config.enableSignup(true, total)
|
||||||
await server.registrations.requestRegistration({
|
await server.registrations.requestRegistration({
|
||||||
username: 'user42',
|
username: 'user42',
|
||||||
registrationReason: 'reason',
|
registrationReason: 'reason',
|
||||||
expectedStatus: HttpStatusCode.FORBIDDEN_403
|
expectedStatus: HttpStatusCode.FORBIDDEN_403
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Should succeed if the user limit is not reached', async function () {
|
||||||
|
this.timeout(60000)
|
||||||
|
|
||||||
|
const { total } = await server.users.list()
|
||||||
|
|
||||||
|
await server.config.enableSignup(false, total + 1)
|
||||||
|
await server.registrations.register({ username: 'user43', expectedStatus: HttpStatusCode.NO_CONTENT_204 })
|
||||||
|
|
||||||
|
await server.config.enableSignup(true, total + 2)
|
||||||
|
await server.registrations.requestRegistration({
|
||||||
|
username: 'user44',
|
||||||
|
registrationReason: 'reason',
|
||||||
|
expectedStatus: HttpStatusCode.OK_200
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('On direct registration', function () {
|
describe('On direct registration', function () {
|
||||||
|
|
|
@ -31,13 +31,13 @@ export class ConfigCommand extends AbstractCommand {
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
enableSignup (requiresApproval: boolean) {
|
enableSignup (requiresApproval: boolean, limit = -1) {
|
||||||
return this.updateExistingSubConfig({
|
return this.updateExistingSubConfig({
|
||||||
newConfig: {
|
newConfig: {
|
||||||
signup: {
|
signup: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
requiresApproval,
|
requiresApproval,
|
||||||
limit: -1
|
limit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue