2017-01-24 08:00:22 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2021-07-16 13:33:27 +00:00
|
|
|
/* jshint esversion: 8 */
|
2020-10-11 13:26:50 +00:00
|
|
|
/* global describe */
|
|
|
|
/* global before */
|
|
|
|
/* global after */
|
|
|
|
/* global it */
|
2021-07-16 13:33:27 +00:00
|
|
|
/* global xit */
|
2020-10-11 13:26:50 +00:00
|
|
|
|
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';
|
2021-07-16 13:33:27 +00:00
|
|
|
const username = process.env.USERNAME;
|
|
|
|
const password = process.env.PASSWORD;
|
|
|
|
|
|
|
|
let browser, app;
|
2017-01-24 08:00:22 +00:00
|
|
|
|
2021-07-16 13:33:27 +00:00
|
|
|
before(function (done) {
|
|
|
|
if (!process.env.PASSWORD) return done(new Error('PASSWORD env var not set'));
|
|
|
|
if (!process.env.USERNAME) return done(new Error('USERNAME env var not set'));
|
2017-01-24 08:00:22 +00:00
|
|
|
|
2020-10-11 13:26:50 +00:00
|
|
|
browser = new Builder().forBrowser('chrome').setChromeOptions(new Options().windowSize({ width: 1280, height: 1024 })).build();
|
2021-07-16 13:33:27 +00:00
|
|
|
done();
|
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();
|
|
|
|
});
|
|
|
|
|
2021-07-16 13:33:27 +00:00
|
|
|
function sleep(millis) {
|
|
|
|
return new Promise(resolve => setTimeout(resolve, millis));
|
|
|
|
}
|
|
|
|
|
|
|
|
async function waitForElement(elem) {
|
|
|
|
await browser.wait(until.elementLocated(elem), TEST_TIMEOUT);
|
|
|
|
await browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2021-07-16 13:33:27 +00:00
|
|
|
async function login(accessKey='minioadmin', secretKey='minioadmin') {
|
|
|
|
await browser.get(`https://${app.fqdn}/login`);
|
|
|
|
await waitForElement(By.id('accessKey'));
|
|
|
|
await browser.findElement(By.id('accessKey')).sendKeys(accessKey);
|
|
|
|
await browser.findElement(By.id('secretKey')).sendKeys(secretKey);
|
|
|
|
await browser.findElement(By.xpath('//button[@type="submit"]/span[text()="Login"]')).click();
|
|
|
|
await waitForElement(By.xpath(`//div/span[contains(text(), "Dashboard")]`));
|
2017-01-24 08:00:22 +00:00
|
|
|
}
|
|
|
|
|
2021-07-16 13:33:27 +00:00
|
|
|
async function old_login(accessKey='minioadmin', secretKey='minioadmin') {
|
|
|
|
await browser.get(`https://${app.fqdn}/minio/login`);
|
|
|
|
await waitForElement(By.id('accessKey'));
|
|
|
|
await browser.findElement(By.id('accessKey')).sendKeys(accessKey);
|
|
|
|
await browser.findElement(By.id('secretKey')).sendKeys(secretKey);
|
|
|
|
await browser.findElement(By.xpath('//button[@type="submit"]')).click();
|
|
|
|
await waitForElement(By.xpath(`//input[@placeholder="Search Buckets..."]`));
|
2017-01-24 08:00:22 +00:00
|
|
|
}
|
|
|
|
|
2021-07-16 13:33:27 +00:00
|
|
|
async function logout() {
|
|
|
|
await browser.get(`https://${app.fqdn}/`);
|
|
|
|
await waitForElement(By.xpath(`//div/span[contains(text(), "Dashboard")]`));
|
|
|
|
await browser.findElement(By.xpath('//div/span[contains(text(), "Logout")]')).click();
|
|
|
|
await waitForElement(By.id('accessKey'));
|
2017-01-24 08:00:22 +00:00
|
|
|
}
|
|
|
|
|
2021-07-16 13:33:27 +00:00
|
|
|
async function old_logout() {
|
|
|
|
await browser.get(`https://${app.fqdn}/`);
|
|
|
|
await waitForElement(By.xpath(`//input[@placeholder="Search Buckets..."]`));
|
|
|
|
await browser.findElement(By.xpath('//div/button[@id="top-right-menu"]')).click();
|
|
|
|
await browser.findElement(By.xpath('//ul/li/a[@id="logout"]')).click();
|
|
|
|
await waitForElement(By.id('accessKey'));
|
2017-01-24 08:00:22 +00:00
|
|
|
}
|
|
|
|
|
2021-07-16 13:33:27 +00:00
|
|
|
async function addBucket() {
|
|
|
|
await browser.get(`https://${app.fqdn}/`);
|
|
|
|
await waitForElement(By.xpath('//div/span[contains(text(), "Bucket")]'));
|
|
|
|
await browser.findElement(By.xpath('//div/span[contains(text(), "Bucket")]')).click();
|
|
|
|
await waitForElement(By.xpath('//span[text()="Create Bucket"]'));
|
|
|
|
await browser.findElement(By.xpath('//span[text()="Create Bucket"]')).click();
|
|
|
|
await browser.findElement(By.xpath('//input[@id="bucket-name"]')).sendKeys(BUCKET);
|
|
|
|
await browser.findElement(By.xpath('//button[@type="submit"]/span[text()="Save"]')).click();
|
|
|
|
await waitForElement(By.xpath(`//div/span[contains(text(), "${BUCKET}")]`));
|
|
|
|
await browser.findElement(By.xpath(`//div/span[contains(text(), "${BUCKET}")]`));
|
2017-01-24 08:00:22 +00:00
|
|
|
}
|
|
|
|
|
2021-07-16 13:33:27 +00:00
|
|
|
async function old_addBucket() {
|
|
|
|
await browser.get(`https://${app.fqdn}/`);
|
|
|
|
await waitForElement(By.xpath(`//input[@placeholder="Search Buckets..."]`));
|
|
|
|
await browser.findElement(By.xpath('//div/button[@id="fe-action-toggle"]')).click();
|
|
|
|
await browser.findElement(By.xpath('//ul/a[@id="show-make-bucket"]')).click();
|
|
|
|
await browser.findElement(By.xpath('//input[@placeholder="Bucket Name"]')).sendKeys(BUCKET);
|
|
|
|
await browser.findElement(By.xpath('//*[@class="modal-body"]/form')).submit();
|
|
|
|
await waitForElement(By.xpath(`//*[@class="main"]/a[text()="${BUCKET}"]`));
|
|
|
|
}
|
|
|
|
|
|
|
|
async function checkBucket() {
|
|
|
|
await browser.get(`https://${app.fqdn}/`);
|
|
|
|
await waitForElement(By.xpath(`//div/span[contains(text(), "Dashboard")]`));
|
|
|
|
await browser.findElement(By.xpath('//div/span[contains(text(), "Bucket")]')).click();
|
|
|
|
await waitForElement(By.xpath(`//div/span[contains(text(), "${BUCKET}")]`));
|
|
|
|
await browser.findElement(By.xpath(`//div/span[contains(text(), "${BUCKET}")]`));
|
|
|
|
}
|
2017-02-16 06:23:47 +00:00
|
|
|
|
2021-07-16 13:33:27 +00:00
|
|
|
async function old_checkBucket() {
|
|
|
|
await browser.get(`https://${app.fqdn}/`);
|
|
|
|
await waitForElement(By.xpath(`//input[@placeholder="Search Buckets..."]`));
|
|
|
|
await waitForElement(By.xpath(`//*[@class="main"]/a[text()="${BUCKET}"]`));
|
2017-09-20 21:30:46 +00:00
|
|
|
}
|
2017-02-16 06:23:47 +00:00
|
|
|
|
2021-07-16 13:33:27 +00:00
|
|
|
async function openSettings() {
|
|
|
|
await browser.get(`https://${app.fqdn}/`);
|
|
|
|
await waitForElement(By.xpath(`//div/span[contains(text(), "Dashboard")]`));
|
|
|
|
await browser.findElement(By.xpath('//div/span[contains(text(), "Account")]')).click();
|
|
|
|
await waitForElement(By.xpath(`//button/span[text()="Change Password"]`));
|
|
|
|
await browser.findElement(By.xpath('//button/span[text()="Change Password"]'));
|
|
|
|
}
|
|
|
|
|
|
|
|
async function old_openSettings() {
|
|
|
|
await browser.get(`https://${app.fqdn}/`);
|
|
|
|
await waitForElement(By.xpath(`//input[@placeholder="Search Buckets..."]`));
|
|
|
|
await browser.findElement(By.xpath('//div/button[@id="top-right-menu"]')).click();
|
|
|
|
await waitForElement(By.xpath('//ul/li/a[contains(text(), "Change Password")]'));
|
|
|
|
await browser.findElement(By.xpath('//ul/li/a[contains(text(), "Change Password")]'));
|
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
|
|
|
|
2021-07-16 13:33:27 +00:00
|
|
|
it('can login', old_login.bind(null, 'minioadmin', 'minioadmin'));
|
|
|
|
it('can add buckets', old_addBucket);
|
|
|
|
it('can logout', old_logout);
|
|
|
|
it('can update', function () { execSync(`cloudron update --app ${LOCATION} --no-wait`, EXEC_ARGS); });
|
|
|
|
it('can enable API Port', function () { execSync(`cloudron configure --app ${LOCATION} -p API_PORT=9000 -l ${LOCATION} `, EXEC_ARGS); });
|
2020-10-11 13:26:50 +00:00
|
|
|
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
|
|
|
|