refactor chatuser api tests (#2416)
* block and unblock ipv6 explicitly * refactor admin api tests * use sendAdminPayload() for chatuser tests * fix sendAdminRequests * add getAdminResponse() to api test lib/admin.js * some admin apis don't have response body * cleanup test/automated/api/chatusers.test.js * cleanup test/automated/api/chatusers.test.js use getAdminResponse() to access admin apis
This commit is contained in:
parent
e5fef18b1c
commit
fd683f0a72
@ -6,8 +6,13 @@ const fs = require('fs');
|
|||||||
|
|
||||||
const registerChat = require('./lib/chat').registerChat;
|
const registerChat = require('./lib/chat').registerChat;
|
||||||
const sendChatMessage = require('./lib/chat').sendChatMessage;
|
const sendChatMessage = require('./lib/chat').sendChatMessage;
|
||||||
|
const sendAdminRequest = require('./lib/admin').sendAdminRequest;
|
||||||
|
const sendAdminPayload = require('./lib/admin').sendAdminPayload;
|
||||||
|
const getAdminResponse = require('./lib/admin').getAdminResponse;
|
||||||
|
|
||||||
const localIPAddress = '127.0.0.1';
|
|
||||||
|
const localIPAddressV4 = '127.0.0.1';
|
||||||
|
const localIPAddressV6 = '::1';
|
||||||
|
|
||||||
const testVisibilityMessage = {
|
const testVisibilityMessage = {
|
||||||
body: 'message ' + Math.floor(Math.random() * 100),
|
body: 'message ' + Math.floor(Math.random() * 100),
|
||||||
@ -16,31 +21,24 @@ const testVisibilityMessage = {
|
|||||||
|
|
||||||
var userId;
|
var userId;
|
||||||
var accessToken;
|
var accessToken;
|
||||||
test('can register a user', async (done) => {
|
test('register a user', async (done) => {
|
||||||
const registration = await registerChat();
|
const registration = await registerChat();
|
||||||
userId = registration.id;
|
userId = registration.id;
|
||||||
accessToken = registration.accessToken;
|
accessToken = registration.accessToken;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('can send a chat message', async (done) => {
|
test('send a chat message', async (done) => {
|
||||||
sendChatMessage(testVisibilityMessage, accessToken, done);
|
sendChatMessage(testVisibilityMessage, accessToken, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('can set the user as moderator', async (done) => {
|
test('set the user as moderator', async (done) => {
|
||||||
await request
|
const res = await sendAdminPayload('chat/users/setmoderator', { userId: userId, isModerator: true });
|
||||||
.post('/api/admin/chat/users/setmoderator')
|
|
||||||
.send({ userId: userId, isModerator: true })
|
|
||||||
.auth('admin', 'abc123')
|
|
||||||
.expect(200);
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('verify user is a moderator', async (done) => {
|
test('verify user is a moderator', async (done) => {
|
||||||
const response = await request
|
const response = await getAdminResponse('chat/users/moderators');
|
||||||
.get('/api/admin/chat/users/moderators')
|
|
||||||
.auth('admin', 'abc123')
|
|
||||||
.expect(200);
|
|
||||||
const tokenCheck = response.body.filter((user) => user.id === userId);
|
const tokenCheck = response.body.filter((user) => user.id === userId);
|
||||||
expect(tokenCheck).toHaveLength(1);
|
expect(tokenCheck).toHaveLength(1);
|
||||||
|
|
||||||
@ -56,10 +54,7 @@ test('verify user list is populated', async (done) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
ws.on('open', async function open() {
|
ws.on('open', async function open() {
|
||||||
const response = await request
|
const response = await getAdminResponse('chat/clients');
|
||||||
.get('/api/admin/chat/clients')
|
|
||||||
.auth('admin', 'abc123')
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
expect(response.body.length).toBeGreaterThan(0);
|
expect(response.body.length).toBeGreaterThan(0);
|
||||||
|
|
||||||
@ -81,7 +76,7 @@ test('verify user list is populated', async (done) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('can disable a user', async (done) => {
|
test('disable a user', async (done) => {
|
||||||
// To allow for visually being able to see the test hiding the
|
// To allow for visually being able to see the test hiding the
|
||||||
// message add a short delay.
|
// message add a short delay.
|
||||||
await new Promise((r) => setTimeout(r, 1500));
|
await new Promise((r) => setTimeout(r, 1500));
|
||||||
@ -93,31 +88,21 @@ test('can disable a user', async (done) => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
await request
|
const res = await sendAdminPayload('chat/users/setenabled', { userId: userId, enabled: false });
|
||||||
.post('/api/admin/chat/users/setenabled')
|
|
||||||
.send({ userId: userId, enabled: false })
|
|
||||||
.auth('admin', 'abc123')
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
await new Promise((r) => setTimeout(r, 1500));
|
await new Promise((r) => setTimeout(r, 1500));
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('verify user is disabled', async (done) => {
|
test('verify user is disabled', async (done) => {
|
||||||
const response = await request
|
const response = await getAdminResponse('chat/users/disabled');
|
||||||
.get('/api/admin/chat/users/disabled')
|
|
||||||
.auth('admin', 'abc123')
|
|
||||||
.expect(200);
|
|
||||||
const tokenCheck = response.body.filter((user) => user.id === userId);
|
const tokenCheck = response.body.filter((user) => user.id === userId);
|
||||||
expect(tokenCheck).toHaveLength(1);
|
expect(tokenCheck).toHaveLength(1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('verify messages from user are hidden', async (done) => {
|
test('verify messages from user are hidden', async (done) => {
|
||||||
const response = await request
|
const response = await getAdminResponse('chat/messages');
|
||||||
.get('/api/admin/chat/messages')
|
|
||||||
.auth('admin', 'abc123')
|
|
||||||
.expect(200);
|
|
||||||
const message = response.body.filter((obj) => {
|
const message = response.body.filter((obj) => {
|
||||||
return obj.user.id === userId;
|
return obj.user.id === userId;
|
||||||
});
|
});
|
||||||
@ -125,20 +110,13 @@ test('verify messages from user are hidden', async (done) => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('can re-enable a user', async (done) => {
|
test('re-enable a user', async (done) => {
|
||||||
await request
|
const res = await sendAdminPayload('chat/users/setenabled', { userId: userId, enabled: true });
|
||||||
.post('/api/admin/chat/users/setenabled')
|
|
||||||
.send({ userId: userId, enabled: true })
|
|
||||||
.auth('admin', 'abc123')
|
|
||||||
.expect(200);
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('verify user is enabled', async (done) => {
|
test('verify user is enabled', async (done) => {
|
||||||
const response = await request
|
const response = await getAdminResponse('chat/users/disabled');
|
||||||
.get('/api/admin/chat/users/disabled')
|
|
||||||
.auth('admin', 'abc123')
|
|
||||||
.expect(200);
|
|
||||||
const tokenCheck = response.body.filter((user) => user.id === userId);
|
const tokenCheck = response.body.filter((user) => user.id === userId);
|
||||||
expect(tokenCheck).toHaveLength(0);
|
expect(tokenCheck).toHaveLength(0);
|
||||||
|
|
||||||
@ -146,20 +124,15 @@ test('verify user is enabled', async (done) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('ban an ip address', async (done) => {
|
test('ban an ip address', async (done) => {
|
||||||
await request
|
const resIPv4 = await sendAdminRequest('chat/users/ipbans/create', localIPAddressV4);
|
||||||
.post('/api/admin/chat/users/ipbans/create')
|
const resIPv6 = await sendAdminRequest('chat/users/ipbans/create', localIPAddressV6);
|
||||||
.send({ value: localIPAddress })
|
|
||||||
.auth('admin', 'abc123')
|
|
||||||
.expect(200);
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('verify IP address is blocked from the ban', async (done) => {
|
test('verify IP address is blocked from the ban', async (done) => {
|
||||||
const response = await request
|
const response = await getAdminResponse('chat/users/ipbans');
|
||||||
.get(`/api/admin/chat/users/ipbans`)
|
|
||||||
.auth('admin', 'abc123')
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
|
expect(response.body).toHaveLength(2);
|
||||||
expect(onlyLocalIPAddress(response.body)).toBe(true);
|
expect(onlyLocalIPAddress(response.body)).toBe(true);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -170,34 +143,28 @@ test('verify access is denied', async (done) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('remove an ip address ban', async (done) => {
|
test('remove an ip address ban', async (done) => {
|
||||||
await request
|
const resIPv4 = await sendAdminRequest('chat/users/ipbans/remove', localIPAddressV4);
|
||||||
.post('/api/admin/chat/users/ipbans/remove')
|
const resIPv6 = await sendAdminRequest('chat/users/ipbans/remove', localIPAddressV6);
|
||||||
.send({ value: localIPAddress })
|
|
||||||
.auth('admin', 'abc123')
|
|
||||||
.expect(200);
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('verify IP address is no longer banned', async (done) => {
|
test('verify IP address is no longer banned', async (done) => {
|
||||||
const response = await request
|
const response = await getAdminResponse('chat/users/ipbans');
|
||||||
.get(`/api/admin/chat/users/ipbans`)
|
|
||||||
.auth('admin', 'abc123')
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
expect(response.body).toHaveLength(0);
|
expect(response.body).toHaveLength(0);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('verify access is again allowed', async (done) => {
|
test('verify access is allowed after unban', async (done) => {
|
||||||
await request.get(`/api/chat?accessToken=${accessToken}`).expect(200);
|
await request.get(`/api/chat?accessToken=${accessToken}`).expect(200);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// This function expects the local address to be 127.0.0.1 & ::1
|
// This function expects the local address to be localIPAddressV4 & localIPAddressV6
|
||||||
function onlyLocalIPAddress(banInfo) {
|
function onlyLocalIPAddress(banInfo) {
|
||||||
for (let i = 0; i < banInfo.length; i++) {
|
for (let i = 0; i < banInfo.length; i++) {
|
||||||
if ((banInfo[i].ipAddress != "127.0.0.1") && (banInfo[i].ipAddress != "::1")) {
|
if ((banInfo[i].ipAddress != localIPAddressV4) && (banInfo[i].ipAddress != localIPAddressV6)) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,8 @@ var request = require('supertest');
|
|||||||
|
|
||||||
const Random = require('crypto-random');
|
const Random = require('crypto-random');
|
||||||
|
|
||||||
const sendConfigChangeRequest = require('./lib/admin').sendConfigChangeRequest;
|
const sendAdminRequest = require('./lib/admin').sendAdminRequest;
|
||||||
const getAdminConfig = require('./lib/admin').getAdminConfig;
|
const getAdminResponse = require('./lib/admin').getAdminResponse;
|
||||||
const getAdminStatus = require('./lib/admin').getAdminStatus;
|
|
||||||
|
|
||||||
request = request('http://127.0.0.1:8080');
|
request = request('http://127.0.0.1:8080');
|
||||||
|
|
||||||
@ -144,7 +143,7 @@ test('verify default config values', async (done) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('verify default admin configuration', async (done) => {
|
test('verify default admin configuration', async (done) => {
|
||||||
const res = await getAdminConfig();
|
const res = await getAdminResponse('serverconfig');
|
||||||
|
|
||||||
expect(res.body.instanceDetails.name).toBe(defaultServerName);
|
expect(res.body.instanceDetails.name).toBe(defaultServerName);
|
||||||
expect(res.body.instanceDetails.summary).toBe(defaultServerSummary);
|
expect(res.body.instanceDetails.summary).toBe(defaultServerSummary);
|
||||||
@ -181,165 +180,165 @@ test('verify default admin configuration', async (done) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('set server name', async (done) => {
|
test('set server name', async (done) => {
|
||||||
const res = await sendConfigChangeRequest('name', newServerName);
|
const res = await sendAdminRequest('config/name', newServerName);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('set stream title', async (done) => {
|
test('set stream title', async (done) => {
|
||||||
const res = await sendConfigChangeRequest('streamtitle', newStreamTitle);
|
const res = await sendAdminRequest('config/streamtitle', newStreamTitle);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('set server summary', async (done) => {
|
test('set server summary', async (done) => {
|
||||||
const res = await sendConfigChangeRequest('serversummary', newServerSummary);
|
const res = await sendAdminRequest('config/serversummary', newServerSummary);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('set extra page content', async (done) => {
|
test('set extra page content', async (done) => {
|
||||||
const res = await sendConfigChangeRequest('pagecontent', newPageContent);
|
const res = await sendAdminRequest('config/pagecontent', newPageContent);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('set tags', async (done) => {
|
test('set tags', async (done) => {
|
||||||
const res = await sendConfigChangeRequest('tags', newTags);
|
const res = await sendAdminRequest('config/tags', newTags);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('set stream keys', async (done) => {
|
test('set stream keys', async (done) => {
|
||||||
const res = await sendConfigChangeRequest('streamkeys', newStreamKeys);
|
const res = await sendAdminRequest('config/streamkeys', newStreamKeys);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('set latency level', async (done) => {
|
test('set latency level', async (done) => {
|
||||||
const res = await sendConfigChangeRequest(
|
const res = await sendAdminRequest(
|
||||||
'video/streamlatencylevel',
|
'config/video/streamlatencylevel',
|
||||||
latencyLevel
|
latencyLevel
|
||||||
);
|
);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('set video stream output variants', async (done) => {
|
test('set video stream output variants', async (done) => {
|
||||||
const res = await sendConfigChangeRequest('video/streamoutputvariants', [
|
const res = await sendAdminRequest('config/video/streamoutputvariants', [
|
||||||
streamOutputVariants,
|
streamOutputVariants,
|
||||||
]);
|
]);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('set social handles', async (done) => {
|
test('set social handles', async (done) => {
|
||||||
const res = await sendConfigChangeRequest('socialhandles', newSocialHandles);
|
const res = await sendAdminRequest('config/socialhandles', newSocialHandles);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('set s3 configuration', async (done) => {
|
test('set s3 configuration', async (done) => {
|
||||||
const res = await sendConfigChangeRequest('s3', newS3Config);
|
const res = await sendAdminRequest('config/s3', newS3Config);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('set forbidden usernames', async (done) => {
|
test('set forbidden usernames', async (done) => {
|
||||||
const res = await sendConfigChangeRequest(
|
const res = await sendAdminRequest(
|
||||||
'chat/forbiddenusernames',
|
'config/chat/forbiddenusernames',
|
||||||
newForbiddenUsernames
|
newForbiddenUsernames
|
||||||
);
|
);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('set server url', async (done) => {
|
test('set server url', async (done) => {
|
||||||
const res = await sendConfigChangeRequest(
|
const res = await sendAdminRequest(
|
||||||
'serverurl',
|
'config/serverurl',
|
||||||
newYPConfig.instanceUrl
|
newYPConfig.instanceUrl
|
||||||
);
|
);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('set federation username', async (done) => {
|
test('set federation username', async (done) => {
|
||||||
const res = await sendConfigChangeRequest(
|
const res = await sendAdminRequest(
|
||||||
'federation/username',
|
'config/federation/username',
|
||||||
newFederationConfig.username
|
newFederationConfig.username
|
||||||
);
|
);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('set federation goLiveMessage', async (done) => {
|
test('set federation goLiveMessage', async (done) => {
|
||||||
const res = await sendConfigChangeRequest(
|
const res = await sendAdminRequest(
|
||||||
'federation/livemessage',
|
'config/federation/livemessage',
|
||||||
newFederationConfig.goLiveMessage
|
newFederationConfig.goLiveMessage
|
||||||
);
|
);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('toggle private federation mode', async (done) => {
|
test('toggle private federation mode', async (done) => {
|
||||||
const res = await sendConfigChangeRequest(
|
const res = await sendAdminRequest(
|
||||||
'federation/private',
|
'config/federation/private',
|
||||||
newFederationConfig.isPrivate
|
newFederationConfig.isPrivate
|
||||||
);
|
);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('toggle federation engagement', async (done) => {
|
test('toggle federation engagement', async (done) => {
|
||||||
const res = await sendConfigChangeRequest(
|
const res = await sendAdminRequest(
|
||||||
'federation/showengagement',
|
'config/federation/showengagement',
|
||||||
newFederationConfig.showEngagement
|
newFederationConfig.showEngagement
|
||||||
);
|
);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('set federation blocked domains', async (done) => {
|
test('set federation blocked domains', async (done) => {
|
||||||
const res = await sendConfigChangeRequest(
|
const res = await sendAdminRequest(
|
||||||
'federation/blockdomains',
|
'config/federation/blockdomains',
|
||||||
newFederationConfig.blockedDomains
|
newFederationConfig.blockedDomains
|
||||||
);
|
);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('set offline message', async (done) => {
|
test('set offline message', async (done) => {
|
||||||
const res = await sendConfigChangeRequest(
|
const res = await sendAdminRequest(
|
||||||
'offlinemessage',
|
'config/offlinemessage',
|
||||||
newOfflineMessage
|
newOfflineMessage
|
||||||
);
|
);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('set hide viewer count', async (done) => {
|
test('set hide viewer count', async (done) => {
|
||||||
const res = await sendConfigChangeRequest(
|
const res = await sendAdminRequest(
|
||||||
'hideviewercount',
|
'config/hideviewercount',
|
||||||
newHideViewerCount
|
newHideViewerCount
|
||||||
);
|
);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('set custom style values', async (done) => {
|
test('set custom style values', async (done) => {
|
||||||
const res = await sendConfigChangeRequest('appearance', appearanceValues);
|
const res = await sendAdminRequest('config/appearance', appearanceValues);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('enable directory', async (done) => {
|
test('enable directory', async (done) => {
|
||||||
const res = await sendConfigChangeRequest('directoryenabled', true);
|
const res = await sendAdminRequest('config/directoryenabled', true);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('enable federation', async (done) => {
|
test('enable federation', async (done) => {
|
||||||
const res = await sendConfigChangeRequest(
|
const res = await sendAdminRequest(
|
||||||
'federation/enable',
|
'config/federation/enable',
|
||||||
newFederationConfig.enabled
|
newFederationConfig.enabled
|
||||||
);
|
);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('change admin password', async (done) => {
|
test('change admin password', async (done) => {
|
||||||
const res = await sendConfigChangeRequest('adminpass', newAdminPassword);
|
const res = await sendAdminRequest('config/adminpass', newAdminPassword);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('verify admin password change', async (done) => {
|
test('verify admin password change', async (done) => {
|
||||||
const res = await getAdminConfig((adminPassword = newAdminPassword));
|
const res = await getAdminResponse('serverconfig', (adminPassword = newAdminPassword));
|
||||||
|
|
||||||
expect(res.body.adminPassword).toBe(newAdminPassword);
|
expect(res.body.adminPassword).toBe(newAdminPassword);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('reset admin password', async (done) => {
|
test('reset admin password', async (done) => {
|
||||||
const res = await sendConfigChangeRequest(
|
const res = await sendAdminRequest(
|
||||||
'adminpass',
|
'config/adminpass',
|
||||||
defaultAdminPassword,
|
defaultAdminPassword,
|
||||||
(adminPassword = newAdminPassword)
|
(adminPassword = newAdminPassword)
|
||||||
);
|
);
|
||||||
@ -360,7 +359,7 @@ test('verify updated config values', async (done) => {
|
|||||||
|
|
||||||
// Test that the raw video details being broadcasted are coming through
|
// Test that the raw video details being broadcasted are coming through
|
||||||
test('verify admin stream details', async (done) => {
|
test('verify admin stream details', async (done) => {
|
||||||
const res = await getAdminStatus();
|
const res = await getAdminResponse('status');
|
||||||
|
|
||||||
expect(res.body.broadcaster.streamDetails.width).toBe(320);
|
expect(res.body.broadcaster.streamDetails.width).toBe(320);
|
||||||
expect(res.body.broadcaster.streamDetails.height).toBe(180);
|
expect(res.body.broadcaster.streamDetails.height).toBe(180);
|
||||||
@ -373,7 +372,7 @@ test('verify admin stream details', async (done) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('verify updated admin configuration', async (done) => {
|
test('verify updated admin configuration', async (done) => {
|
||||||
const res = await getAdminConfig();
|
const res = await getAdminResponse('serverconfig');
|
||||||
|
|
||||||
expect(res.body.instanceDetails.name).toBe(newServerName);
|
expect(res.body.instanceDetails.name).toBe(newServerName);
|
||||||
expect(res.body.instanceDetails.summary).toBe(newServerSummary);
|
expect(res.body.instanceDetails.summary).toBe(newServerSummary);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
var request = require('supertest');
|
var request = require('supertest');
|
||||||
const jsonfile = require('jsonfile');
|
const jsonfile = require('jsonfile');
|
||||||
const Ajv = require('ajv-draft-04');
|
const Ajv = require('ajv-draft-04');
|
||||||
const sendConfigChangeRequest = require('./lib/admin').sendConfigChangeRequest;
|
const sendAdminRequest = require('./lib/admin').sendAdminRequest;
|
||||||
|
|
||||||
request = request('http://127.0.0.1:8080');
|
request = request('http://127.0.0.1:8080');
|
||||||
|
|
||||||
@ -12,7 +12,7 @@ const serverURL = 'owncast.server.test'
|
|||||||
const fediUsername = 'streamer'
|
const fediUsername = 'streamer'
|
||||||
|
|
||||||
test('disable federation', async (done) => {
|
test('disable federation', async (done) => {
|
||||||
const res = await sendConfigChangeRequest('federation/enable', false);
|
const res = await sendAdminRequest('config/federation/enable', false);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -57,15 +57,15 @@ test('verify responses of /federation/ when federation is disabled', async (done
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('set required parameters and enable federation', async (done) => {
|
test('set required parameters and enable federation', async (done) => {
|
||||||
const res1 = await sendConfigChangeRequest(
|
const res1 = await sendAdminRequest(
|
||||||
'serverurl',
|
'config/serverurl',
|
||||||
serverURL
|
serverURL
|
||||||
);
|
);
|
||||||
const res2 = await sendConfigChangeRequest(
|
const res2 = await sendAdminRequest(
|
||||||
'federation/username',
|
'config/federation/username',
|
||||||
fediUsername
|
fediUsername
|
||||||
);
|
);
|
||||||
const res3 = await sendConfigChangeRequest('federation/enable', true);
|
const res3 = await sendAdminRequest('config/federation/enable', true);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -3,30 +3,22 @@ request = request('http://127.0.0.1:8080');
|
|||||||
|
|
||||||
const defaultAdminPassword = 'abc123';
|
const defaultAdminPassword = 'abc123';
|
||||||
|
|
||||||
async function getAdminConfig(adminPassword = defaultAdminPassword) {
|
async function getAdminResponse(endpoint, adminPassword = defaultAdminPassword) {
|
||||||
|
const url = '/api/admin/' + endpoint;
|
||||||
const res = request
|
const res = request
|
||||||
.get('/api/admin/serverconfig')
|
.get(url)
|
||||||
.auth('admin', adminPassword)
|
.auth('admin', adminPassword)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getAdminStatus(adminPassword = defaultAdminPassword) {
|
async function sendAdminRequest(
|
||||||
const res = request
|
|
||||||
.get('/api/admin/status')
|
|
||||||
.auth('admin', adminPassword)
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function sendConfigChangeRequest(
|
|
||||||
endpoint,
|
endpoint,
|
||||||
value,
|
value,
|
||||||
adminPassword = defaultAdminPassword
|
adminPassword = defaultAdminPassword
|
||||||
) {
|
) {
|
||||||
const url = '/api/admin/config/' + endpoint;
|
const url = '/api/admin/' + endpoint;
|
||||||
const res = await request
|
const res = await request
|
||||||
.post(url)
|
.post(url)
|
||||||
.auth('admin', adminPassword)
|
.auth('admin', adminPassword)
|
||||||
@ -37,24 +29,23 @@ async function sendConfigChangeRequest(
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendConfigChangePayload(
|
async function sendAdminPayload(
|
||||||
endpoint,
|
endpoint,
|
||||||
payload,
|
payload,
|
||||||
adminPassword = defaultAdminPassword
|
adminPassword = defaultAdminPassword
|
||||||
) {
|
) {
|
||||||
const url = '/api/admin/config/' + endpoint;
|
const url = '/api/admin/' + endpoint;
|
||||||
const res = await request
|
const res = await request
|
||||||
.post(url)
|
.post(url)
|
||||||
.auth('admin', adminPassword)
|
.auth('admin', adminPassword)
|
||||||
.send(payload)
|
.send(payload)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
expect(res.body.success).toBe(true);
|
expect(res.body.success).not.toBe(false);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.getAdminConfig = getAdminConfig;
|
module.exports.getAdminResponse = getAdminResponse;
|
||||||
module.exports.getAdminStatus = getAdminStatus;
|
module.exports.sendAdminRequest = sendAdminRequest;
|
||||||
module.exports.sendConfigChangeRequest = sendConfigChangeRequest;
|
module.exports.sendAdminPayload = sendAdminPayload;
|
||||||
module.exports.sendConfigChangePayload = sendConfigChangePayload;
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user