Bring test deps up to date

This commit is contained in:
Johannes Zellner 2019-11-14 16:45:34 +01:00
parent 5b625519c1
commit b72d7ad682
3 changed files with 292 additions and 453 deletions

593
test/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -8,16 +8,12 @@
}, },
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"devDependencies": { "dependencies": {
"chromedriver": "^78.0.1", "selenium-webdriver": "^3.6.0",
"chromedriver": "^76.0.1",
"expect.js": "^0.3.1", "expect.js": "^0.3.1",
"mocha": "^6.2.2", "mocha": "^6.2.2",
"rimraf": "^3.0.0", "rimraf": "^3.0.0",
"superagent": "^5.1.0" "superagent": "^5.1.0"
},
"dependencies": {
"selenium-server-standalone-jar": "^3.141.59",
"selenium-webdriver": "^3.6.0",
"superagent": "^1.8.5"
} }
} }

View File

@ -9,49 +9,45 @@
'use strict'; 'use strict';
require('chromedriver');
var execSync = require('child_process').execSync, var execSync = require('child_process').execSync,
expect = require('expect.js'), expect = require('expect.js'),
fs = require('fs'), fs = require('fs'),
path = require('path'), path = require('path'),
rimraf = require('rimraf'), rimraf = require('rimraf'),
superagent = require('superagent'); superagent = require('superagent'),
{ Builder, By, until } = require('selenium-webdriver'),
{ Options } = require('selenium-webdriver/chrome');
var by = require('selenium-webdriver').By, if (!process.env.USERNAME || !process.env.PASSWORD || !process.env.EMAIL) {
until = require('selenium-webdriver').until, console.log('USERNAME, PASSWORD and EMAIL env vars need to be set');
Builder = require('selenium-webdriver').Builder; process.exit(1);
}
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
describe('Application life cycle test', function () { describe('Application life cycle test', function () {
this.timeout(0); this.timeout(0);
var server, browser = new Builder().forBrowser('chrome').build();
var TIMEOUT = parseInt(process.env.TIMEOUT, 10) || 5000;
var EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
var LOCATION = 'test'; var LOCATION = 'test';
var SSH_PORT = 29420; var SSH_PORT = 29420;
var browser;
var app;
var token;
var repodir = '/tmp/testrepo'; var repodir = '/tmp/testrepo';
var app, reponame = 'testrepo'; var reponame = 'testrepo';
var username = process.env.USERNAME; var username = process.env.USERNAME;
var password = process.env.PASSWORD; var password = process.env.PASSWORD;
var TIMEOUT = parseInt(process.env.TIMEOUT, 10) || 5000; var email = process.env.EMAIL;
var email = process.env.EMAIL, token;
before(function (done) { before(function () {
if (!process.env.USERNAME) return done(new Error('USERNAME env var not set')); browser = new Builder().forBrowser('chrome').setChromeOptions(new Options().windowSize({ width: 1280, height: 1024 })).build();
if (!process.env.PASSWORD) return done(new Error('PASSWORD env var not set'));
if (!process.env.EMAIL) return done(new Error('EMAIL env var not set'));
var seleniumJar= require('selenium-server-standalone-jar');
var SeleniumServer = require('selenium-webdriver/remote').SeleniumServer;
server = new SeleniumServer(seleniumJar.path, { port: 4444 });
server.start();
done();
}); });
after(function (done) { after(function (done) {
browser.quit(); browser.quit();
server.stop();
rimraf.sync(repodir); rimraf.sync(repodir);
done(); done();
}); });
@ -74,14 +70,14 @@ describe('Application life cycle test', function () {
function setAvatarOld(done) { function setAvatarOld(done) {
browser.get('https://' + app.fqdn + '/user/settings/avatar').then(function () { browser.get('https://' + app.fqdn + '/user/settings/avatar').then(function () {
return browser.findElement(by.xpath('//input[@type="file" and @name="avatar"]')).sendKeys(path.resolve(__dirname, '../logo.png')); return browser.findElement(By.xpath('//input[@type="file" and @name="avatar"]')).sendKeys(path.resolve(__dirname, '../logo.png'));
}).then(function () { }).then(function () {
return browser.findElement(by.xpath('//button[contains(text(), "Update Avatar Setting")]')).click(); return browser.findElement(By.xpath('//button[contains(text(), "Update Avatar Setting")]')).click();
}).then(function () { }).then(function () {
if (app.manifest.version === '1.0.3') { if (app.manifest.version === '1.0.3') {
return browser.wait(until.elementLocated(by.xpath('//p[contains(text(),"updated successfully")]')), TIMEOUT); return browser.wait(until.elementLocated(By.xpath('//p[contains(text(),"updated successfully")]')), TIMEOUT);
} else { } else {
return browser.wait(until.elementLocated(by.xpath('//p[contains(text(),"Your avatar setting has been updated.")]')), TIMEOUT); return browser.wait(until.elementLocated(By.xpath('//p[contains(text(),"Your avatar setting has been updated.")]')), TIMEOUT);
} }
}).then(function () { }).then(function () {
done(); done();
@ -92,16 +88,16 @@ describe('Application life cycle test', function () {
if (app.manifest.version === '1.5.4') return setAvatarOld(done); if (app.manifest.version === '1.5.4') return setAvatarOld(done);
browser.get('https://' + app.fqdn + '/user/settings').then(function () { browser.get('https://' + app.fqdn + '/user/settings').then(function () {
var button = browser.findElement(by.xpath('//label[contains(text(), "Use Custom Avatar")]')); var button = browser.findElement(By.xpath('//label[contains(text(), "Use Custom Avatar")]'));
return browser.executeScript('arguments[0].scrollIntoView(false)', button); return browser.executeScript('arguments[0].scrollIntoView(false)', button);
}).then(function () { }).then(function () {
return browser.findElement(by.xpath('//label[contains(text(), "Use Custom Avatar")]')).click(); return browser.findElement(By.xpath('//label[contains(text(), "Use Custom Avatar")]')).click();
}).then(function () { }).then(function () {
return browser.findElement(by.xpath('//input[@type="file" and @name="avatar"]')).sendKeys(path.resolve(__dirname, '../logo.png')); return browser.findElement(By.xpath('//input[@type="file" and @name="avatar"]')).sendKeys(path.resolve(__dirname, '../logo.png'));
}).then(function () { }).then(function () {
return browser.findElement(by.xpath('//button[contains(text(), "Update Avatar")]')).click(); return browser.findElement(By.xpath('//button[contains(text(), "Update Avatar")]')).click();
}).then(function () { }).then(function () {
return browser.wait(until.elementLocated(by.xpath('//p[contains(text(),"Your avatar has been updated.")]')), TIMEOUT); return browser.wait(until.elementLocated(By.xpath('//p[contains(text(),"Your avatar has been updated.")]')), TIMEOUT);
}).then(function () { }).then(function () {
done(); done();
}); });
@ -118,13 +114,13 @@ return done();
function editFile(done) { function editFile(done) {
browser.get('https://' + app.fqdn + '/' + username + '/' + reponame + '/_edit/master/newfile').then(function () { browser.get('https://' + app.fqdn + '/' + username + '/' + reponame + '/_edit/master/newfile').then(function () {
var cm = browser.findElement(by.xpath('//div[contains(@class,"CodeMirror")]')); var cm = browser.findElement(By.xpath('//div[contains(@class,"CodeMirror")]'));
var text = 'yo'; var text = 'yo';
return browser.executeScript('arguments[0].CodeMirror.setValue("' + text + '");', cm); return browser.executeScript('arguments[0].CodeMirror.setValue("' + text + '");', cm);
}).then(function () { }).then(function () {
return browser.findElement(by.xpath('//input[@name="commit_summary"]')).sendKeys('Dummy edit'); return browser.findElement(By.xpath('//input[@name="commit_summary"]')).sendKeys('Dummy edit');
}).then(function () { }).then(function () {
return browser.findElement(by.xpath('//button[contains(text(), "Commit Changes")]')).click(); return browser.findElement(By.xpath('//button[contains(text(), "Commit Changes")]')).click();
}).then(function () { }).then(function () {
return waitForUrl('https://' + app.fqdn + '/' + username + '/' + reponame + '/src/branch/master/newfile'); return waitForUrl('https://' + app.fqdn + '/' + username + '/' + reponame + '/src/branch/master/newfile');
}).then(function () { }).then(function () {
@ -134,13 +130,13 @@ return done();
function login(username, password, done) { function login(username, password, done) {
browser.get('https://' + app.fqdn + '/user/login').then(function () { browser.get('https://' + app.fqdn + '/user/login').then(function () {
return browser.findElement(by.id('user_name')).sendKeys(username); return browser.findElement(By.id('user_name')).sendKeys(username);
}).then(function () { }).then(function () {
return browser.findElement(by.id('password')).sendKeys(password); return browser.findElement(By.id('password')).sendKeys(password);
}).then(function () { }).then(function () {
return browser.findElement(by.tagName('form')).submit(); return browser.findElement(By.tagName('form')).submit();
}).then(function () { }).then(function () {
return browser.wait(until.elementLocated(by.linkText('Dashboard')), TIMEOUT); return browser.wait(until.elementLocated(By.linkText('Dashboard')), TIMEOUT);
}).then(function () { }).then(function () {
done(); done();
}); });
@ -164,21 +160,21 @@ return done();
const sshPage = 'https://' + app.fqdn + '/user/settings/keys'; const sshPage = 'https://' + app.fqdn + '/user/settings/keys';
browser.get(sshPage).then(function () { browser.get(sshPage).then(function () {
return browser.findElement(by.xpath('//div[text()="Add Key"]')).click(); return browser.findElement(By.xpath('//div[text()="Add Key"]')).click();
}).then(function () { }).then(function () {
return browser.findElement(by.id('ssh-key-title')).sendKeys('testkey'); return browser.findElement(By.id('ssh-key-title')).sendKeys('testkey');
}).then(function () { }).then(function () {
return browser.findElement(by.id('ssh-key-content')).sendKeys(publicKey.trim()); // #3480 return browser.findElement(By.id('ssh-key-content')).sendKeys(publicKey.trim()); // #3480
}).then(function () { }).then(function () {
var button = browser.findElement(by.xpath('//button[contains(text(), "Add Key")]')); var button = browser.findElement(By.xpath('//button[contains(text(), "Add Key")]'));
return browser.executeScript('arguments[0].scrollIntoView(false)', button); return browser.executeScript('arguments[0].scrollIntoView(false)', button);
}).then(function () { }).then(function () {
return browser.findElement(by.xpath('//button[contains(text(), "Add Key")]')).click(); return browser.findElement(By.xpath('//button[contains(text(), "Add Key")]')).click();
}).then(function () { }).then(function () {
if (app.manifest.version === '1.0.3') { if (app.manifest.version === '1.0.3') {
return browser.wait(until.elementLocated(by.xpath('//p[contains(text(), "added successfully!")]')), TIMEOUT); return browser.wait(until.elementLocated(By.xpath('//p[contains(text(), "added successfully!")]')), TIMEOUT);
} else { } else {
return browser.wait(until.elementLocated(by.xpath('//p[contains(text(), "has been added.")]')), TIMEOUT); return browser.wait(until.elementLocated(By.xpath('//p[contains(text(), "has been added.")]')), TIMEOUT);
} }
}).then(function () { }).then(function () {
done(); done();
@ -189,23 +185,23 @@ return done();
var getRepoPage; var getRepoPage;
if (app.manifest.version === '1.0.3') { if (app.manifest.version === '1.0.3') {
getRepoPage = browser.get('https://' + app.fqdn).then(function () { getRepoPage = browser.get('https://' + app.fqdn).then(function () {
return browser.findElement(by.linkText('New Repository')).click(); return browser.findElement(By.linkText('New Repository')).click();
}).then(function () { }).then(function () {
return browser.wait(until.elementLocated(by.xpath('//*[contains(text(), "New Repository")]')), TIMEOUT); return browser.wait(until.elementLocated(By.xpath('//*[contains(text(), "New Repository")]')), TIMEOUT);
}); });
} else { } else {
getRepoPage = browser.get('https://' + app.fqdn + '/repo/create'); getRepoPage = browser.get('https://' + app.fqdn + '/repo/create');
} }
getRepoPage.then(function () { getRepoPage.then(function () {
return browser.findElement(by.id('repo_name')).sendKeys(reponame); return browser.findElement(By.id('repo_name')).sendKeys(reponame);
}).then(function () { }).then(function () {
var button = browser.findElement(by.xpath('//button[contains(text(), "Create Repository")]')); var button = browser.findElement(By.xpath('//button[contains(text(), "Create Repository")]'));
return browser.executeScript('arguments[0].scrollIntoView(true)', button); return browser.executeScript('arguments[0].scrollIntoView(true)', button);
}).then(function () { }).then(function () {
return browser.findElement(by.id('auto-init')).click(); return browser.findElement(By.id('auto-init')).click();
}).then(function () { }).then(function () {
return browser.findElement(by.xpath('//button[contains(text(), "Create Repository")]')).click(); return browser.findElement(By.xpath('//button[contains(text(), "Create Repository")]')).click();
}).then(function () { }).then(function () {
browser.wait(function () { browser.wait(function () {
return browser.getCurrentUrl().then(function (url) { return browser.getCurrentUrl().then(function (url) {
@ -219,9 +215,9 @@ return done();
function checkCloneUrl(done) { function checkCloneUrl(done) {
browser.get('https://' + app.fqdn + '/' + username + '/' + reponame).then(function () { browser.get('https://' + app.fqdn + '/' + username + '/' + reponame).then(function () {
return browser.findElement(by.id('repo-clone-ssh')).click(); return browser.findElement(By.id('repo-clone-ssh')).click();
}).then(function () { }).then(function () {
return browser.findElement(by.id('repo-clone-url')).getAttribute('value'); return browser.findElement(By.id('repo-clone-url')).getAttribute('value');
}).then(function (cloneUrl) { }).then(function (cloneUrl) {
expect(cloneUrl).to.be(`ssh://git@${app.fqdn}:${SSH_PORT}/${username}/${reponame}.git`); expect(cloneUrl).to.be(`ssh://git@${app.fqdn}:${SSH_PORT}/${username}/${reponame}.git`);
done(); done();
@ -268,21 +264,21 @@ return done();
function sendMail(done) { function sendMail(done) {
browser.get(`https://${app.fqdn}/admin/config`).then(function () { browser.get(`https://${app.fqdn}/admin/config`).then(function () {
var button = browser.findElement(by.xpath('//button[@id="test-mail-btn"]')); var button = browser.findElement(By.xpath('//button[@id="test-mail-btn"]'));
return browser.executeScript('arguments[0].scrollIntoView(true)', button); return browser.executeScript('arguments[0].scrollIntoView(true)', button);
}).then(function () { }).then(function () {
return browser.findElement(by.xpath('//input[@name="email"]')).sendKeys('test@cloudron.io'); return browser.findElement(By.xpath('//input[@name="email"]')).sendKeys('test@cloudron.io');
}).then(function () { }).then(function () {
return browser.findElement(by.xpath('//button[@id="test-mail-btn"]')).click(); return browser.findElement(By.xpath('//button[@id="test-mail-btn"]')).click();
}).then(function () { }).then(function () {
return browser.wait(until.elementLocated(by.xpath('//p[contains(text(),"A testing email has been sent to \'test@cloudron.io\'")]')), TIMEOUT); return browser.wait(until.elementLocated(By.xpath('//p[contains(text(),"A testing email has been sent to \'test@cloudron.io\'")]')), TIMEOUT);
}).then(function () { }).then(function () {
done(); done();
}); });
} }
xit('build app', function () { xit('build app', function () {
execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); execSync('cloudron build', EXEC_ARGS);
}); });
it('can login', function (done) { it('can login', function (done) {
@ -308,8 +304,8 @@ return done();
}); });
}); });
it('install app', function () { xit('install app', function () {
execSync(`cloudron install --new --wait --location ${LOCATION} -p SSH_PORT=${SSH_PORT}`, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); execSync(`cloudron install --new --wait --location ${LOCATION} -p SSH_PORT=${SSH_PORT}`, EXEC_ARGS);
}); });
it('can get app information', getAppInfo); it('can get app information', getAppInfo);
@ -355,11 +351,11 @@ return done();
it('file exists in repo', fileExists); it('file exists in repo', fileExists);
it('backup app', function () { it('backup app', function () {
execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); execSync('cloudron backup create --app ' + app.id, EXEC_ARGS);
}); });
it('restore app', function () { it('restore app', function () {
execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); execSync('cloudron restore --app ' + app.id, EXEC_ARGS);
}); });
it('can login', login.bind(null, username, password)); it('can login', login.bind(null, username, password));
@ -371,7 +367,7 @@ return done();
//browser.manage().deleteAllCookies(); // commented because of error "'Network.deleteCookie' wasn't found" //browser.manage().deleteAllCookies(); // commented because of error "'Network.deleteCookie' wasn't found"
// ensure we don't hit NXDOMAIN in the mean time // ensure we don't hit NXDOMAIN in the mean time
browser.get('about:blank').then(function () { browser.get('about:blank').then(function () {
execSync('cloudron configure --wait --location ' + LOCATION + '2 --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); execSync('cloudron configure --wait --location ' + LOCATION + '2 --app ' + app.id, EXEC_ARGS);
var inspect = JSON.parse(execSync('cloudron inspect')); var inspect = JSON.parse(execSync('cloudron inspect'));
app = inspect.apps.filter(function (a) { return a.location === LOCATION + '2'; })[0]; app = inspect.apps.filter(function (a) { return a.location === LOCATION + '2'; })[0];
expect(app).to.be.an('object'); expect(app).to.be.an('object');
@ -389,14 +385,14 @@ return done();
it('uninstall app', function (done) { it('uninstall app', function (done) {
// ensure we don't hit NXDOMAIN in the mean time // ensure we don't hit NXDOMAIN in the mean time
browser.get('about:blank').then(function () { browser.get('about:blank').then(function () {
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
done(); done();
}); });
}); });
// check if the _first_ login via email succeeds // check if the _first_ login via email succeeds
it('can login via email', function (done) { it('can login via email', function (done) {
execSync(`cloudron install --new --wait --location ${LOCATION} -p SSH_PORT=${SSH_PORT}`, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); execSync(`cloudron install --new --wait --location ${LOCATION} -p SSH_PORT=${SSH_PORT}`, EXEC_ARGS);
var inspect = JSON.parse(execSync('cloudron inspect')); var inspect = JSON.parse(execSync('cloudron inspect'));
app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0]; app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
@ -407,7 +403,7 @@ return done();
// ensure we don't hit NXDOMAIN in the mean time // ensure we don't hit NXDOMAIN in the mean time
browser.get('about:blank').then(function () { browser.get('about:blank').then(function () {
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
done(); done();
}); });
}); });
@ -415,7 +411,7 @@ return done();
// No SSO // No SSO
it('install app (no sso)', function () { it('install app (no sso)', function () {
execSync(`cloudron install --new --wait --no-sso --location ${LOCATION} -p SSH_PORT=${SSH_PORT}`, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); execSync(`cloudron install --new --wait --no-sso --location ${LOCATION} -p SSH_PORT=${SSH_PORT}`, EXEC_ARGS);
}); });
it('can get app information', function () { it('can get app information', function () {
@ -430,12 +426,12 @@ return done();
it('can logout', logout); it('can logout', logout);
it('uninstall app (no sso)', function () { it('uninstall app (no sso)', function () {
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
}); });
// test update // test update
it('can install app', function () { it('can install app', function () {
execSync(`cloudron install --new --wait --appstore-id ${app.manifest.id} --location ${LOCATION} -p SSH_PORT=${SSH_PORT}`, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); execSync(`cloudron install --new --wait --appstore-id ${app.manifest.id} --location ${LOCATION} -p SSH_PORT=${SSH_PORT}`, EXEC_ARGS);
}); });
it('can get app information', getAppInfo); it('can get app information', getAppInfo);
@ -448,7 +444,7 @@ return done();
it('can add and push a file', pushFile); it('can add and push a file', pushFile);
it('can update', function () { it('can update', function () {
execSync('cloudron install --wait --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); execSync('cloudron install --wait --app ' + app.id, EXEC_ARGS);
}); });
xit('can admin login', adminLogin); xit('can admin login', adminLogin);
@ -463,7 +459,7 @@ return done();
it('uninstall app', function (done) { it('uninstall app', function (done) {
// ensure we don't hit NXDOMAIN in the mean time // ensure we don't hit NXDOMAIN in the mean time
browser.get('about:blank').then(function () { browser.get('about:blank').then(function () {
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
done(); done();
}); });
}); });