diff --git a/.travis.yml b/.travis.yml index f784dd342..680052c74 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,8 +21,12 @@ jobs: script: - "tests/frontend/travis/runner.sh" - name: "Test the Dockerfile" + install: + - "cd src && npm install && cd -" script: - - "docker build ." + - "docker build -t etherpad:test ." + - "docker run -d -p 9001:9001 etherpad:test && sleep 3" + - "cd src && npm run test-container" notifications: irc: diff --git a/src/package.json b/src/package.json index 5c925007b..926de995e 100644 --- a/src/package.json +++ b/src/package.json @@ -82,7 +82,8 @@ "url": "https://github.com/ether/etherpad-lite.git" }, "scripts": { - "test": "nyc mocha --timeout 5000 ../tests/backend/specs/api" + "test": "nyc mocha --timeout 5000 ../tests/backend/specs/api", + "test-container": "nyc mocha --timeout 5000 ../tests/container/specs/api" }, "version": "1.8.0", "license": "Apache-2.0" diff --git a/tests/backend/loadSettings.js b/tests/backend/loadSettings.js index e1c9ddf31..e1ab27d90 100644 --- a/tests/backend/loadSettings.js +++ b/tests/backend/loadSettings.js @@ -1,3 +1,10 @@ +/* + * ACHTUNG: there is a copied & modified version of this file in + * /tests/container/loadSettings.js + * + * TODO: unify those two files, and merge in a single one. + */ + var jsonminify = require(__dirname+"/../../src/node_modules/jsonminify"); const fs = require('fs'); diff --git a/tests/backend/specs/api/pad.js b/tests/backend/specs/api/pad.js index 269501a01..9eff06562 100644 --- a/tests/backend/specs/api/pad.js +++ b/tests/backend/specs/api/pad.js @@ -1,3 +1,10 @@ +/* + * ACHTUNG: there is a copied & modified version of this file in + * /tests/container/spacs/api/pad.js + * + * TODO: unify those two files, and merge in a single one. + */ + const assert = require('assert'); const supertest = require(__dirname+'/../../../../src/node_modules/supertest'); const fs = require('fs'); @@ -204,7 +211,7 @@ describe('getText', function(){ api.get(endPoint('getText')+"&padID="+testPadId) .expect(function(res){ if(res.body.data.text !== "testText\n") throw new Error("Pad Creation with text") - }) + }) .expect('Content-Type', /json/) .expect(200, done) }); @@ -573,7 +580,7 @@ describe('createPad', function(){ it('errors if pad can be created', function(done) { var badUrlChars = ["/", "%23", "%3F", "%26"]; async.map( - badUrlChars, + badUrlChars, function (badUrlChar, cb) { api.get(endPoint('createPad')+"&padID="+badUrlChar) .expect(function(res){ diff --git a/tests/container/loadSettings.js b/tests/container/loadSettings.js new file mode 100644 index 000000000..4ac445fe9 --- /dev/null +++ b/tests/container/loadSettings.js @@ -0,0 +1,30 @@ +/* + * ACHTUNG: this file was copied & modified from the analogous + * /tests/backend/loadSettings.js + * + * TODO: unify those two files, and merge in a single one. + */ + +var jsonminify = require(__dirname+"/../../src/node_modules/jsonminify"); +const fs = require('fs'); + +function loadSettings(){ + var settingsStr = fs.readFileSync(__dirname+"/../../settings.json.docker").toString(); + // try to parse the settings + try { + if(settingsStr) { + settingsStr = jsonminify(settingsStr).replace(",]","]").replace(",}","}"); + var settings = JSON.parse(settingsStr); + + // custom settings for running in a container + settings.ip = 'localhost'; + settings.port = '9001'; + + return settings; + } + }catch(e){ + console.error("whoops something is bad with settings"); + } +} + +exports.loadSettings = loadSettings; diff --git a/tests/container/specs/api/pad.js b/tests/container/specs/api/pad.js new file mode 100644 index 000000000..f50b79864 --- /dev/null +++ b/tests/container/specs/api/pad.js @@ -0,0 +1,38 @@ +/* + * ACHTUNG: this file was copied & modified from the analogous + * /tests/backend/specs/api/pad.js + * + * TODO: unify those two files, and merge in a single one. + */ + +const supertest = require(__dirname+'/../../../../src/node_modules/supertest'); +const settings = require(__dirname+'/../../loadSettings').loadSettings(); +const api = supertest('http://'+settings.ip+":"+settings.port); + +var apiVersion = 1; + +describe('Connectivity', function(){ + it('can connect', function(done) { + api.get('/api/') + .expect('Content-Type', /json/) + .expect(200, done) + }); +}) + +describe('API Versioning', function(){ + it('finds the version tag', function(done) { + api.get('/api/') + .expect(function(res){ + if (!res.body.currentVersion) throw new Error("No version set in API"); + return; + }) + .expect(200, done) + }); +}) + +describe('Permission', function(){ + it('errors with invalid APIKey', function(done) { + api.get('/api/'+apiVersion+'/createPad?apikey=wrong_password&padID=test') + .expect(401, done) + }); +})