mirror of
https://git.cloudron.io/cloudron/minio-app
synced 2026-05-03 23:45:56 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 231a7485a4 | |||
| b3fce86d02 | |||
| 5517962ee8 | |||
| bbf33e6cdd | |||
| a2a90e130b | |||
| 5fd9ba74ba | |||
| b1f79dfa1e | |||
| 3d5d79ba0b |
Generated
-2285
File diff suppressed because it is too large
Load Diff
@@ -1,19 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "test",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "",
|
|
||||||
"main": "index.js",
|
|
||||||
"scripts": {
|
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
|
||||||
},
|
|
||||||
"author": "",
|
|
||||||
"license": "ISC",
|
|
||||||
"dependencies": {
|
|
||||||
"@eslint/js": "^9.37.0",
|
|
||||||
"chromedriver": "^141.0.3",
|
|
||||||
"expect.js": "^0.3.1",
|
|
||||||
"mocha": "^11.7.4",
|
|
||||||
"selenium-webdriver": "^4.36.0",
|
|
||||||
"superagent": "^10.2.3"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+43
-173
@@ -1,241 +1,111 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
/* jshint esversion: 8 */
|
import assert from 'node:assert/strict';
|
||||||
/* global it, xit, describe, before, after, afterEach */
|
import fs from 'node:fs';
|
||||||
|
import path from 'node:path';
|
||||||
|
import superagent from '@cloudron/superagent';
|
||||||
|
|
||||||
'use strict';
|
import { app, clearCache, click, cloudronCli, goto, LOCATION, sendKeys, setupBrowser, takeScreenshot, teardownBrowser, waitFor } from '@cloudron/charlie';
|
||||||
|
|
||||||
require('chromedriver');
|
/* global it, describe, before, after, afterEach */
|
||||||
|
|
||||||
const execSync = require('child_process').execSync,
|
|
||||||
expect = require('expect.js'),
|
|
||||||
fs = require('fs'),
|
|
||||||
path = require('path'),
|
|
||||||
superagent = require('superagent'),
|
|
||||||
timers = require('timers/promises'),
|
|
||||||
{ Builder, By, until } = require('selenium-webdriver'),
|
|
||||||
{ Options } = require('selenium-webdriver/chrome');
|
|
||||||
|
|
||||||
if (!process.env.USERNAME || !process.env.PASSWORD) {
|
|
||||||
console.log('USERNAME and PASSWORD env vars need to be set');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('Application life cycle test', function () {
|
describe('Application life cycle test', function () {
|
||||||
this.timeout(0);
|
|
||||||
|
|
||||||
const LOCATION = process.env.LOCATION || 'test';
|
|
||||||
const TEST_TIMEOUT = parseInt(process.env.TIMEOUT, 10) || 30000;
|
|
||||||
const BUCKET = 'cloudrontestbucket';
|
const BUCKET = 'cloudrontestbucket';
|
||||||
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
|
|
||||||
|
|
||||||
let browser, app;
|
before(setupBrowser);
|
||||||
let rootPassword;
|
after(teardownBrowser);
|
||||||
const username = process.env.USERNAME;
|
|
||||||
const password = process.env.PASSWORD;
|
|
||||||
|
|
||||||
before(function () {
|
|
||||||
const chromeOptions = new Options().windowSize({ width: 1600, height: 1024 });
|
|
||||||
chromeOptions.addArguments('guest'); // disable password checks
|
|
||||||
if (process.env.CI) chromeOptions.addArguments('no-sandbox', 'disable-dev-shm-usage', 'headless');
|
|
||||||
browser = new Builder().forBrowser('chrome').setChromeOptions(chromeOptions).build();
|
|
||||||
if (!fs.existsSync('./screenshots')) fs.mkdirSync('./screenshots');
|
|
||||||
});
|
|
||||||
|
|
||||||
after(function () {
|
|
||||||
browser.quit();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(async function () {
|
afterEach(async function () {
|
||||||
if (!process.env.CI || !app) return;
|
await takeScreenshot(this.currentTest);
|
||||||
|
|
||||||
const currentUrl = await browser.getCurrentUrl();
|
|
||||||
if (!currentUrl.includes(app.domain)) return;
|
|
||||||
expect(this.currentTest.title).to.be.a('string');
|
|
||||||
|
|
||||||
const screenshotData = await browser.takeScreenshot();
|
|
||||||
fs.writeFileSync(`./screenshots/${new Date().getTime()}-${this.currentTest.title.replaceAll(' ', '_')}.png`, screenshotData, 'base64');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
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');
|
|
||||||
}
|
|
||||||
|
|
||||||
async function confirmLicense() {
|
async function confirmLicense() {
|
||||||
await timers.setTimeout(5000);
|
try {
|
||||||
await waitForElement(By.id('acknowledge-confirm'));
|
await waitFor('css=#acknowledge-confirm', { timeout: 10000 });
|
||||||
const button = await browser.findElement(By.id('acknowledge-confirm'));
|
await click('css=#acknowledge-confirm');
|
||||||
await browser.executeScript('arguments[0].scrollIntoView(false)', button);
|
} catch {
|
||||||
await browser.sleep(4000);
|
// license modal not shown
|
||||||
await button.click();
|
}
|
||||||
await browser.sleep(4000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function login(username, password, acceptLicense=false) {
|
async function login(accessKey, secretKey, acceptLicense = false) {
|
||||||
await browser.manage().deleteAllCookies();
|
await goto(`https://${app.fqdn}/login`, 'css=#accessKey');
|
||||||
await browser.get('about:blank');
|
await sendKeys('css=#accessKey', accessKey);
|
||||||
await browser.sleep(2000);
|
await sendKeys('css=#secretKey', secretKey);
|
||||||
await browser.get(`https://${app.fqdn}/login`);
|
await click('css=#do-login');
|
||||||
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);
|
|
||||||
await browser.findElement(By.xpath('//button[@id="do-login"]')).click();
|
|
||||||
|
|
||||||
if (acceptLicense) await confirmLicense();
|
if (acceptLicense) await confirmLicense();
|
||||||
|
|
||||||
await waitForElement(By.xpath('//button[contains(., "Create Bucket")]'));
|
await waitFor('Create Bucket');
|
||||||
await timers.setTimeout(5000);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function logout() {
|
|
||||||
await browser.sleep(10000);
|
|
||||||
// await browser.get(`https://${app.fqdn}/`);
|
|
||||||
await waitForElement(By.xpath('//button[contains(., "Create Bucket")]'));
|
|
||||||
|
|
||||||
const button = await browser.findElement(By.xpath('//button[@id="sign-out"]'));
|
|
||||||
await browser.executeScript('arguments[0].scrollIntoView(false)', button);
|
|
||||||
await button.click();
|
|
||||||
await browser.sleep(10000); // needed!
|
|
||||||
await waitForElement(By.xpath('//*[@id="accessKey"]'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addBucket() {
|
async function addBucket() {
|
||||||
// await browser.get(`https://${app.fqdn}/buckets`);
|
await click('Create Bucket');
|
||||||
await waitForElement(By.xpath('//button[contains(., "Create Bucket")]'));
|
await sendKeys('css=#bucket-name', BUCKET);
|
||||||
await browser.findElement(By.xpath('//button[contains(., "Create Bucket")]')).click();
|
await click('css=#create-bucket');
|
||||||
await browser.sleep(1000);
|
await waitFor(`xpath=//h1[contains(text(), "${BUCKET}")]`);
|
||||||
await waitForElement(By.xpath('//input[@id="bucket-name"]'));
|
|
||||||
await browser.findElement(By.xpath('//input[@id="bucket-name"]')).sendKeys(BUCKET);
|
|
||||||
await browser.findElement(By.xpath('//button[@id="create-bucket"]')).click();
|
|
||||||
// await browser.get(`https://${app.fqdn}/buckets`);
|
|
||||||
await waitForElement(By.xpath(`//h1[contains(text(), "${BUCKET}")]`));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkBucket() {
|
async function checkBucket() {
|
||||||
await browser.sleep(10000);
|
await waitFor(`xpath=//h1[contains(text(), "${BUCKET}")]`);
|
||||||
// await browser.get(`https://${app.fqdn}/buckets`);
|
|
||||||
await waitForElement(By.xpath(`//h1[contains(text(), "${BUCKET}")]`));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkRedirect() {
|
async function checkRedirect() {
|
||||||
const response = await superagent.get(`https://${app.secondaryDomains[0].fqdn}`).set('User-Agent', 'Mozilla/5.0').redirects(0).ok(() => true);
|
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);
|
assert.strictEqual(response.status, 307);
|
||||||
expect(response.headers.location).to.be(`https://${app.fqdn}`);
|
assert.strictEqual(response.headers.location, `https://${app.fqdn}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkApi() {
|
async function checkApi() {
|
||||||
const response = await superagent.get(`https://${app.secondaryDomains[0].fqdn}`).ok(() => true);
|
const response = await superagent.get(`https://${app.secondaryDomains[0].fqdn}`).ok(() => true);
|
||||||
expect(response.status).to.be(403);
|
assert.strictEqual(response.status, 403);
|
||||||
expect(response.body.toString('utf8')).to.contain('<Code>AccessDenied</Code>');
|
assert.ok(response.body.toString('utf8').includes('<Code>AccessDenied</Code>'));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function changeAdminCredentials() {
|
async function changeAdminCredentials() {
|
||||||
let data = fs.readFileSync(path.join(__dirname, '../env.sh.template'), 'utf8');
|
let data = fs.readFileSync(path.join(import.meta.dirname, '../env.sh.template'), 'utf8');
|
||||||
data += '\nexport MINIO_ROOT_USER=minioakey\nexport MINIO_ROOT_PASSWORD=minioskey\n';
|
data += '\nexport MINIO_ROOT_USER=minioakey\nexport MINIO_ROOT_PASSWORD=minioskey\n';
|
||||||
fs.writeFileSync('/tmp/env.sh', data);
|
fs.writeFileSync('/tmp/env.sh', data);
|
||||||
execSync(`cloudron push --app ${app.id} /tmp/env.sh /app/data/env.sh`, EXEC_ARGS);
|
await cloudronCli.push('/tmp/env.sh', '/app/data/env.sh');
|
||||||
execSync(`cloudron restart --app ${app.id}`, EXEC_ARGS);
|
await cloudronCli.restart();
|
||||||
await timers.setTimeout(10000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getAdminCredentials() {
|
it('install app', () => cloudronCli.install({ secondaryDomains: { API_SERVER_DOMAIN: `${LOCATION}-api` } }));
|
||||||
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); });
|
|
||||||
|
|
||||||
it('install app', async function () {
|
|
||||||
execSync(`cloudron install --location ${LOCATION} --secondary-domains API_SERVER_DOMAIN=${LOCATION}-api`, EXEC_ARGS);
|
|
||||||
await timers.setTimeout(10000);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('can get app information', getAppInfo);
|
|
||||||
it('can admin login', login.bind(null, 'minioadmin', 'minioadmin', true));
|
it('can admin login', login.bind(null, 'minioadmin', 'minioadmin', true));
|
||||||
it('can add bucket', addBucket);
|
it('can add bucket', addBucket);
|
||||||
it('can logout', logout);
|
it('can logout', clearCache);
|
||||||
it('does redirect', checkRedirect);
|
it('does redirect', checkRedirect);
|
||||||
it('check api', checkApi);
|
it('check api', checkApi);
|
||||||
|
|
||||||
it('can change admin credentials', changeAdminCredentials);
|
it('can change admin credentials', changeAdminCredentials);
|
||||||
|
|
||||||
it('can restart app', async function () {
|
it('can restart app', cloudronCli.restart);
|
||||||
execSync(`cloudron restart --app ${app.id}`, EXEC_ARGS);
|
|
||||||
await timers.setTimeout(10000);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('can admin login', login.bind(null, 'minioakey', 'minioskey', false));
|
it('can admin login', login.bind(null, 'minioakey', 'minioskey', false));
|
||||||
it('has bucket', checkBucket);
|
it('has bucket', checkBucket);
|
||||||
it('can logout', logout);
|
it('can logout', clearCache);
|
||||||
it('does redirect', checkRedirect);
|
it('does redirect', checkRedirect);
|
||||||
it('check api', checkApi);
|
it('check api', checkApi);
|
||||||
|
|
||||||
it('backup app', function () { execSync('cloudron backup create --app ' + app.id, EXEC_ARGS); });
|
it('backup app', cloudronCli.createBackup);
|
||||||
it('restore app', async function () {
|
it('restore app', cloudronCli.restoreFromLatestBackup);
|
||||||
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);
|
|
||||||
await timers.setTimeout(10000);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('can get app information', getAppInfo);
|
|
||||||
it('can admin login', login.bind(null, 'minioakey', 'minioskey', false));
|
it('can admin login', login.bind(null, 'minioakey', 'minioskey', false));
|
||||||
it('has bucket', checkBucket);
|
it('has bucket', checkBucket);
|
||||||
it('can logout', logout);
|
it('can logout', clearCache);
|
||||||
|
|
||||||
it('does redirect', checkRedirect);
|
it('does redirect', checkRedirect);
|
||||||
it('check api', checkApi);
|
it('check api', checkApi);
|
||||||
|
|
||||||
it('move to different location', async function () {
|
it('move to different location', cloudronCli.changeLocation);
|
||||||
browser.manage().deleteAllCookies();
|
|
||||||
execSync('cloudron configure --location ' + LOCATION + '2', EXEC_ARGS);
|
|
||||||
await timers.setTimeout(10000);
|
|
||||||
});
|
|
||||||
it('can get app information', getAppInfo);
|
|
||||||
|
|
||||||
it('can admin login', login.bind(null, 'minioakey', 'minioskey', true));
|
it('can admin login', login.bind(null, 'minioakey', 'minioskey', true));
|
||||||
it('has bucket', checkBucket);
|
it('has bucket', checkBucket);
|
||||||
it('can logout', logout);
|
it('can logout', clearCache);
|
||||||
|
|
||||||
it('does redirect', checkRedirect);
|
it('does redirect', checkRedirect);
|
||||||
it('check api', checkApi);
|
it('check api', checkApi);
|
||||||
|
|
||||||
it('uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); });
|
it('uninstall app', cloudronCli.uninstall);
|
||||||
|
|
||||||
// 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);
|
|
||||||
//
|
|
||||||
// it('can get admin credentials', getAdminCredentials);
|
|
||||||
// it('can admin login', async () => await login('minioadmin', rootPassword, true));
|
|
||||||
// it('can add buckets', addBucket);
|
|
||||||
// it('can logout', logout);
|
|
||||||
//
|
|
||||||
// it('can update', function () { execSync(`cloudron update --app ${LOCATION}`, EXEC_ARGS); });
|
|
||||||
// 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);
|
|
||||||
//
|
|
||||||
// it('can admin login', async () => await login('minioadmin', rootPassword, true));
|
|
||||||
// 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); });
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user