minio-app/test/test.js

297 lines
12 KiB
JavaScript
Raw 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');
2023-06-03 08:26:21 +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'),
2023-06-03 08:26:21 +00:00
timers = require('timers/promises'),
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
2024-02-19 13:13:57 +00:00
if (!process.env.USERNAME || !process.env.PASSWORD) {
console.log('USERNAME and PASSWORD env vars need to be set');
process.exit(1);
}
2017-01-24 08:00:22 +00:00
describe('Application life cycle test', function () {
this.timeout(0);
const LOCATION = 'test';
2024-03-04 10:33:45 +00:00
const TEST_TIMEOUT = parseInt(process.env.TIMEOUT, 10) || 30000;
const BUCKET = 'cloudrontestbucket';
2022-01-21 21:40:04 +00:00
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
let browser, app;
let athenticated_by_oidc = false, rootPassword;
2024-02-19 13:13:57 +00:00
let username = process.env.USERNAME;
let password = process.env.PASSWORD;
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
2024-02-20 12:26:29 +00:00
async function login(username, password, expandLoginForm=true) {
await browser.manage().deleteAllCookies();
await browser.get('about:blank');
await browser.sleep(2000);
await browser.get(`https://${app.fqdn}/login`);
2024-02-19 13:13:57 +00:00
await browser.sleep(2000);
2024-02-20 12:26:29 +00:00
if (expandLoginForm) {
await waitForElement(By.xpath('//div[@id="alternativeMethods-select"]/div[contains(., "Other Authentication Methods")]'));
2024-02-19 13:13:57 +00:00
await browser.findElement(By.xpath('//div[@id="alternativeMethods-select"]/div[contains(., "Other Authentication Methods")]')).click();
await browser.sleep(2000);
await browser.findElement(By.xpath('//li[contains(., "Use Credentials")] | //div[@label="Use Credentials"]')).click();
await browser.sleep(2000);
}
await waitForElement(By.id('accessKey'));
await browser.findElement(By.id('accessKey')).sendKeys(username);
await browser.findElement(By.id('secretKey')).sendKeys(password);
2022-09-20 16:57:27 +00:00
await browser.findElement(By.xpath('//button[@id="do-login"]')).click();
2022-04-26 05:46:17 +00:00
await waitForElement(By.xpath('//span[contains(text(), "Buckets")]'));
2023-06-03 08:26:21 +00:00
await timers.setTimeout(5000);
2017-01-24 08:00:22 +00:00
}
2024-02-19 13:13:57 +00:00
async function loginOIDC(username, password) {
browser.manage().deleteAllCookies();
await browser.get(`https://${app.fqdn}/login`);
2024-03-07 08:19:29 +00:00
await browser.sleep(10000);
2024-02-19 13:13:57 +00:00
await browser.findElement(By.xpath('//button[contains(., "Cloudron")]')).click();
2024-03-07 08:19:29 +00:00
await browser.sleep(10000);
2024-02-19 13:13:57 +00:00
if (!athenticated_by_oidc) {
await waitForElement(By.xpath('//input[@name="username"]'));
await browser.findElement(By.xpath('//input[@name="username"]')).sendKeys(username);
await browser.findElement(By.xpath('//input[@name="password"]')).sendKeys(password);
await browser.sleep(2000);
await browser.findElement(By.id('loginSubmitButton')).click();
await browser.sleep(2000);
athenticated_by_oidc = true;
}
await waitForElement(By.xpath('//span[contains(text(), "Buckets")]'));
}
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")]'));
2023-06-16 11:55:23 +00:00
const button = await browser.findElement(By.xpath('//button[@id="sign-out"]'));
2022-11-11 09:51:12 +00:00
await browser.executeScript('arguments[0].scrollIntoView(false)', button);
await button.click();
2024-03-04 10:33:45 +00:00
await browser.sleep(10000); // needed!
2024-02-19 13:13:57 +00:00
await waitForElement(By.xpath('//*[@id="accessKey"] | //button[contains(., "Cloudron")]'));
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`);
2022-09-20 16:57:27 +00:00
await waitForElement(By.xpath('//button[@id="create-bucket"]'));
await browser.findElement(By.xpath('//button[@id="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-09-20 16:57:27 +00:00
await browser.findElement(By.xpath('//button[@id="create-bucket"]')).click();
2023-01-12 09:53:26 +00:00
await waitForElement(By.xpath(`//h1[contains(text(), "${BUCKET}")]`));
2023-06-03 08:26:21 +00:00
await timers.setTimeout(5000);
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>');
}
async function changeAdminCredentials() {
let data = fs.readFileSync(path.join(__dirname, '../env.sh.template'), 'utf8');
data += '\nexport MINIO_ROOT_USER=minioakey\nexport MINIO_ROOT_PASSWORD=minioskey\n';
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);
await timers.setTimeout(10000);
}
async function getAdminCredentials() {
execSync(`cloudron pull --app ${app.id} /app/data/env.sh /tmp/env.sh`, EXEC_ARGS);
const data = fs.readFileSync('/tmp/env.sh', 'utf8');
const m = data.match(/MINIO_ROOT_PASSWORD=(.*)/);
if (!m) throw new Error('Could not detect root password');
rootPassword = m[1].trim();
console.log(`root password is [${rootPassword}]`);
}
xit('build app', function () { execSync('cloudron build', EXEC_ARGS); });
2024-02-19 14:31:04 +00:00
// // no SSO
2024-02-19 14:31:04 +00:00
it('install app (no SSO)', async function () {
execSync(`cloudron install --no-sso --location ${LOCATION} --secondary-domains API_SERVER_DOMAIN=${LOCATION}-api`, EXEC_ARGS);
await timers.setTimeout(10000);
});
it('can get app information', getAppInfo);
2024-02-20 12:26:29 +00:00
it('can admin login', login.bind(null, 'minioadmin', 'minioadmin', false));
2024-02-19 14:31:04 +00:00
it('can add bucket', addBucket);
it('can logout', logout);
it('does redirect', checkRedirect);
it('check api', checkApi);
it('can change admin credentials', changeAdminCredentials);
it('can restart app', async function () {
2024-02-19 14:31:04 +00:00
execSync(`cloudron restart --app ${app.id}`, EXEC_ARGS);
await timers.setTimeout(10000);
});
2024-02-20 12:26:29 +00:00
it('can admin login', login.bind(null, 'minioakey', 'minioskey', false));
2024-02-19 14:31:04 +00:00
it('has bucket', checkBucket);
it('can logout', logout);
it('does redirect', checkRedirect);
it('check api', checkApi);
it('uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); });
// SSO
it('install app (SSO)', async function () {
execSync(`cloudron install --location ${LOCATION} --secondary-domains API_SERVER_DOMAIN=${LOCATION}-api`, EXEC_ARGS);
2023-06-03 08:26:21 +00:00
await timers.setTimeout(10000);
});
2017-01-24 08:00:22 +00:00
it('can get app information', getAppInfo);
it('can get admin credentials', getAdminCredentials);
it('can admin login', async function () { await login('minioadmin', rootPassword); });
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
2024-02-19 13:13:57 +00:00
it('can OIDC login', loginOIDC.bind(null, username, password));
it('has bucket', checkBucket);
it('can logout', logout);
it('can change admin credentials', changeAdminCredentials);
it('can restart app', async function () {
2022-01-21 21:40:04 +00:00
execSync(`cloudron restart --app ${app.id}`, EXEC_ARGS);
2023-06-03 08:26:21 +00:00
await timers.setTimeout(10000);
2020-01-16 23:36:41 +00:00
});
it('can admin 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
2024-02-19 13:13:57 +00:00
it('can OIDC login', loginOIDC.bind(null, username, password));
it('has bucket', checkBucket);
it('can logout', logout);
it('backup app', function () { execSync('cloudron backup create --app ' + app.id, EXEC_ARGS); });
it('restore app', async 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);
2023-06-03 08:26:21 +00:00
await timers.setTimeout(10000);
2017-01-24 08:00:22 +00:00
});
2024-02-19 13:13:57 +00:00
it('can get app information', getAppInfo);
it('can admin login', login.bind(null, 'minioakey', 'minioskey'));
2024-02-19 13:13:57 +00:00
it('has bucket', checkBucket);
it('can logout', logout);
it('can OIDC login', loginOIDC.bind(null, username, password));
2017-09-20 21:30:46 +00:00
it('has bucket', checkBucket);
2017-01-24 08:00:22 +00:00
it('can logout', logout);
2024-02-19 13:13:57 +00:00
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', async function () {
2017-01-24 08:00:22 +00:00
browser.manage().deleteAllCookies();
execSync('cloudron configure --location ' + LOCATION + '2', EXEC_ARGS);
2023-06-03 08:26:21 +00:00
await timers.setTimeout(10000);
2017-01-24 08:00:22 +00:00
});
it('can get app information', getAppInfo);
2017-01-24 08:00:22 +00:00
it('can admin 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);
2024-02-19 13:13:57 +00:00
it('can OIDC login', loginOIDC.bind(null, username, password));
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-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 for update', 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
2024-02-20 12:26:29 +00:00
it('can get admin credentials', getAdminCredentials);
it('can admin login', async function () { await login('minioadmin', rootPassword); });
2022-01-30 18:19:09 +00:00
it('can add buckets', addBucket);
it('can logout', logout);
2024-02-19 13:13:57 +00:00
it('can OIDC login', loginOIDC.bind(null, username, password));
it('has bucket', checkBucket);
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);
2024-02-20 12:26:29 +00:00
it('can admin login', async function () { await login('minioadmin', rootPassword); });
2017-09-20 21:30:46 +00:00
it('has bucket', checkBucket);
it('can logout', logout);
2024-02-19 13:13:57 +00:00
it('can OIDC login', loginOIDC.bind(null, username, password));
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