2017-02-17 10:28:42 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2018-05-21 19:36:04 +00:00
|
|
|
require('chromedriver');
|
|
|
|
|
2017-02-17 10:28:42 +00:00
|
|
|
var execSync = require('child_process').execSync,
|
|
|
|
expect = require('expect.js'),
|
|
|
|
path = require('path'),
|
2018-05-31 20:59:21 +00:00
|
|
|
superagent = require('superagent'),
|
2017-02-17 10:28:42 +00:00
|
|
|
webdriver = require('selenium-webdriver');
|
|
|
|
|
|
|
|
var by = webdriver.By,
|
|
|
|
until = webdriver.until;
|
|
|
|
|
|
|
|
var username = 'admin',
|
2019-01-04 00:36:12 +00:00
|
|
|
password = 'changeme';
|
2017-02-17 10:28:42 +00:00
|
|
|
|
|
|
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
|
|
|
|
|
|
|
|
|
|
describe('Application life cycle test', function () {
|
|
|
|
this.timeout(0);
|
|
|
|
|
|
|
|
var chrome = require('selenium-webdriver/chrome');
|
|
|
|
var server, browser = new chrome.Driver();
|
|
|
|
|
|
|
|
before(function (done) {
|
|
|
|
var seleniumJar= require('selenium-server-standalone-jar');
|
|
|
|
var SeleniumServer = require('selenium-webdriver/remote').SeleniumServer;
|
|
|
|
server = new SeleniumServer(seleniumJar.path, { port: 4444 });
|
|
|
|
server.start();
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function (done) {
|
|
|
|
browser.quit();
|
|
|
|
server.stop();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2017-06-01 08:43:14 +00:00
|
|
|
var LOCATION = 'test';
|
2017-02-17 10:28:42 +00:00
|
|
|
var TEST_TIMEOUT = 10000;
|
|
|
|
var app;
|
|
|
|
|
2018-09-10 01:31:57 +00:00
|
|
|
function exists(selector) {
|
|
|
|
return browser.wait(until.elementLocated(selector), TEST_TIMEOUT);
|
2017-02-17 10:28:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function visible(selector, callback) {
|
2018-09-10 01:31:57 +00:00
|
|
|
return exists(selector).then(function () {
|
|
|
|
return browser.wait(until.elementIsVisible(browser.findElement(selector)), TEST_TIMEOUT);
|
2017-02-17 10:28:42 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-01-04 00:36:12 +00:00
|
|
|
function baseUrl() {
|
|
|
|
if (app.manifest.version === '1.4.0') return `https://${app.fqdn}/p`;
|
|
|
|
return `https://${app.fqdn}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we do this because it perm redirects to /p/ in old versions
|
|
|
|
function clearCache() {
|
|
|
|
// https://stackoverflow.com/questions/49614217/selenium-clear-chrome-cache
|
|
|
|
// defaut clearance is 1 hour of cache
|
|
|
|
return browser.get('chrome://settings/clearBrowserData').then(function () {
|
|
|
|
return visible(by.css('* /deep/ #clearBrowsingDataConfirm'));
|
|
|
|
}).then(function () {
|
|
|
|
return browser.findElement(by.css('* /deep/ #clearBrowsingDataConfirm')).click();
|
|
|
|
}).then(function () {
|
|
|
|
return browser.sleep(5000);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function login(password, callback) {
|
2019-07-29 18:47:10 +00:00
|
|
|
browser.get('https://' + app.fqdn).then(function () {
|
2018-09-10 01:31:57 +00:00
|
|
|
return visible(by.id('loginButton'));
|
|
|
|
}).then(function () {
|
|
|
|
return browser.findElement(by.id('username')).sendKeys(username);
|
|
|
|
}).then(function () {
|
|
|
|
return browser.findElement(by.id('passwordPlain')).sendKeys(password);
|
|
|
|
}).then(function () {
|
|
|
|
return browser.findElement(by.id('loginButton')).click();
|
|
|
|
}).then(function () {
|
|
|
|
return browser.wait(until.elementLocated(by.id('dropdown-configure')), TEST_TIMEOUT);
|
|
|
|
}).then(function () {
|
|
|
|
callback();
|
2017-02-17 10:28:42 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function logout(callback) {
|
|
|
|
var logout_btn = by.xpath('//ul[@class="dropdown-menu"]/li/a[@class="signout"]');
|
|
|
|
|
2018-09-10 01:31:57 +00:00
|
|
|
browser.get('https://' + app.fqdn).then(function () {
|
|
|
|
return visible(by.id('stream'));
|
|
|
|
}).then(function () {
|
|
|
|
return browser.findElement(by.className('dropdown-toggle')).click();
|
|
|
|
}).then(function () {
|
|
|
|
return visible(logout_btn);
|
|
|
|
}).then(function () {
|
|
|
|
return browser.findElement(logout_btn).click();
|
|
|
|
}).then(function () {
|
|
|
|
return browser.wait(until.elementLocated(by.id('loginButton')), TEST_TIMEOUT);
|
|
|
|
}).then(function () {
|
|
|
|
callback();
|
2017-02-17 10:28:42 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function addSubscription(callback) {
|
|
|
|
var url = "https://cloudron.io/blog/rss.xml";
|
|
|
|
|
2019-01-04 00:36:12 +00:00
|
|
|
browser.get(`${baseUrl()}/i/?c=subscription`).then(function () {
|
2018-09-10 01:45:51 +00:00
|
|
|
return visible(by.xpath('//input[@name="url_rss"]'));
|
2018-09-10 01:31:57 +00:00
|
|
|
}).then(function () {
|
|
|
|
return browser.findElement(by.xpath('//input[@name="url_rss"]')).sendKeys(url);
|
|
|
|
}).then(function () {
|
|
|
|
return browser.findElement(by.xpath('//form[@id="add_rss"]/div/button[@type="submit"]')).click();
|
|
|
|
}).then(function () {
|
|
|
|
return visible(by.xpath('//div[@id="notification" and @class="notification good"]'));
|
|
|
|
}).then(function () {
|
|
|
|
callback();
|
2017-02-17 10:28:42 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-01-04 00:36:12 +00:00
|
|
|
function addUser(password, callback) {
|
2017-02-17 10:28:42 +00:00
|
|
|
var test_username = 'test';
|
|
|
|
|
2019-01-04 00:36:12 +00:00
|
|
|
browser.get(`${baseUrl()}/i/?c=user&a=manage`).then(function () {
|
2018-09-10 01:31:57 +00:00
|
|
|
return visible(by.id('new_user_name'));
|
|
|
|
}).then(function () {
|
|
|
|
return browser.findElement(by.id('new_user_name')).sendKeys(test_username);
|
|
|
|
}).then(function () {
|
|
|
|
return browser.findElement(by.id('new_user_passwordPlain')).sendKeys(password);
|
|
|
|
}).then(function () {
|
2018-09-10 01:45:51 +00:00
|
|
|
return browser.findElement(by.xpath('//button[text()="Create"]')).click();
|
2018-09-10 01:31:57 +00:00
|
|
|
}).then(function () {
|
|
|
|
return visible(by.xpath('//div[@id="notification" and @class="notification good"]'));
|
|
|
|
}).then(function () {
|
|
|
|
callback();
|
2017-02-17 10:28:42 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-24 18:19:26 +00:00
|
|
|
function enableApi(callback) {
|
2019-01-04 00:36:12 +00:00
|
|
|
browser.get(`${baseUrl()}/i/?c=auth`).then(function () {
|
2017-05-24 18:19:26 +00:00
|
|
|
return browser.findElement(by.id('api_enabled')).click();
|
|
|
|
}).then(function () {
|
2018-09-10 01:45:51 +00:00
|
|
|
return browser.findElement(by.xpath('//button[text()="Submit"]')).submit();
|
2018-09-10 01:31:57 +00:00
|
|
|
}).then(function () {
|
|
|
|
callback();
|
|
|
|
});
|
2017-05-24 18:19:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkApiConfiguration(callback) {
|
2019-02-03 23:55:19 +00:00
|
|
|
browser.get(`${baseUrl()}/api/`).then(function () {
|
|
|
|
return exists(by.xpath('//dd[@id="greaderOutput" and contains(text(), "PASS")]'));
|
|
|
|
}).then(function () {
|
|
|
|
return exists(by.xpath('//dd[@id="feverOutput" and contains(text(), "PASS")]'));
|
2018-09-10 01:31:57 +00:00
|
|
|
}).then(function () {
|
|
|
|
callback();
|
2017-05-24 18:19:26 +00:00
|
|
|
});
|
|
|
|
}
|
2017-02-17 10:28:42 +00:00
|
|
|
|
2018-03-19 11:01:48 +00:00
|
|
|
function getAppInfo() {
|
|
|
|
var inspect = JSON.parse(execSync('cloudron inspect'));
|
|
|
|
app = inspect.apps.filter(function (a) { return a.location === LOCATION || a.location === LOCATION + '2'; })[0];
|
|
|
|
expect(app).to.be.an('object');
|
|
|
|
}
|
|
|
|
|
|
|
|
function subscriptionExists(callback) {
|
2019-01-04 00:36:12 +00:00
|
|
|
browser.get(`${baseUrl()}/i/?get=c_1`).then(function () {
|
2018-09-10 01:31:57 +00:00
|
|
|
return visible(by.xpath('//a[text()="Cloudron.io"]'));
|
|
|
|
}).then(function () {
|
|
|
|
callback();
|
|
|
|
});
|
2018-03-19 11:01:48 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 20:59:21 +00:00
|
|
|
function getStaticExtensionFile(callback) {
|
2019-01-04 00:36:12 +00:00
|
|
|
superagent.get(`${baseUrl()}/ext.php?f=xExtension-StickyFeeds/static/script.js&t=js`)
|
2018-05-31 20:59:21 +00:00
|
|
|
.buffer(true)
|
|
|
|
.end(function (err, res) {
|
|
|
|
expect(err).to.be(null);
|
|
|
|
expect(res.status).to.be(200);
|
|
|
|
expect(res.text).to.contain('sticky_feeds'); // relies on the buffer flag above
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-02-17 10:28:42 +00:00
|
|
|
xit('build app', function () {
|
|
|
|
execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('install app', function () {
|
2019-11-22 18:26:47 +00:00
|
|
|
execSync('cloudron install --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
2017-02-17 10:28:42 +00:00
|
|
|
});
|
|
|
|
|
2018-03-19 11:01:48 +00:00
|
|
|
it('can get app information', getAppInfo);
|
2017-02-17 10:28:42 +00:00
|
|
|
|
2019-01-04 00:36:12 +00:00
|
|
|
it('can login', login.bind(null, password));
|
2017-02-17 10:28:42 +00:00
|
|
|
it('can subscribe', addSubscription);
|
2019-01-04 00:36:12 +00:00
|
|
|
it('can add users', addUser.bind(null, password));
|
2017-05-24 18:19:26 +00:00
|
|
|
it('can enable API', enableApi);
|
|
|
|
it('can check configuration', checkApiConfiguration);
|
2018-03-19 11:01:48 +00:00
|
|
|
it('subscription exists', subscriptionExists);
|
2018-05-31 20:59:21 +00:00
|
|
|
it('can get static extension file', getStaticExtensionFile);
|
2017-02-17 10:28:42 +00:00
|
|
|
it('can logout', logout);
|
|
|
|
|
|
|
|
it('backup app', function () {
|
|
|
|
execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('restore app', function () {
|
|
|
|
execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
|
});
|
|
|
|
|
2019-01-04 00:36:12 +00:00
|
|
|
it('can login', login.bind(null, password));
|
2017-05-24 18:19:26 +00:00
|
|
|
it('can check configuration', checkApiConfiguration);
|
2018-03-19 11:01:48 +00:00
|
|
|
it('subscription exists', subscriptionExists);
|
2018-05-31 20:59:21 +00:00
|
|
|
it('can get static extension file', getStaticExtensionFile);
|
2017-02-17 10:28:42 +00:00
|
|
|
it('can logout', logout);
|
|
|
|
|
|
|
|
it('move to different location', function () {
|
|
|
|
browser.manage().deleteAllCookies();
|
2019-11-22 18:26:47 +00:00
|
|
|
execSync('cloudron configure --location ' + LOCATION + '2 --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
2017-02-17 10:28:42 +00:00
|
|
|
var inspect = JSON.parse(execSync('cloudron inspect'));
|
|
|
|
app = inspect.apps.filter(function (a) { return a.location === LOCATION + '2'; })[0];
|
|
|
|
expect(app).to.be.an('object');
|
|
|
|
});
|
|
|
|
|
2019-01-04 00:36:12 +00:00
|
|
|
it('can login', login.bind(null, password));
|
2017-05-24 18:19:26 +00:00
|
|
|
it('can check configuration', checkApiConfiguration);
|
2018-03-19 11:01:48 +00:00
|
|
|
it('subscription exists', subscriptionExists);
|
2018-05-31 20:59:21 +00:00
|
|
|
it('can get static extension file', getStaticExtensionFile);
|
2017-02-17 10:28:42 +00:00
|
|
|
it('can logout', logout);
|
|
|
|
|
|
|
|
it('uninstall app', function () {
|
|
|
|
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
|
});
|
|
|
|
|
2018-03-19 11:01:48 +00:00
|
|
|
// test update
|
|
|
|
it('can install app', function () {
|
2019-11-22 18:26:47 +00:00
|
|
|
execSync('cloudron install --appstore-id org.freshrss.cloudronapp --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
2018-03-19 11:01:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('can get app information', getAppInfo);
|
2019-02-03 23:55:19 +00:00
|
|
|
it('can login', login.bind(null, password));
|
2018-03-19 11:01:48 +00:00
|
|
|
it('can subscribe', addSubscription);
|
2019-01-04 00:36:12 +00:00
|
|
|
it('can add users', addUser.bind(null, password));
|
2018-03-19 11:01:48 +00:00
|
|
|
|
|
|
|
it('can update', function () {
|
2019-11-22 18:26:47 +00:00
|
|
|
execSync('cloudron update --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
2018-03-19 11:01:48 +00:00
|
|
|
var inspect = JSON.parse(execSync('cloudron inspect'));
|
|
|
|
app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
|
|
|
|
expect(app).to.be.an('object');
|
|
|
|
});
|
|
|
|
|
2019-02-03 23:55:19 +00:00
|
|
|
it('can login', login.bind(null, password));
|
2018-03-19 11:01:48 +00:00
|
|
|
it('subscription exists', subscriptionExists);
|
2018-05-31 20:59:21 +00:00
|
|
|
it('can get static extension file', getStaticExtensionFile);
|
2018-03-19 11:01:48 +00:00
|
|
|
|
|
|
|
it('uninstall app', function () {
|
|
|
|
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
|
});
|
2017-02-17 10:28:42 +00:00
|
|
|
});
|