tests: Use the supertest agent from `common.js` for backend tests

This commit is contained in:
Richard Hansen 2021-02-16 18:35:50 -05:00
parent 5a91cf1b49
commit 7dae5e3db8
10 changed files with 139 additions and 189 deletions

View File

@ -30,9 +30,8 @@ jobs:
- name: Install all dependencies and symlink for ep_etherpad-lite
run: src/bin/installDeps.sh
# configures some settings and runs npm run test
- name: Run the backend tests
run: src/tests/frontend/travis/runnerBackend.sh
run: cd src && npm test
withplugins:
# run on pushes to any branch
@ -84,6 +83,5 @@ jobs:
- name: Install all dependencies and symlink for ep_etherpad-lite
run: src/bin/installDeps.sh
# configures some settings and runs npm run test
- name: Run the backend tests
run: src/tests/frontend/travis/runnerBackend.sh
run: cd src && npm test

View File

@ -64,7 +64,7 @@ jobs:
- "src/bin/installDeps.sh"
- "cd src && npm install && cd -"
script:
- "src/tests/frontend/travis/runnerBackend.sh"
- "cd src && npm test"
- name: "Test the Dockerfile"
install:
- "cd src && npm install && cd -"
@ -107,7 +107,7 @@ jobs:
- *install_plugins
- "cd src && npm install && cd -"
script:
- "src/tests/frontend/travis/runnerBackend.sh"
- "cd src && npm test"
- name: "Test the Dockerfile"
install:
- "cd src && npm install && cd -"

View File

@ -43,9 +43,8 @@ jobs:
cd node_modules/${{github.event.repository.name}}
npm ci
# configures some settings and runs npm run test
- name: Run the backend tests
run: src/tests/frontend/travis/runnerBackend.sh
run: cd src && npm test
##ETHERPAD_NPM_V=1
## NPM configuration automatically created using src/bin/plugins/updateAllPluginsScript.sh

View File

@ -8,10 +8,8 @@
const common = require('../../common');
const fs = require('fs');
const settings = require('../../../../node/utils/Settings');
const supertest = require('supertest');
const api = supertest(`http://${settings.ip}:${settings.port}`);
let agent;
const apiKey = common.apiKey;
let apiVersion = 1;
const testPadId = makeid();
@ -19,10 +17,12 @@ const testPadId = makeid();
const endPoint = (point, version) => `/api/${version || apiVersion}/${point}?apikey=${apiKey}`;
describe(__filename, function () {
before(async function () { agent = await common.init(); });
describe('Connectivity For Character Encoding', function () {
it('can connect', function (done) {
this.timeout(250);
api.get('/api/')
agent.get('/api/')
.expect('Content-Type', /json/)
.expect(200, done);
});
@ -31,7 +31,7 @@ describe(__filename, function () {
describe('API Versioning', function () {
this.timeout(150);
it('finds the version tag', function (done) {
api.get('/api/')
agent.get('/api/')
.expect((res) => {
apiVersion = res.body.currentVersion;
if (!res.body.currentVersion) throw new Error('No version set in API');
@ -47,7 +47,7 @@ describe(__filename, function () {
// This is broken because Etherpad doesn't handle HTTP codes properly see #2343
// If your APIKey is password you deserve to fail all tests anyway
const permErrorURL = `/api/${apiVersion}/createPad?apikey=password&padID=test`;
api.get(permErrorURL)
agent.get(permErrorURL)
.expect(401, done);
});
});
@ -55,7 +55,7 @@ describe(__filename, function () {
describe('createPad', function () {
it('creates a new Pad', function (done) {
this.timeout(150);
api.get(`${endPoint('createPad')}&padID=${testPadId}`)
agent.get(`${endPoint('createPad')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.code !== 0) throw new Error('Unable to create new Pad');
})
@ -68,7 +68,7 @@ describe(__filename, function () {
it('Sets the HTML of a Pad attempting to weird utf8 encoded content', function (done) {
this.timeout(1000);
fs.readFile('tests/backend/specs/api/emojis.html', 'utf8', (err, html) => {
api.post(endPoint('setHTML'))
agent.post(endPoint('setHTML'))
.send({
padID: testPadId,
html,
@ -85,7 +85,7 @@ describe(__filename, function () {
describe('getHTML', function () {
it('get the HTML of Pad with emojis', function (done) {
this.timeout(400);
api.get(`${endPoint('getHTML')}&padID=${testPadId}`)
agent.get(`${endPoint('getHTML')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.data.html.indexOf('&#127484') === -1) {
throw new Error('Unable to get the HTML');

View File

@ -1,10 +1,8 @@
'use strict';
const common = require('../../common');
const settings = require('../../../../node/utils/Settings');
const supertest = require('supertest');
const api = supertest(`http://${settings.ip}:${settings.port}`);
let agent;
const apiKey = common.apiKey;
let apiVersion = 1;
let authorID = '';
@ -14,9 +12,11 @@ const timestamp = Date.now();
const endPoint = (point) => `/api/${apiVersion}/${point}?apikey=${apiKey}`;
describe(__filename, function () {
before(async function () { agent = await common.init(); });
describe('API Versioning', function () {
it('errors if can not connect', function (done) {
api.get('/api/')
agent.get('/api/')
.expect((res) => {
apiVersion = res.body.currentVersion;
if (!res.body.currentVersion) throw new Error('No version set in API');
@ -41,7 +41,7 @@ describe(__filename, function () {
describe('createPad', function () {
this.timeout(400);
it('creates a new Pad', function (done) {
api.get(`${endPoint('createPad')}&padID=${padID}`)
agent.get(`${endPoint('createPad')}&padID=${padID}`)
.expect((res) => {
if (res.body.code !== 0) throw new Error('Unable to create new Pad');
})
@ -53,7 +53,7 @@ describe(__filename, function () {
describe('createAuthor', function () {
this.timeout(100);
it('Creates an author with a name set', function (done) {
api.get(endPoint('createAuthor'))
agent.get(endPoint('createAuthor'))
.expect((res) => {
if (res.body.code !== 0 || !res.body.data.authorID) {
throw new Error('Unable to create author');
@ -68,8 +68,8 @@ describe(__filename, function () {
describe('appendChatMessage', function () {
this.timeout(100);
it('Adds a chat message to the pad', function (done) {
api.get(`${endPoint('appendChatMessage')}&padID=${padID}&text=blalblalbha` +
`&authorID=${authorID}&time=${timestamp}`)
agent.get(`${endPoint('appendChatMessage')}&padID=${padID}&text=blalblalbha` +
`&authorID=${authorID}&time=${timestamp}`)
.expect((res) => {
if (res.body.code !== 0) throw new Error('Unable to create chat message');
})
@ -82,7 +82,7 @@ describe(__filename, function () {
describe('getChatHead', function () {
this.timeout(100);
it('Gets the head of chat', function (done) {
api.get(`${endPoint('getChatHead')}&padID=${padID}`)
agent.get(`${endPoint('getChatHead')}&padID=${padID}`)
.expect((res) => {
if (res.body.data.chatHead !== 0) throw new Error('Chat Head Length is wrong');
@ -96,7 +96,7 @@ describe(__filename, function () {
describe('getChatHistory', function () {
this.timeout(40);
it('Gets Chat History of a Pad', function (done) {
api.get(`${endPoint('getChatHistory')}&padID=${padID}`)
agent.get(`${endPoint('getChatHistory')}&padID=${padID}`)
.expect((res) => {
if (res.body.data.messages.length !== 1) {
throw new Error('Chat History Length is wrong');

View File

@ -7,10 +7,8 @@
*/
const common = require('../../common');
const settings = require('../../../container/loadSettings.js').loadSettings();
const supertest = require('supertest');
const api = supertest(`http://${settings.ip}:${settings.port}`);
let agent;
const apiKey = common.apiKey;
const apiVersion = 1;
@ -228,6 +226,8 @@ const testImports = {
};
describe(__filename, function () {
before(async function () { agent = await common.init(); });
Object.keys(testImports).forEach((testName) => {
describe(testName, function () {
const testPadId = makeid();
@ -239,7 +239,7 @@ describe(__filename, function () {
}
it('createPad', function (done) {
this.timeout(200);
api.get(`${endPoint('createPad')}&padID=${testPadId}`)
agent.get(`${endPoint('createPad')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.code !== 0) throw new Error('Unable to create new Pad');
})
@ -249,7 +249,8 @@ describe(__filename, function () {
it('setHTML', function (done) {
this.timeout(150);
api.get(`${endPoint('setHTML')}&padID=${testPadId}&html=${encodeURIComponent(test.input)}`)
agent.get(`${endPoint('setHTML')}&padID=${testPadId}` +
`&html=${encodeURIComponent(test.input)}`)
.expect((res) => {
if (res.body.code !== 0) throw new Error(`Error:${testName}`);
})
@ -259,7 +260,7 @@ describe(__filename, function () {
it('getHTML', function (done) {
this.timeout(150);
api.get(`${endPoint('getHTML')}&padID=${testPadId}`)
agent.get(`${endPoint('getHTML')}&padID=${testPadId}`)
.expect((res) => {
const gotHtml = res.body.data.html;
if (gotHtml !== test.wantHTML) {
@ -283,7 +284,7 @@ describe(__filename, function () {
it('getText', function (done) {
this.timeout(100);
api.get(`${endPoint('getText')}&padID=${testPadId}`)
agent.get(`${endPoint('getText')}&padID=${testPadId}`)
.expect((res) => {
const gotText = res.body.data.text;
if (gotText !== test.wantText) {

View File

@ -6,21 +6,20 @@
* Section "GLOBAL FUNCTIONS" in src/node/db/API.js
*/
const common = require('../../common');
const settings = require('../../../../node/utils/Settings');
const supertest = require('supertest');
const api = supertest(`http://${settings.ip}:${settings.port}`);
let agent;
const apiKey = common.apiKey;
const apiVersion = '1.2.14';
const endPoint = (point, version) => `/api/${version || apiVersion}/${point}?apikey=${apiKey}`;
describe(__filename, function () {
before(async function () { agent = await common.init(); });
describe('Connectivity for instance-level API tests', function () {
it('can connect', function (done) {
this.timeout(150);
api.get('/api/')
agent.get('/api/')
.expect('Content-Type', /json/)
.expect(200, done);
});
@ -29,7 +28,7 @@ describe(__filename, function () {
describe('getStats', function () {
it('Gets the stats of a running instance', function (done) {
this.timeout(100);
api.get(endPoint('getStats'))
agent.get(endPoint('getStats'))
.expect((res) => {
if (res.body.code !== 0) throw new Error('getStats() failed');

View File

@ -10,11 +10,8 @@
const assert = require('assert').strict;
const async = require('async');
const common = require('../../common');
const settings = require('../../../../node/utils/Settings');
const supertest = require('supertest');
const api = supertest(`http://${settings.ip}:${settings.port}`);
let agent;
const apiKey = common.apiKey;
let apiVersion = 1;
const testPadId = makeid();
@ -50,10 +47,12 @@ const ulSpaceHtml = '<!doctype html><html><body><ul class="bullet"> <li>one</li>
const expectedSpaceHtml = '<!doctype html><html><body><ul class="bullet"><li>one</ul></body></html>';
describe(__filename, function () {
before(async function () { agent = await common.init(); });
describe('Connectivity', function () {
it('can connect', function (done) {
this.timeout(200);
api.get('/api/')
agent.get('/api/')
.expect('Content-Type', /json/)
.expect(200, done);
});
@ -62,7 +61,7 @@ describe(__filename, function () {
describe('API Versioning', function () {
it('finds the version tag', function (done) {
this.timeout(150);
api.get('/api/')
agent.get('/api/')
.expect((res) => {
apiVersion = res.body.currentVersion;
if (!res.body.currentVersion) throw new Error('No version set in API');
@ -78,7 +77,7 @@ describe(__filename, function () {
// This is broken because Etherpad doesn't handle HTTP codes properly see #2343
// If your APIKey is password you deserve to fail all tests anyway
const permErrorURL = `/api/${apiVersion}/createPad?apikey=password&padID=test`;
api.get(permErrorURL)
agent.get(permErrorURL)
.expect(401, done);
});
});
@ -128,7 +127,7 @@ describe(__filename, function () {
describe('deletePad', function () {
it('deletes a Pad', function (done) {
this.timeout(150);
api.get(`${endPoint('deletePad')}&padID=${testPadId}`)
agent.get(`${endPoint('deletePad')}&padID=${testPadId}`)
.expect('Content-Type', /json/)
.expect(200, done); // @TODO: we shouldn't expect 200 here since the pad may not exist
});
@ -137,7 +136,7 @@ describe(__filename, function () {
describe('createPad', function () {
it('creates a new Pad', function (done) {
this.timeout(150);
api.get(`${endPoint('createPad')}&padID=${testPadId}`)
agent.get(`${endPoint('createPad')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.code !== 0) throw new Error('Unable to create new Pad');
})
@ -149,7 +148,7 @@ describe(__filename, function () {
describe('getRevisionsCount', function () {
it('gets revision count of Pad', function (done) {
this.timeout(150);
api.get(`${endPoint('getRevisionsCount')}&padID=${testPadId}`)
agent.get(`${endPoint('getRevisionsCount')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.code !== 0) throw new Error('Unable to get Revision Count');
if (res.body.data.revisions !== 0) throw new Error('Incorrect Revision Count');
@ -162,7 +161,7 @@ describe(__filename, function () {
describe('getSavedRevisionsCount', function () {
it('gets saved revisions count of Pad', function (done) {
this.timeout(150);
api.get(`${endPoint('getSavedRevisionsCount')}&padID=${testPadId}`)
agent.get(`${endPoint('getSavedRevisionsCount')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.code !== 0) throw new Error('Unable to get Saved Revisions Count');
if (res.body.data.savedRevisions !== 0) {
@ -177,7 +176,7 @@ describe(__filename, function () {
describe('listSavedRevisions', function () {
it('gets saved revision list of Pad', function (done) {
this.timeout(150);
api.get(`${endPoint('listSavedRevisions')}&padID=${testPadId}`)
agent.get(`${endPoint('listSavedRevisions')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.code !== 0) throw new Error('Unable to get Saved Revisions List');
assert.deepEqual(res.body.data.savedRevisions, []);
@ -190,7 +189,7 @@ describe(__filename, function () {
describe('getHTML', function () {
it('get the HTML of Pad', function (done) {
this.timeout(150);
api.get(`${endPoint('getHTML')}&padID=${testPadId}`)
agent.get(`${endPoint('getHTML')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.data.html.length <= 1) throw new Error('Unable to get the HTML');
})
@ -202,7 +201,7 @@ describe(__filename, function () {
describe('listAllPads', function () {
it('list all pads', function (done) {
this.timeout(150);
api.get(endPoint('listAllPads'))
agent.get(endPoint('listAllPads'))
.expect((res) => {
if (res.body.data.padIDs.includes(testPadId) !== true) {
throw new Error('Unable to find pad in pad list');
@ -216,7 +215,7 @@ describe(__filename, function () {
describe('deletePad', function () {
it('deletes a Pad', function (done) {
this.timeout(150);
api.get(`${endPoint('deletePad')}&padID=${testPadId}`)
agent.get(`${endPoint('deletePad')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.code !== 0) throw new Error('Pad Deletion failed');
})
@ -228,7 +227,7 @@ describe(__filename, function () {
describe('listAllPads', function () {
it('list all pads', function (done) {
this.timeout(150);
api.get(endPoint('listAllPads'))
agent.get(endPoint('listAllPads'))
.expect((res) => {
if (res.body.data.padIDs.includes(testPadId) !== false) {
throw new Error('Test pad should not be in pads list');
@ -242,7 +241,7 @@ describe(__filename, function () {
describe('getHTML', function () {
it('get the HTML of a Pad -- Should return a failure', function (done) {
this.timeout(150);
api.get(`${endPoint('getHTML')}&padID=${testPadId}`)
agent.get(`${endPoint('getHTML')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.code !== 1) throw new Error('Pad deletion failed');
})
@ -254,7 +253,7 @@ describe(__filename, function () {
describe('createPad', function () {
it('creates a new Pad with text', function (done) {
this.timeout(200);
api.get(`${endPoint('createPad')}&padID=${testPadId}&text=testText`)
agent.get(`${endPoint('createPad')}&padID=${testPadId}&text=testText`)
.expect((res) => {
if (res.body.code !== 0) throw new Error('Pad Creation failed');
})
@ -266,7 +265,7 @@ describe(__filename, function () {
describe('getText', function () {
it('gets the Pad text and expect it to be testText with \n which is a line break', function (done) {
this.timeout(150);
api.get(`${endPoint('getText')}&padID=${testPadId}`)
agent.get(`${endPoint('getText')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.data.text !== 'testText\n') throw new Error('Pad Creation with text');
})
@ -278,7 +277,7 @@ describe(__filename, function () {
describe('setText', function () {
it('creates a new Pad with text', function (done) {
this.timeout(200);
api.post(endPoint('setText'))
agent.post(endPoint('setText'))
.send({
padID: testPadId,
text: 'testTextTwo',
@ -294,7 +293,7 @@ describe(__filename, function () {
describe('getText', function () {
it('gets the Pad text', function (done) {
this.timeout(150);
api.get(`${endPoint('getText')}&padID=${testPadId}`)
agent.get(`${endPoint('getText')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.data.text !== 'testTextTwo\n') throw new Error('Setting Text');
})
@ -306,7 +305,7 @@ describe(__filename, function () {
describe('getRevisionsCount', function () {
it('gets Revision Count of a Pad', function (done) {
this.timeout(150);
api.get(`${endPoint('getRevisionsCount')}&padID=${testPadId}`)
agent.get(`${endPoint('getRevisionsCount')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.data.revisions !== 1) throw new Error('Unable to get text revision count');
})
@ -318,7 +317,7 @@ describe(__filename, function () {
describe('saveRevision', function () {
it('saves Revision', function (done) {
this.timeout(150);
api.get(`${endPoint('saveRevision')}&padID=${testPadId}`)
agent.get(`${endPoint('saveRevision')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.code !== 0) throw new Error('Unable to save Revision');
})
@ -330,7 +329,7 @@ describe(__filename, function () {
describe('getSavedRevisionsCount', function () {
it('gets saved revisions count of Pad', function (done) {
this.timeout(150);
api.get(`${endPoint('getSavedRevisionsCount')}&padID=${testPadId}`)
agent.get(`${endPoint('getSavedRevisionsCount')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.code !== 0) throw new Error('Unable to get Saved Revisions Count');
if (res.body.data.savedRevisions !== 1) {
@ -345,7 +344,7 @@ describe(__filename, function () {
describe('listSavedRevisions', function () {
it('gets saved revision list of Pad', function (done) {
this.timeout(150);
api.get(`${endPoint('listSavedRevisions')}&padID=${testPadId}`)
agent.get(`${endPoint('listSavedRevisions')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.code !== 0) throw new Error('Unable to get Saved Revisions List');
assert.deepEqual(res.body.data.savedRevisions, [1]);
@ -357,7 +356,7 @@ describe(__filename, function () {
describe('padUsersCount', function () {
it('gets User Count of a Pad', function (done) {
this.timeout(150);
api.get(`${endPoint('padUsersCount')}&padID=${testPadId}`)
agent.get(`${endPoint('padUsersCount')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.data.padUsersCount !== 0) throw new Error('Incorrect Pad User count');
})
@ -369,7 +368,7 @@ describe(__filename, function () {
describe('getReadOnlyID', function () {
it('Gets the Read Only ID of a Pad', function (done) {
this.timeout(150);
api.get(`${endPoint('getReadOnlyID')}&padID=${testPadId}`)
agent.get(`${endPoint('getReadOnlyID')}&padID=${testPadId}`)
.expect((res) => {
if (!res.body.data.readOnlyID) throw new Error('No Read Only ID for Pad');
})
@ -381,7 +380,7 @@ describe(__filename, function () {
describe('listAuthorsOfPad', function () {
it('Get Authors of the Pad', function (done) {
this.timeout(150);
api.get(`${endPoint('listAuthorsOfPad')}&padID=${testPadId}`)
agent.get(`${endPoint('listAuthorsOfPad')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.data.authorIDs.length !== 0) {
throw new Error('# of Authors of pad is not 0');
@ -395,7 +394,7 @@ describe(__filename, function () {
describe('getLastEdited', function () {
it('Get When Pad was left Edited', function (done) {
this.timeout(150);
api.get(`${endPoint('getLastEdited')}&padID=${testPadId}`)
agent.get(`${endPoint('getLastEdited')}&padID=${testPadId}`)
.expect((res) => {
if (!res.body.data.lastEdited) {
throw new Error('# of Authors of pad is not 0');
@ -411,7 +410,7 @@ describe(__filename, function () {
describe('setText', function () {
it('creates a new Pad with text', function (done) {
this.timeout(200);
api.post(endPoint('setText'))
agent.post(endPoint('setText'))
.send({
padID: testPadId,
text: 'testTextTwo',
@ -427,7 +426,7 @@ describe(__filename, function () {
describe('getLastEdited', function () {
it('Get When Pad was left Edited', function (done) {
this.timeout(150);
api.get(`${endPoint('getLastEdited')}&padID=${testPadId}`)
agent.get(`${endPoint('getLastEdited')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.data.lastEdited <= lastEdited) {
throw new Error('Editing A Pad is not updating when it was last edited');
@ -441,7 +440,7 @@ describe(__filename, function () {
describe('padUsers', function () {
it('gets User Count of a Pad', function (done) {
this.timeout(150);
api.get(`${endPoint('padUsers')}&padID=${testPadId}`)
agent.get(`${endPoint('padUsers')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.data.padUsers.length !== 0) throw new Error('Incorrect Pad Users');
})
@ -453,7 +452,7 @@ describe(__filename, function () {
describe('deletePad', function () {
it('deletes a Pad', function (done) {
this.timeout(150);
api.get(`${endPoint('deletePad')}&padID=${testPadId}`)
agent.get(`${endPoint('deletePad')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.code !== 0) throw new Error('Pad Deletion failed');
})
@ -468,7 +467,7 @@ describe(__filename, function () {
describe('createPad', function () {
it('creates a new Pad with text', function (done) {
this.timeout(200);
api.get(`${endPoint('createPad')}&padID=${testPadId}`)
agent.get(`${endPoint('createPad')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.code !== 0) throw new Error('Pad Creation failed');
})
@ -480,7 +479,7 @@ describe(__filename, function () {
describe('setText', function () {
it('Sets text on a pad Id', function (done) {
this.timeout(150);
api.post(`${endPoint('setText')}&padID=${testPadId}`)
agent.post(`${endPoint('setText')}&padID=${testPadId}`)
.field({text})
.expect((res) => {
if (res.body.code !== 0) throw new Error('Pad Set Text failed');
@ -493,7 +492,7 @@ describe(__filename, function () {
describe('getText', function () {
it('Gets text on a pad Id', function (done) {
this.timeout(200);
api.get(`${endPoint('getText')}&padID=${testPadId}`)
agent.get(`${endPoint('getText')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.code !== 0) throw new Error('Pad Get Text failed');
if (res.body.data.text !== `${text}\n`) throw new Error('Pad Text not set properly');
@ -506,7 +505,7 @@ describe(__filename, function () {
describe('setText', function () {
it('Sets text on a pad Id including an explicit newline', function (done) {
this.timeout(200);
api.post(`${endPoint('setText')}&padID=${testPadId}`)
agent.post(`${endPoint('setText')}&padID=${testPadId}`)
.field({text: `${text}\n`})
.expect((res) => {
if (res.body.code !== 0) throw new Error('Pad Set Text failed');
@ -519,7 +518,7 @@ describe(__filename, function () {
describe('getText', function () {
it("Gets text on a pad Id and doesn't have an excess newline", function (done) {
this.timeout(150);
api.get(`${endPoint('getText')}&padID=${testPadId}`)
agent.get(`${endPoint('getText')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.code !== 0) throw new Error('Pad Get Text failed');
if (res.body.data.text !== `${text}\n`) throw new Error('Pad Text not set properly');
@ -532,7 +531,7 @@ describe(__filename, function () {
describe('getLastEdited', function () {
it('Gets when pad was last edited', function (done) {
this.timeout(150);
api.get(`${endPoint('getLastEdited')}&padID=${testPadId}`)
agent.get(`${endPoint('getLastEdited')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.lastEdited === 0) throw new Error('Get Last Edited Failed');
})
@ -544,7 +543,7 @@ describe(__filename, function () {
describe('movePad', function () {
it('Move a Pad to a different Pad ID', function (done) {
this.timeout(200);
api.get(`${endPoint('movePad')}&sourceID=${testPadId}&destinationID=${newPadId}&force=true`)
agent.get(`${endPoint('movePad')}&sourceID=${testPadId}&destinationID=${newPadId}&force=true`)
.expect((res) => {
if (res.body.code !== 0) throw new Error('Moving Pad Failed');
})
@ -556,7 +555,7 @@ describe(__filename, function () {
describe('getText', function () {
it('Gets text on a pad Id', function (done) {
this.timeout(150);
api.get(`${endPoint('getText')}&padID=${newPadId}`)
agent.get(`${endPoint('getText')}&padID=${newPadId}`)
.expect((res) => {
if (res.body.data.text !== `${text}\n`) throw new Error('Pad Get Text failed');
})
@ -568,7 +567,8 @@ describe(__filename, function () {
describe('movePad', function () {
it('Move a Pad to a different Pad ID', function (done) {
this.timeout(200);
api.get(`${endPoint('movePad')}&sourceID=${newPadId}&destinationID=${testPadId}&force=false`)
agent.get(`${endPoint('movePad')}&sourceID=${newPadId}&destinationID=${testPadId}` +
'&force=false')
.expect((res) => {
if (res.body.code !== 0) throw new Error('Moving Pad Failed');
})
@ -580,7 +580,7 @@ describe(__filename, function () {
describe('getText', function () {
it('Gets text on a pad Id', function (done) {
this.timeout(150);
api.get(`${endPoint('getText')}&padID=${testPadId}`)
agent.get(`${endPoint('getText')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.data.text !== `${text}\n`) throw new Error('Pad Get Text failed');
})
@ -592,7 +592,7 @@ describe(__filename, function () {
describe('getLastEdited', function () {
it('Gets when pad was last edited', function (done) {
this.timeout(150);
api.get(`${endPoint('getLastEdited')}&padID=${testPadId}`)
agent.get(`${endPoint('getLastEdited')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.lastEdited === 0) throw new Error('Get Last Edited Failed');
})
@ -604,7 +604,7 @@ describe(__filename, function () {
describe('appendText', function () {
it('Append text to a pad Id', function (done) {
this.timeout(150);
api.get(`${endPoint('appendText', '1.2.13')}&padID=${testPadId}&text=hello`)
agent.get(`${endPoint('appendText', '1.2.13')}&padID=${testPadId}&text=hello`)
.expect((res) => {
if (res.body.code !== 0) throw new Error('Pad Append Text failed');
})
@ -616,7 +616,7 @@ describe(__filename, function () {
describe('getText', function () {
it('Gets text on a pad Id', function (done) {
this.timeout(150);
api.get(`${endPoint('getText')}&padID=${testPadId}`)
agent.get(`${endPoint('getText')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.code !== 0) throw new Error('Pad Get Text failed');
if (res.body.data.text !== `${text}hello\n`) {
@ -633,7 +633,7 @@ describe(__filename, function () {
it('Sets the HTML of a Pad attempting to pass ugly HTML', function (done) {
this.timeout(200);
const html = '<div><b>Hello HTML</title></head></div>';
api.post(endPoint('setHTML'))
agent.post(endPoint('setHTML'))
.send({
padID: testPadId,
html,
@ -651,7 +651,7 @@ describe(__filename, function () {
describe('setHTML', function () {
it('Sets the HTML of a Pad with complex nested lists of different types', function (done) {
this.timeout(200);
api.post(endPoint('setHTML'))
agent.post(endPoint('setHTML'))
.send({
padID: testPadId,
html: ulHtml,
@ -667,7 +667,7 @@ describe(__filename, function () {
describe('getHTML', function () {
it('Gets back the HTML of a Pad with complex nested lists of different types', function (done) {
this.timeout(150);
api.get(`${endPoint('getHTML')}&padID=${testPadId}`)
agent.get(`${endPoint('getHTML')}&padID=${testPadId}`)
.expect((res) => {
const receivedHtml = res.body.data.html.replace('<br></body>', '</body>').toLowerCase();
@ -691,7 +691,7 @@ describe(__filename, function () {
describe('setHTML', function () {
it('Sets the HTML of a Pad with white space between list items', function (done) {
this.timeout(200);
api.get(`${endPoint('setHTML')}&padID=${testPadId}&html=${ulSpaceHtml}`)
agent.get(`${endPoint('setHTML')}&padID=${testPadId}&html=${ulSpaceHtml}`)
.expect((res) => {
if (res.body.code !== 0) throw new Error('List HTML cant be imported');
})
@ -703,7 +703,7 @@ describe(__filename, function () {
describe('getHTML', function () {
it('Gets back the HTML of a Pad with complex nested lists of different types', function (done) {
this.timeout(150);
api.get(`${endPoint('getHTML')}&padID=${testPadId}`)
agent.get(`${endPoint('getHTML')}&padID=${testPadId}`)
.expect((res) => {
const receivedHtml = res.body.data.html.replace('<br></body>', '</body>').toLowerCase();
if (receivedHtml !== expectedSpaceHtml) {
@ -730,7 +730,7 @@ describe(__filename, function () {
async.map(
badUrlChars,
(badUrlChar, cb) => {
api.get(`${endPoint('createPad')}&padID=${badUrlChar}`)
agent.get(`${endPoint('createPad')}&padID=${badUrlChar}`)
.expect((res) => {
if (res.body.code !== 1) throw new Error('Pad with bad characters was created');
})
@ -744,8 +744,8 @@ describe(__filename, function () {
describe('copyPad', function () {
it('copies the content of a existent pad', function (done) {
this.timeout(200);
api.get(`${endPoint('copyPad')}&sourceID=${testPadId}&destinationID=${copiedPadId}` +
'&force=true')
agent.get(`${endPoint('copyPad')}&sourceID=${testPadId}&destinationID=${copiedPadId}` +
'&force=true')
.expect((res) => {
if (res.body.code !== 0) throw new Error('Copy Pad Failed');
})
@ -768,8 +768,8 @@ describe(__filename, function () {
it('returns a successful response', function (done) {
this.timeout(200);
api.get(`${endPoint('copyPadWithoutHistory')}&sourceID=${sourcePadId}` +
`&destinationID=${newPad}&force=false`)
agent.get(`${endPoint('copyPadWithoutHistory')}&sourceID=${sourcePadId}` +
`&destinationID=${newPad}&force=false`)
.expect((res) => {
if (res.body.code !== 0) throw new Error('Copy Pad Without History Failed');
})
@ -780,13 +780,13 @@ describe(__filename, function () {
// this test validates if the source pad's text and attributes are kept
it('creates a new pad with the same content as the source pad', function (done) {
this.timeout(200);
api.get(`${endPoint('copyPadWithoutHistory')}&sourceID=${sourcePadId}` +
`&destinationID=${newPad}&force=false`)
agent.get(`${endPoint('copyPadWithoutHistory')}&sourceID=${sourcePadId}` +
`&destinationID=${newPad}&force=false`)
.expect((res) => {
if (res.body.code !== 0) throw new Error('Copy Pad Without History Failed');
})
.end(() => {
api.get(`${endPoint('getHTML')}&padID=${newPad}`)
agent.get(`${endPoint('getHTML')}&padID=${newPad}`)
.expect((res) => {
const receivedHtml =
res.body.data.html.replace('<br><br></body>', '</body>').toLowerCase();
@ -812,8 +812,8 @@ describe(__filename, function () {
const padWithNonExistentGroup = `notExistentGroup$${padId}`;
it('throws an error', function (done) {
this.timeout(150);
api.get(`${endPoint('copyPadWithoutHistory')}&sourceID=${sourcePadId}&` +
`destinationID=${padWithNonExistentGroup}&force=true`)
agent.get(`${endPoint('copyPadWithoutHistory')}&sourceID=${sourcePadId}&` +
`destinationID=${padWithNonExistentGroup}&force=true`)
.expect((res) => {
// code 1, it means an error has happened
if (res.body.code !== 1) throw new Error('It should report an error');
@ -832,8 +832,8 @@ describe(__filename, function () {
context('and force is false', function () {
it('throws an error', function (done) {
this.timeout(150);
api.get(`${endPoint('copyPadWithoutHistory')}&sourceID=${sourcePadId}` +
`&destinationID=${padIdExistent}&force=false`)
agent.get(`${endPoint('copyPadWithoutHistory')}&sourceID=${sourcePadId}` +
`&destinationID=${padIdExistent}&force=false`)
.expect((res) => {
// code 1, it means an error has happened
if (res.body.code !== 1) throw new Error('It should report an error');
@ -845,8 +845,8 @@ describe(__filename, function () {
context('and force is true', function () {
it('returns a successful response', function (done) {
this.timeout(200);
api.get(`${endPoint('copyPadWithoutHistory')}&sourceID=${sourcePadId}` +
`&destinationID=${padIdExistent}&force=true`)
agent.get(`${endPoint('copyPadWithoutHistory')}&sourceID=${sourcePadId}` +
`&destinationID=${padIdExistent}&force=true`)
.expect((res) => {
// code 1, it means an error has happened
if (res.body.code !== 0) {
@ -866,9 +866,9 @@ describe(__filename, function () {
*/
const createNewPadWithHtml = (padId, html, cb) => {
api.get(`${endPoint('createPad')}&padID=${padId}`)
agent.get(`${endPoint('createPad')}&padID=${padId}`)
.end(() => {
api.post(endPoint('setHTML'))
agent.post(endPoint('setHTML'))
.send({
padID: padId,
html,

View File

@ -2,11 +2,8 @@
const assert = require('assert').strict;
const common = require('../../common');
const settings = require('../../../../node/utils/Settings');
const supertest = require('supertest');
const api = supertest(`http://${settings.ip}:${settings.port}`);
let agent;
const apiKey = common.apiKey;
let apiVersion = 1;
let groupID = '';
@ -17,10 +14,12 @@ let padID = makeid();
const endPoint = (point) => `/api/${apiVersion}/${point}?apikey=${apiKey}`;
describe(__filename, function () {
before(async function () { agent = await common.init(); });
describe('API Versioning', function () {
it('errors if can not connect', async function () {
this.timeout(200);
await api.get('/api/')
await agent.get('/api/')
.expect(200)
.expect((res) => {
assert(res.body.currentVersion);
@ -62,7 +61,7 @@ describe(__filename, function () {
describe('API: Group creation and deletion', function () {
it('createGroup', async function () {
this.timeout(100);
await api.get(endPoint('createGroup'))
await agent.get(endPoint('createGroup'))
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
@ -74,7 +73,7 @@ describe(__filename, function () {
it('listSessionsOfGroup for empty group', async function () {
this.timeout(100);
await api.get(`${endPoint('listSessionsOfGroup')}&groupID=${groupID}`)
await agent.get(`${endPoint('listSessionsOfGroup')}&groupID=${groupID}`)
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
@ -85,7 +84,7 @@ describe(__filename, function () {
it('deleteGroup', async function () {
this.timeout(100);
await api.get(`${endPoint('deleteGroup')}&groupID=${groupID}`)
await agent.get(`${endPoint('deleteGroup')}&groupID=${groupID}`)
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
@ -95,7 +94,7 @@ describe(__filename, function () {
it('createGroupIfNotExistsFor', async function () {
this.timeout(100);
await api.get(`${endPoint('createGroupIfNotExistsFor')}&groupMapper=management`)
await agent.get(`${endPoint('createGroupIfNotExistsFor')}&groupMapper=management`)
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
@ -108,7 +107,7 @@ describe(__filename, function () {
// Creates a group, creates 2 sessions, 2 pads and then deletes the group.
it('createGroup', async function () {
this.timeout(100);
await api.get(endPoint('createGroup'))
await agent.get(endPoint('createGroup'))
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
@ -120,7 +119,7 @@ describe(__filename, function () {
it('createAuthor', async function () {
this.timeout(100);
await api.get(endPoint('createAuthor'))
await agent.get(endPoint('createAuthor'))
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
@ -132,8 +131,8 @@ describe(__filename, function () {
it('createSession', async function () {
this.timeout(100);
await api.get(`${endPoint('createSession')
}&authorID=${authorID}&groupID=${groupID}&validUntil=999999999999`)
await agent.get(`${endPoint('createSession')}&authorID=${authorID}&groupID=${groupID}` +
'&validUntil=999999999999')
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
@ -145,8 +144,8 @@ describe(__filename, function () {
it('createSession', async function () {
this.timeout(100);
await api.get(`${endPoint('createSession')
}&authorID=${authorID}&groupID=${groupID}&validUntil=999999999999`)
await agent.get(`${endPoint('createSession')}&authorID=${authorID}&groupID=${groupID}` +
'&validUntil=999999999999')
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
@ -158,7 +157,7 @@ describe(__filename, function () {
it('createGroupPad', async function () {
this.timeout(100);
await api.get(`${endPoint('createGroupPad')}&groupID=${groupID}&padName=x1234567`)
await agent.get(`${endPoint('createGroupPad')}&groupID=${groupID}&padName=x1234567`)
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
@ -168,7 +167,7 @@ describe(__filename, function () {
it('createGroupPad', async function () {
this.timeout(100);
await api.get(`${endPoint('createGroupPad')}&groupID=${groupID}&padName=x12345678`)
await agent.get(`${endPoint('createGroupPad')}&groupID=${groupID}&padName=x12345678`)
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
@ -178,7 +177,7 @@ describe(__filename, function () {
it('deleteGroup', async function () {
this.timeout(100);
await api.get(`${endPoint('deleteGroup')}&groupID=${groupID}`)
await agent.get(`${endPoint('deleteGroup')}&groupID=${groupID}`)
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
@ -191,7 +190,7 @@ describe(__filename, function () {
describe('API: Author creation', function () {
it('createGroup', async function () {
this.timeout(100);
await api.get(endPoint('createGroup'))
await agent.get(endPoint('createGroup'))
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
@ -203,7 +202,7 @@ describe(__filename, function () {
it('createAuthor', async function () {
this.timeout(100);
await api.get(endPoint('createAuthor'))
await agent.get(endPoint('createAuthor'))
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
@ -214,7 +213,7 @@ describe(__filename, function () {
it('createAuthor with name', async function () {
this.timeout(100);
await api.get(`${endPoint('createAuthor')}&name=john`)
await agent.get(`${endPoint('createAuthor')}&name=john`)
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
@ -226,7 +225,7 @@ describe(__filename, function () {
it('createAuthorIfNotExistsFor', async function () {
this.timeout(100);
await api.get(`${endPoint('createAuthorIfNotExistsFor')}&authorMapper=chris`)
await agent.get(`${endPoint('createAuthorIfNotExistsFor')}&authorMapper=chris`)
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
@ -237,7 +236,7 @@ describe(__filename, function () {
it('getAuthorName', async function () {
this.timeout(100);
await api.get(`${endPoint('getAuthorName')}&authorID=${authorID}`)
await agent.get(`${endPoint('getAuthorName')}&authorID=${authorID}`)
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
@ -250,8 +249,8 @@ describe(__filename, function () {
describe('API: Sessions', function () {
it('createSession', async function () {
this.timeout(100);
await api.get(`${endPoint('createSession')
}&authorID=${authorID}&groupID=${groupID}&validUntil=999999999999`)
await agent.get(`${endPoint('createSession')}&authorID=${authorID}&groupID=${groupID}` +
'&validUntil=999999999999')
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
@ -263,7 +262,7 @@ describe(__filename, function () {
it('getSessionInfo', async function () {
this.timeout(100);
await api.get(`${endPoint('getSessionInfo')}&sessionID=${sessionID}`)
await agent.get(`${endPoint('getSessionInfo')}&sessionID=${sessionID}`)
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
@ -276,7 +275,7 @@ describe(__filename, function () {
it('listSessionsOfGroup', async function () {
this.timeout(100);
await api.get(`${endPoint('listSessionsOfGroup')}&groupID=${groupID}`)
await agent.get(`${endPoint('listSessionsOfGroup')}&groupID=${groupID}`)
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
@ -287,7 +286,7 @@ describe(__filename, function () {
it('deleteSession', async function () {
this.timeout(100);
await api.get(`${endPoint('deleteSession')}&sessionID=${sessionID}`)
await agent.get(`${endPoint('deleteSession')}&sessionID=${sessionID}`)
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
@ -297,7 +296,7 @@ describe(__filename, function () {
it('getSessionInfo of deleted session', async function () {
this.timeout(100);
await api.get(`${endPoint('getSessionInfo')}&sessionID=${sessionID}`)
await agent.get(`${endPoint('getSessionInfo')}&sessionID=${sessionID}`)
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
@ -309,7 +308,7 @@ describe(__filename, function () {
describe('API: Group pad management', function () {
it('listPads', async function () {
this.timeout(100);
await api.get(`${endPoint('listPads')}&groupID=${groupID}`)
await agent.get(`${endPoint('listPads')}&groupID=${groupID}`)
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
@ -320,7 +319,7 @@ describe(__filename, function () {
it('createGroupPad', async function () {
this.timeout(100);
await api.get(`${endPoint('createGroupPad')}&groupID=${groupID}&padName=${padID}`)
await agent.get(`${endPoint('createGroupPad')}&groupID=${groupID}&padName=${padID}`)
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
@ -331,7 +330,7 @@ describe(__filename, function () {
it('listPads after creating a group pad', async function () {
this.timeout(100);
await api.get(`${endPoint('listPads')}&groupID=${groupID}`)
await agent.get(`${endPoint('listPads')}&groupID=${groupID}`)
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
@ -344,7 +343,7 @@ describe(__filename, function () {
describe('API: Pad security', function () {
it('getPublicStatus', async function () {
this.timeout(100);
await api.get(`${endPoint('getPublicStatus')}&padID=${padID}`)
await agent.get(`${endPoint('getPublicStatus')}&padID=${padID}`)
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
@ -355,7 +354,7 @@ describe(__filename, function () {
it('setPublicStatus', async function () {
this.timeout(100);
await api.get(`${endPoint('setPublicStatus')}&padID=${padID}&publicStatus=true`)
await agent.get(`${endPoint('setPublicStatus')}&padID=${padID}&publicStatus=true`)
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
@ -365,7 +364,7 @@ describe(__filename, function () {
it('getPublicStatus after changing public status', async function () {
this.timeout(100);
await api.get(`${endPoint('getPublicStatus')}&padID=${padID}`)
await agent.get(`${endPoint('getPublicStatus')}&padID=${padID}`)
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
@ -382,7 +381,7 @@ describe(__filename, function () {
describe('API: Misc', function () {
it('listPadsOfAuthor', async function () {
this.timeout(100);
await api.get(`${endPoint('listPadsOfAuthor')}&authorID=${authorID}`)
await agent.get(`${endPoint('listPadsOfAuthor')}&authorID=${authorID}`)
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {

View File

@ -1,46 +0,0 @@
#!/bin/sh
pecho() { printf %s\\n "$*"; }
log() { pecho "$@"; }
error() { log "ERROR: $@" >&2; }
fatal() { error "$@"; exit 1; }
try() { "$@" || fatal "'$@' failed"; }
# Move to the Etherpad base directory.
MY_DIR=$(try cd "${0%/*}" && try pwd -P) || exit 1
try cd "${MY_DIR}/../../../.."
try sed -e '
s!"soffice":[^,]*!"soffice": "/usr/bin/soffice"!
# Reduce rate limit aggressiveness
s!"max":[^,]*!"max": 100!
s!"points":[^,]*!"points": 1000!
' settings.json.template >settings.json
log "Assuming src/bin/installDeps.sh has already been run"
node src/node/server.js "${@}" &
ep_pid=$!
log "Waiting for Etherpad to accept connections (http://localhost:9001)..."
connected=false
can_connect() {
curl -sSfo /dev/null http://localhost:9001/ || return 1
connected=true
}
now() { date +%s; }
start=$(now)
while [ $(($(now) - $start)) -le 15 ] && ! can_connect; do
sleep 1
done
[ "$connected" = true ] \
|| fatal "Timed out waiting for Etherpad to accept connections"
log "Successfully connected to Etherpad on http://localhost:9001"
log "Running the backend tests..."
try cd src
npm test
exit_code=$?
kill "$ep_pid" && wait "$ep_pid"
log "Done."
exit "$exit_code"