minio-app/test/test.js

172 lines
6.9 KiB
JavaScript
Raw Permalink Normal View History

2017-01-24 08:00:22 +00:00
#!/usr/bin/env node
/* jshint esversion: 8 */
/* global describe */
/* global before */
/* global after */
/* global it */
/* global xit */
2017-01-24 08:00:22 +00:00
'use strict';
2018-03-20 16:23:55 +00:00
require('chromedriver');
2022-01-21 21:40:04 +00:00
const execSync = require('child_process').execSync,
2017-01-24 08:00:22 +00:00
expect = require('expect.js'),
2022-01-21 21:40:04 +00:00
fs = require('fs'),
2017-01-24 08:00:22 +00:00
path = require('path'),
2022-01-21 22:26:34 +00:00
superagent = require('superagent'),
2022-01-21 21:40:04 +00:00
{ Builder, By, 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);
const LOCATION = 'test';
const TEST_TIMEOUT = 10000;
const BUCKET = 'cloudrontestbucket';
2022-01-21 21:40:04 +00:00
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
let browser, app;
2017-01-24 08:00:22 +00:00
2022-01-21 21:40:04 +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
});
after(function () {
2017-01-24 08:00:22 +00:00
browser.quit();
});
async function waitForElement(elem) {
await browser.wait(until.elementLocated(elem), TEST_TIMEOUT);
await browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT);
}
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
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);
2022-01-21 21:40:04 +00:00
await browser.findElement(By.xpath('//button[contains(text(), "Login")]')).click();
2022-04-26 05:46:17 +00:00
await waitForElement(By.xpath('//span[contains(text(), "Buckets")]'));
2017-01-24 08:00:22 +00:00
}
async function logout() {
await browser.get(`https://${app.fqdn}/`);
2022-04-26 05:46:17 +00:00
await waitForElement(By.xpath('//span[contains(text(), "Buckets")]'));
await browser.findElement(By.xpath('//div/span[contains(text(), "Logout")]')).click();
await waitForElement(By.id('accessKey'));
2017-01-24 08:00:22 +00:00
}
async function addBucket() {
2022-01-30 18:19:09 +00:00
await browser.get(`https://${app.fqdn}/buckets`);
await waitForElement(By.xpath('//button/span[text()="Create Bucket"]'));
await browser.findElement(By.xpath('//button/span[text()="Create Bucket"]')).click();
2022-01-21 21:40:04 +00:00
await browser.sleep(2000);
await browser.findElement(By.xpath('//input[@id="bucket-name"]')).sendKeys(BUCKET);
2022-01-21 21:40:04 +00:00
await browser.findElement(By.xpath('//button[text()="Create Bucket"]')).click();
await waitForElement(By.xpath(`//a[contains(text(), "${BUCKET}")]`));
2017-01-24 08:00:22 +00:00
}
async function checkBucket() {
2022-01-21 21:40:04 +00:00
await browser.get(`https://${app.fqdn}/buckets`);
await waitForElement(By.xpath(`//h1[contains(text(), "${BUCKET}")]`));
2017-02-16 06:23:47 +00:00
}
2022-01-21 22:26:34 +00:00
async function checkRedirect() {
const response = await superagent.get(`https://${app.secondaryDomains[0].fqdn}`).set('User-Agent', 'Mozilla/5.0').redirects(0).ok(() => true);
expect(response.status).to.be(307);
expect(response.headers.location).to.be(`https://${app.fqdn}`);
}
async function checkApi() {
const response = await superagent.get(`https://${app.secondaryDomains[0].fqdn}`).ok(() => true);
expect(response.status).to.be(403);
expect(response.body.toString('utf8')).to.contain('<Code>AccessDenied</Code>');
}
xit('build app', function () { execSync('cloudron build', EXEC_ARGS); });
2022-01-21 22:26:34 +00:00
it('install app', function () { execSync(`cloudron install --location ${LOCATION} --secondary-domains API_SERVER_DOMAIN=${LOCATION}-api`, EXEC_ARGS); });
2017-01-24 08:00:22 +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-01-24 08:00:22 +00:00
it('can logout', logout);
2022-01-21 22:26:34 +00:00
it('does redirect', checkRedirect);
it('check api', checkApi);
2017-01-24 08:00:22 +00:00
2020-01-16 23:36:41 +00:00
it('can change credentials', function () {
2022-01-21 21:40:04 +00:00
let data = fs.readFileSync(path.join(__dirname, '../env.sh'), 'utf8');
data = data
.replace(/MINIO_ROOT_USER=.*/, 'MINIO_ROOT_USER=minioakey')
.replace(/MINIO_ROOT_PASSWORD=.*/, 'MINIO_ROOT_PASSWORD=minioskey');
fs.writeFileSync('/tmp/env.sh', data);
execSync(`cloudron push --app ${app.id} /tmp/env.sh /app/data/env.sh`, EXEC_ARGS);
execSync(`cloudron restart --app ${app.id}`, EXEC_ARGS);
2020-01-16 23:36:41 +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);
2022-01-21 22:26:34 +00:00
it('does redirect', checkRedirect);
it('check api', checkApi);
2017-09-20 21:30:46 +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 () {
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-01-24 08:00:22 +00:00
it('can logout', logout);
2022-01-21 22:26:34 +00:00
it('does redirect', checkRedirect);
it('check api', checkApi);
2017-01-24 08:00:22 +00:00
it('move to different location', function () {
browser.manage().deleteAllCookies();
execSync('cloudron configure --location ' + LOCATION + '2', EXEC_ARGS);
2017-01-24 08:00:22 +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);
2022-01-21 22:26:34 +00:00
it('does redirect', checkRedirect);
it('check api', checkApi);
2017-01-24 08:00:22 +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
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
2022-01-30 18:19:09 +00:00
it('can login', login.bind(null, 'minioadmin', 'minioadmin'));
it('can add buckets', addBucket);
it('can logout', logout);
2022-01-21 22:26:34 +00:00
it('can update', function () { execSync(`cloudron update --app ${LOCATION}`, EXEC_ARGS); });
2022-01-22 01:21:00 +00:00
it('can configure', function () { execSync(`cloudron configure --app ${LOCATION} --location ${LOCATION} --secondary-domains API_SERVER_DOMAIN=${LOCATION}-api`, 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);
2022-01-21 22:26:34 +00:00
it('does redirect', checkRedirect);
it('check api', checkApi);
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