tests: Add security preferences API tests
This commit is contained in:
parent
25b4ef6c1d
commit
676b1c1fc6
@ -111,30 +111,35 @@ export const getSecurityPreferences = async () => {
|
|||||||
return response;
|
return response;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const updateSecurityPreferences = async (preferences: any) => {
|
||||||
|
checkAppIsRunning();
|
||||||
|
|
||||||
|
const adminCookie = await loginUserAsRole(UserRole.ADMIN);
|
||||||
|
const response = await request(app)
|
||||||
|
.put(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/preferences/security`)
|
||||||
|
.set('Cookie', adminCookie)
|
||||||
|
.send(preferences);
|
||||||
|
return response;
|
||||||
|
};
|
||||||
|
|
||||||
export const changeSecurityPreferences = async ({
|
export const changeSecurityPreferences = async ({
|
||||||
usersCanCreateRooms = true,
|
usersCanCreateRooms = true,
|
||||||
authRequired = true,
|
authRequired = true,
|
||||||
authMode = AuthMode.NONE
|
authMode = AuthMode.NONE
|
||||||
}) => {
|
}) => {
|
||||||
checkAppIsRunning();
|
const response = await updateSecurityPreferences({
|
||||||
|
roomCreationPolicy: {
|
||||||
const adminCookie = await loginUserAsRole(UserRole.ADMIN);
|
allowRoomCreation: usersCanCreateRooms,
|
||||||
await request(app)
|
requireAuthentication: authRequired
|
||||||
.put(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/preferences/security`)
|
},
|
||||||
.set('Cookie', adminCookie)
|
authentication: {
|
||||||
.send({
|
authMode: authMode,
|
||||||
roomCreationPolicy: {
|
method: {
|
||||||
allowRoomCreation: usersCanCreateRooms,
|
type: AuthType.SINGLE_USER
|
||||||
requireAuthentication: authRequired
|
|
||||||
},
|
|
||||||
authentication: {
|
|
||||||
authMode: authMode,
|
|
||||||
method: {
|
|
||||||
type: AuthType.SINGLE_USER
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
.expect(200);
|
});
|
||||||
|
expect(response.status).toBe(200);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
import { beforeAll, describe, expect, it } from '@jest/globals';
|
import { beforeAll, describe, expect, it } from '@jest/globals';
|
||||||
import { startTestServer } from '../../../helpers/request-helpers.js';
|
import {
|
||||||
import { getAppearancePreferences, updateAppearancePreferences } from '../../../helpers/request-helpers.js';
|
getAppearancePreferences,
|
||||||
|
startTestServer,
|
||||||
|
updateAppearancePreferences
|
||||||
|
} from '../../../helpers/request-helpers.js';
|
||||||
|
|
||||||
describe('Appearance API Tests', () => {
|
describe('Appearance API Tests', () => {
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
@ -13,6 +16,7 @@ describe('Appearance API Tests', () => {
|
|||||||
expect(response.status).toBe(402);
|
expect(response.status).toBe(402);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Update Appearance Preferences', () => {
|
describe('Update Appearance Preferences', () => {
|
||||||
it('should return 402 status code as it is a PRO feature', async () => {
|
it('should return 402 status code as it is a PRO feature', async () => {
|
||||||
const response = await updateAppearancePreferences({});
|
const response = await updateAppearancePreferences({});
|
||||||
|
|||||||
@ -0,0 +1,229 @@
|
|||||||
|
import { afterEach, beforeAll, describe, expect, it } from '@jest/globals';
|
||||||
|
import { expectValidationError } from '../../../helpers/assertion-helpers.js';
|
||||||
|
import {
|
||||||
|
getSecurityPreferences,
|
||||||
|
startTestServer,
|
||||||
|
updateSecurityPreferences
|
||||||
|
} from '../../../helpers/request-helpers.js';
|
||||||
|
import { AuthMode, AuthType } from '../../../../src/typings/ce/index.js';
|
||||||
|
|
||||||
|
const defaultPreferences = {
|
||||||
|
roomCreationPolicy: {
|
||||||
|
allowRoomCreation: true,
|
||||||
|
requireAuthentication: true
|
||||||
|
},
|
||||||
|
authentication: {
|
||||||
|
authMode: AuthMode.NONE,
|
||||||
|
method: {
|
||||||
|
type: AuthType.SINGLE_USER
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const restoreDefaultSecurityPreferences = async () => {
|
||||||
|
await updateSecurityPreferences(defaultPreferences);
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('Security Preferences API Tests', () => {
|
||||||
|
beforeAll(() => {
|
||||||
|
startTestServer();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
await restoreDefaultSecurityPreferences();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Update security preferences', () => {
|
||||||
|
it('should update security preferences with valid complete data', async () => {
|
||||||
|
const validPreferences = {
|
||||||
|
roomCreationPolicy: {
|
||||||
|
allowRoomCreation: true,
|
||||||
|
requireAuthentication: true
|
||||||
|
},
|
||||||
|
authentication: {
|
||||||
|
authMode: AuthMode.ALL_USERS,
|
||||||
|
method: {
|
||||||
|
type: AuthType.SINGLE_USER
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let response = await updateSecurityPreferences(validPreferences);
|
||||||
|
|
||||||
|
expect(response.status).toBe(200);
|
||||||
|
expect(response.body.message).toBe('Security preferences updated successfully');
|
||||||
|
|
||||||
|
response = await getSecurityPreferences();
|
||||||
|
expect(response.status).toBe(200);
|
||||||
|
expect(response.body).toEqual(validPreferences);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should update security preferences with valid partial data (roomCreationPolicy)', async () => {
|
||||||
|
const validPreferences = {
|
||||||
|
roomCreationPolicy: {
|
||||||
|
allowRoomCreation: false,
|
||||||
|
requireAuthentication: true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let response = await updateSecurityPreferences(validPreferences);
|
||||||
|
|
||||||
|
expect(response.status).toBe(200);
|
||||||
|
expect(response.body.message).toBe('Security preferences updated successfully');
|
||||||
|
|
||||||
|
response = await getSecurityPreferences();
|
||||||
|
expect(response.status).toBe(200);
|
||||||
|
expect(response.body.roomCreationPolicy).toEqual(validPreferences.roomCreationPolicy);
|
||||||
|
expect(response.body.authentication).toEqual(defaultPreferences.authentication);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should update security preferences with valid partial data (authentication)', async () => {
|
||||||
|
const validPreferences = {
|
||||||
|
authentication: {
|
||||||
|
authMode: AuthMode.ALL_USERS,
|
||||||
|
method: {
|
||||||
|
type: AuthType.SINGLE_USER
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let response = await updateSecurityPreferences(validPreferences);
|
||||||
|
|
||||||
|
expect(response.status).toBe(200);
|
||||||
|
expect(response.body.message).toBe('Security preferences updated successfully');
|
||||||
|
|
||||||
|
response = await getSecurityPreferences();
|
||||||
|
expect(response.status).toBe(200);
|
||||||
|
expect(response.body.authentication).toEqual(validPreferences.authentication);
|
||||||
|
expect(response.body.roomCreationPolicy).toEqual(defaultPreferences.roomCreationPolicy);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Update security preferences validation', () => {
|
||||||
|
it('should reject when allowRoomCreation is not a boolean', async () => {
|
||||||
|
const response = await updateSecurityPreferences({
|
||||||
|
roomCreationPolicy: {
|
||||||
|
allowRoomCreation: 'invalid',
|
||||||
|
requireAuthentication: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expectValidationError(
|
||||||
|
response,
|
||||||
|
'roomCreationPolicy.allowRoomCreation',
|
||||||
|
'Expected boolean, received string'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reject when requireAuthentication is not a boolean', async () => {
|
||||||
|
const response = await updateSecurityPreferences({
|
||||||
|
roomCreationPolicy: {
|
||||||
|
allowRoomCreation: true,
|
||||||
|
requireAuthentication: 'invalid'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expectValidationError(
|
||||||
|
response,
|
||||||
|
'roomCreationPolicy.requireAuthentication',
|
||||||
|
'Expected boolean, received string'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reject when allowRoomCreation or requireAuthentication is not provided', async () => {
|
||||||
|
let response = await updateSecurityPreferences({
|
||||||
|
roomCreationPolicy: {
|
||||||
|
allowRoomCreation: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
expectValidationError(response, 'roomCreationPolicy.requireAuthentication', 'Required');
|
||||||
|
|
||||||
|
response = await updateSecurityPreferences({
|
||||||
|
roomCreationPolicy: {
|
||||||
|
requireAuthentication: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
expectValidationError(response, 'roomCreationPolicy.allowRoomCreation', 'Required');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reject when authMode is not a valid enum value', async () => {
|
||||||
|
const response = await updateSecurityPreferences({
|
||||||
|
authentication: {
|
||||||
|
authMode: 'invalid',
|
||||||
|
method: {
|
||||||
|
type: AuthType.SINGLE_USER
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expectValidationError(
|
||||||
|
response,
|
||||||
|
'authentication.authMode',
|
||||||
|
"Invalid enum value. Expected 'none' | 'moderators_only' | 'all_users', received 'invalid'"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reject when authType is not a valid enum value', async () => {
|
||||||
|
const response = await updateSecurityPreferences({
|
||||||
|
authentication: {
|
||||||
|
authMode: AuthMode.NONE,
|
||||||
|
method: {
|
||||||
|
type: 'invalid'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expectValidationError(
|
||||||
|
response,
|
||||||
|
'authentication.method.type',
|
||||||
|
"Invalid enum value. Expected 'single-user', received 'invalid'"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reject when authMode or method.type is not provided', async () => {
|
||||||
|
let response = await updateSecurityPreferences({
|
||||||
|
authentication: {
|
||||||
|
authMode: AuthMode.NONE
|
||||||
|
}
|
||||||
|
});
|
||||||
|
expectValidationError(response, 'authentication.method', 'Required');
|
||||||
|
|
||||||
|
response = await updateSecurityPreferences({
|
||||||
|
authentication: {
|
||||||
|
method: {
|
||||||
|
type: AuthType.SINGLE_USER
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
expectValidationError(response, 'authentication.authMode', 'Required');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reject when roomCreationPolicy is not an object', async () => {
|
||||||
|
const response = await updateSecurityPreferences({
|
||||||
|
roomCreationPolicy: 'invalid'
|
||||||
|
});
|
||||||
|
|
||||||
|
expectValidationError(response, 'roomCreationPolicy', 'Expected object, received string');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reject when authentication is not an object', async () => {
|
||||||
|
const response = await updateSecurityPreferences({
|
||||||
|
authentication: 'invalid'
|
||||||
|
});
|
||||||
|
|
||||||
|
expectValidationError(response, 'authentication', 'Expected object, received string');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reject when both roomCreationPolicy and authentication are not provided', async () => {
|
||||||
|
const response = await updateSecurityPreferences({});
|
||||||
|
|
||||||
|
expectValidationError(response, '', 'At least one field must be provided for the update');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Get security preferences', () => {
|
||||||
|
it('should return security preferences when authenticated as admin', async () => {
|
||||||
|
const response = await getSecurityPreferences();
|
||||||
|
|
||||||
|
expect(response.status).toBe(200);
|
||||||
|
expect(response.body).toEqual(defaultPreferences);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -1,11 +1,11 @@
|
|||||||
import { afterEach, beforeAll, describe, expect, it } from '@jest/globals';
|
import { afterEach, beforeAll, describe, expect, it } from '@jest/globals';
|
||||||
import {
|
|
||||||
startTestServer,
|
|
||||||
updateWebbhookPreferences,
|
|
||||||
getWebbhookPreferences
|
|
||||||
} from '../../../helpers/request-helpers.js';
|
|
||||||
import { expectValidationError } from '../../../helpers/assertion-helpers.js';
|
|
||||||
import { MEET_WEBHOOK_ENABLED, MEET_WEBHOOK_URL } from '../../../../src/environment.js';
|
import { MEET_WEBHOOK_ENABLED, MEET_WEBHOOK_URL } from '../../../../src/environment.js';
|
||||||
|
import { expectValidationError } from '../../../helpers/assertion-helpers.js';
|
||||||
|
import {
|
||||||
|
getWebbhookPreferences,
|
||||||
|
startTestServer,
|
||||||
|
updateWebbhookPreferences
|
||||||
|
} from '../../../helpers/request-helpers.js';
|
||||||
|
|
||||||
const restoreDefaultWebhookPreferences = async () => {
|
const restoreDefaultWebhookPreferences = async () => {
|
||||||
const defaultPreferences = {
|
const defaultPreferences = {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user