2017-01-24 08:00:22 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2020-10-11 13:26:50 +00:00
|
|
|
/* global describe */
|
|
|
|
/* global before */
|
|
|
|
/* global after */
|
|
|
|
/* global it */
|
|
|
|
|
2017-01-24 08:00:22 +00:00
|
|
|
'use strict';
|
|
|
|
|
2018-03-20 16:23:55 +00:00
|
|
|
require('chromedriver');
|
|
|
|
|
2017-01-24 08:00:22 +00:00
|
|
|
var execSync = require('child_process').execSync,
|
|
|
|
expect = require('expect.js'),
|
|
|
|
path = require('path'),
|
2020-10-11 13:26:50 +00:00
|
|
|
{ Builder, By, Key, until } = require('selenium-webdriver'),
|
|
|
|
{ Options } = require('selenium-webdriver/chrome');
|
2017-01-24 08:00:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
describe('Application life cycle test', function () {
|
|
|
|
this.timeout(0);
|
|
|
|
|
2020-10-11 13:26:50 +00:00
|
|
|
const LOCATION = 'test';
|
|
|
|
const TEST_TIMEOUT = 10000;
|
|
|
|
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
|
|
|
|
const BUCKET = 'cloudrontestbucket';
|
2017-01-24 08:00:22 +00:00
|
|
|
|
2020-10-11 13:26:50 +00:00
|
|
|
var app;
|
|
|
|
var browser;
|
2017-01-24 08:00:22 +00:00
|
|
|
|
2020-10-11 13:26:50 +00:00
|
|
|
before(function () {
|
|
|
|
browser = new Builder().forBrowser('chrome').setChromeOptions(new Options().windowSize({ width: 1280, height: 1024 })).build();
|
2017-01-24 08:00:22 +00:00
|
|
|
});
|
|
|
|
|
2020-10-11 13:26:50 +00:00
|
|
|
after(function () {
|
2017-01-24 08:00:22 +00:00
|
|
|
browser.quit();
|
|
|
|
});
|
|
|
|
|
2020-10-11 13:26:50 +00:00
|
|
|
function getAppInfo() {
|
|
|
|
var inspect = JSON.parse(execSync('cloudron inspect'));
|
|
|
|
app = inspect.apps.filter(function (a) { return a.location.indexOf(LOCATION) === 0; })[0];
|
|
|
|
expect(app).to.be.an('object');
|
|
|
|
}
|
2017-01-24 08:00:22 +00:00
|
|
|
|
2017-09-20 21:30:46 +00:00
|
|
|
function pageLoaded() {
|
2020-10-11 13:26:50 +00:00
|
|
|
return browser.wait(until.elementLocated(By.className('page-load pl-0 pl-1')), TEST_TIMEOUT);
|
2017-01-24 08:00:22 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 21:30:46 +00:00
|
|
|
function visible(selector) {
|
2017-01-24 08:00:22 +00:00
|
|
|
return browser.wait(until.elementLocated(selector), TEST_TIMEOUT).then(function () {
|
2017-09-20 21:30:46 +00:00
|
|
|
return browser.wait(until.elementIsVisible(browser.findElement(selector)), TEST_TIMEOUT);
|
2017-01-24 08:00:22 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-16 23:36:41 +00:00
|
|
|
function login(accessKey, secretKey, callback) {
|
2017-01-24 08:00:22 +00:00
|
|
|
browser.manage().deleteAllCookies();
|
2017-09-20 21:30:46 +00:00
|
|
|
browser.get('https://' + app.fqdn).then(function () {
|
2020-10-11 13:26:50 +00:00
|
|
|
return visible(By.id('accessKey'));
|
2017-09-20 21:30:46 +00:00
|
|
|
}).then(function () {
|
2020-10-11 13:26:50 +00:00
|
|
|
return browser.findElement(By.id('accessKey')).sendKeys(accessKey);
|
2017-09-20 21:30:46 +00:00
|
|
|
}).then(function () {
|
2020-10-11 13:26:50 +00:00
|
|
|
return browser.findElement(By.id('secretKey')).sendKeys(secretKey);
|
2017-09-20 21:30:46 +00:00
|
|
|
}).then(function () {
|
2020-10-11 13:26:50 +00:00
|
|
|
// return browser.findElement(By.className('lw-btn')).click();
|
|
|
|
return browser.findElement(By.tagName('form')).submit();
|
2017-09-20 21:30:46 +00:00
|
|
|
}).then(function () {
|
2020-10-11 13:26:50 +00:00
|
|
|
return browser.wait(until.elementLocated(By.id('top-right-menu')), TEST_TIMEOUT);
|
2017-09-20 21:30:46 +00:00
|
|
|
}).then(function () {
|
|
|
|
callback();
|
2017-01-24 08:00:22 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function logout(callback) {
|
|
|
|
browser.get('https://' + app.fqdn);
|
|
|
|
|
2017-09-20 21:30:46 +00:00
|
|
|
pageLoaded().then(function () {
|
2020-10-11 13:26:50 +00:00
|
|
|
return visible(By.id('top-right-menu'));
|
2017-09-20 21:30:46 +00:00
|
|
|
}).then(function () {
|
2020-10-11 13:26:50 +00:00
|
|
|
return browser.findElement(By.id('top-right-menu')).click();
|
2017-09-20 21:30:46 +00:00
|
|
|
}).then(function () {
|
2020-09-22 16:56:30 +00:00
|
|
|
if (app.manifest.version === '1.137.0') {
|
2020-10-11 13:26:50 +00:00
|
|
|
return visible(By.xpath('//*[text()="Sign Out "]'));
|
2020-09-22 16:56:30 +00:00
|
|
|
} else {
|
2020-10-11 13:26:50 +00:00
|
|
|
return visible(By.xpath('//*[contains(text(), "Logout")]'));
|
2020-09-22 16:56:30 +00:00
|
|
|
}
|
|
|
|
}).then(function () {
|
|
|
|
if (app.manifest.version === '1.137.0') {
|
2020-10-11 13:26:50 +00:00
|
|
|
return browser.findElement(By.xpath('//*[text()="Sign Out "]')).click();
|
2020-09-22 16:56:30 +00:00
|
|
|
} else {
|
2020-10-11 13:26:50 +00:00
|
|
|
return browser.findElement(By.xpath('//*[contains(text(),"Logout")]')).click();
|
2020-09-22 16:56:30 +00:00
|
|
|
}
|
2017-09-20 21:30:46 +00:00
|
|
|
}).then(function () {
|
2020-10-11 13:26:50 +00:00
|
|
|
return browser.wait(until.elementLocated(By.id('accessKey')), TEST_TIMEOUT);
|
2017-09-20 21:30:46 +00:00
|
|
|
}).then(function () {
|
|
|
|
callback();
|
2017-01-24 08:00:22 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function addBucket(callback) {
|
|
|
|
browser.get('https://' + app.fqdn);
|
|
|
|
|
2017-09-20 21:30:46 +00:00
|
|
|
pageLoaded().then(function () {
|
2020-10-11 13:26:50 +00:00
|
|
|
return visible(By.className('fa-plus'));
|
2017-09-20 21:30:46 +00:00
|
|
|
}).then(function () {
|
2020-10-11 13:26:50 +00:00
|
|
|
return browser.findElement(By.className('fa-plus')).click();
|
2017-09-20 21:30:46 +00:00
|
|
|
}).then(function () {
|
2019-09-01 15:45:49 +00:00
|
|
|
const c = 'fa-hdd';
|
2020-10-11 13:26:50 +00:00
|
|
|
return visible(By.className(c));
|
2017-09-20 21:30:46 +00:00
|
|
|
}).then(function () {
|
2019-09-01 15:45:49 +00:00
|
|
|
const c = 'fa-hdd';
|
2020-10-11 13:26:50 +00:00
|
|
|
return browser.findElement(By.className(c)).click();
|
2017-09-20 21:30:46 +00:00
|
|
|
}).then(function () {
|
2020-10-11 13:26:50 +00:00
|
|
|
return visible(By.xpath('//*[@class="modal-body"]/form/div/input'));
|
2017-09-20 21:30:46 +00:00
|
|
|
}).then(function () {
|
2020-10-11 13:26:50 +00:00
|
|
|
return browser.findElement(By.xpath('//*[@class="modal-body"]/form/div/input')).sendKeys(BUCKET);
|
2017-09-20 21:30:46 +00:00
|
|
|
}).then(function () {
|
2020-10-11 13:26:50 +00:00
|
|
|
return browser.findElement(By.xpath('//*[@class="modal-body"]/form')).submit();
|
2017-09-20 21:30:46 +00:00
|
|
|
}).then(function () {
|
2020-10-11 13:26:50 +00:00
|
|
|
return visible(By.xpath('//*[@class="main"]/a[text()="' + BUCKET + '"]'));
|
2017-09-20 21:30:46 +00:00
|
|
|
}).then(function () {
|
|
|
|
callback();
|
2017-01-24 08:00:22 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-09-20 21:30:46 +00:00
|
|
|
function checkBucket(callback) {
|
2017-02-16 06:23:47 +00:00
|
|
|
browser.get('https://' + app.fqdn);
|
|
|
|
|
2017-09-20 21:30:46 +00:00
|
|
|
pageLoaded().then(function () {
|
2020-10-11 13:26:50 +00:00
|
|
|
return browser.findElement(By.xpath(`//a[contains(text(), ${BUCKET})]`));
|
2017-09-20 21:30:46 +00:00
|
|
|
}).then(function () {
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
}
|
2017-02-16 06:23:47 +00:00
|
|
|
|
2017-09-20 21:30:46 +00:00
|
|
|
function openSettings(callback) {
|
|
|
|
browser.get('https://' + app.fqdn);
|
|
|
|
|
|
|
|
pageLoaded().then(function () {
|
2020-10-11 13:26:50 +00:00
|
|
|
return visible(By.id('top-right-menu'));
|
2017-09-20 21:30:46 +00:00
|
|
|
}).then(function () {
|
2020-10-11 13:26:50 +00:00
|
|
|
return browser.findElement(By.id('top-right-menu')).click();
|
2017-09-20 21:30:46 +00:00
|
|
|
}).then(function () {
|
2020-10-11 13:26:50 +00:00
|
|
|
return visible(By.xpath('//*[contains(text(), "Change Password")]'));
|
2017-09-20 21:30:46 +00:00
|
|
|
}).then(function () {
|
2020-10-11 13:26:50 +00:00
|
|
|
return browser.findElement(By.xpath('//*[contains(text(),"Change Password")]')).click();
|
2017-09-20 21:30:46 +00:00
|
|
|
}).then(function () {
|
2020-10-11 13:26:50 +00:00
|
|
|
return browser.wait(until.elementLocated(By.xpath('//*[contains(text(), "Change Password")]')), TEST_TIMEOUT);
|
2017-09-20 21:30:46 +00:00
|
|
|
}).then(function () {
|
|
|
|
callback();
|
2017-02-16 06:23:47 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-11 13:26:50 +00:00
|
|
|
xit('build app', function () { execSync('cloudron build', EXEC_ARGS); });
|
|
|
|
it('install app', function () { execSync('cloudron install --location ' + LOCATION, EXEC_ARGS); });
|
2017-01-24 08:00:22 +00:00
|
|
|
|
2020-10-11 13:26:50 +00:00
|
|
|
it('can get app information', getAppInfo);
|
2017-01-24 08:00:22 +00:00
|
|
|
|
2020-01-16 23:36:41 +00:00
|
|
|
it('can login', login.bind(null, 'minioadmin', 'minioadmin'));
|
2017-09-20 21:30:46 +00:00
|
|
|
it('can add bucket', addBucket);
|
2017-02-16 06:23:47 +00:00
|
|
|
it('can open settings', openSettings);
|
2017-01-24 08:00:22 +00:00
|
|
|
it('can logout', logout);
|
|
|
|
|
2020-01-16 23:36:41 +00:00
|
|
|
it('can change credentials', function () {
|
2020-10-11 13:26:50 +00:00
|
|
|
execSync(`cloudron exec --app ${app.id} -- /app/code/minio-credentials set minioakey minioskey`, EXEC_ARGS);
|
2020-01-16 23:36:41 +00:00
|
|
|
});
|
|
|
|
|
2020-10-11 13:26:50 +00:00
|
|
|
it('can restart app', function () { execSync(`cloudron restart --app ${app.id}`, EXEC_ARGS); });
|
2017-09-20 21:30:46 +00:00
|
|
|
|
2020-01-16 23:36:41 +00:00
|
|
|
it('can login', login.bind(null, 'minioakey', 'minioskey'));
|
2017-09-20 21:30:46 +00:00
|
|
|
it('has bucket', checkBucket);
|
|
|
|
it('can logout', logout);
|
|
|
|
|
2020-10-11 13:26:50 +00:00
|
|
|
it('backup app', function () { execSync('cloudron backup create --app ' + app.id, EXEC_ARGS); });
|
2017-01-24 08:00:22 +00:00
|
|
|
it('restore app', function () {
|
2020-10-11 13:26:50 +00:00
|
|
|
const backups = JSON.parse(execSync(`cloudron backup list --raw --app ${app.id}`));
|
|
|
|
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
|
|
|
|
execSync('cloudron install --location ' + LOCATION, EXEC_ARGS);
|
|
|
|
getAppInfo();
|
|
|
|
execSync(`cloudron restore --backup ${backups[0].id} --app ${app.id}`, EXEC_ARGS);
|
2017-01-24 08:00:22 +00:00
|
|
|
});
|
|
|
|
|
2020-01-16 23:36:41 +00:00
|
|
|
it('can login', login.bind(null, 'minioakey', 'minioskey'));
|
2017-09-20 21:30:46 +00:00
|
|
|
it('has bucket', checkBucket);
|
2017-02-16 06:23:47 +00:00
|
|
|
it('can open settings', openSettings);
|
2017-01-24 08:00:22 +00:00
|
|
|
it('can logout', logout);
|
|
|
|
|
|
|
|
it('move to different location', function () {
|
|
|
|
browser.manage().deleteAllCookies();
|
2020-10-11 13:26:50 +00:00
|
|
|
execSync('cloudron configure --location ' + LOCATION + '2', EXEC_ARGS);
|
2017-01-24 08:00:22 +00:00
|
|
|
});
|
2020-10-11 13:26:50 +00:00
|
|
|
it('can get app information', getAppInfo);
|
2017-01-24 08:00:22 +00:00
|
|
|
|
2020-01-16 23:36:41 +00:00
|
|
|
it('can login', login.bind(null, 'minioakey', 'minioskey'));
|
2017-09-20 21:30:46 +00:00
|
|
|
it('has bucket', checkBucket);
|
2017-01-24 08:00:22 +00:00
|
|
|
it('can logout', logout);
|
|
|
|
|
2020-10-11 13:26:50 +00:00
|
|
|
it('uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); });
|
2017-01-24 08:00:22 +00:00
|
|
|
|
2017-09-20 21:30:46 +00:00
|
|
|
// test update
|
2020-10-11 13:26:50 +00:00
|
|
|
it('can install app', function () { execSync('cloudron install --appstore-id io.minio.cloudronapp --location ' + LOCATION, EXEC_ARGS); });
|
|
|
|
it('can get app information', getAppInfo);
|
2017-09-20 21:30:46 +00:00
|
|
|
|
2020-01-17 00:05:59 +00:00
|
|
|
it('can login', login.bind(null, 'minioadmin', 'minioadmin'));
|
2017-09-20 21:30:46 +00:00
|
|
|
it('can add buckets', addBucket);
|
|
|
|
it('can logout', logout);
|
2020-10-11 13:26:50 +00:00
|
|
|
it('can update', function () { execSync('cloudron update --app ' + LOCATION, EXEC_ARGS); });
|
|
|
|
it('can get app information', getAppInfo);
|
|
|
|
|
2020-01-17 00:05:59 +00:00
|
|
|
it('can login', login.bind(null, 'minioadmin', 'minioadmin'));
|
2017-09-20 21:30:46 +00:00
|
|
|
it('has bucket', checkBucket);
|
|
|
|
it('can logout', logout);
|
2020-10-11 13:26:50 +00:00
|
|
|
|
|
|
|
it('uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); });
|
2017-01-24 08:00:22 +00:00
|
|
|
});
|
2017-09-20 21:30:46 +00:00
|
|
|
|