test.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #!/usr/bin/env node
  2. 'use strict';
  3. var execSync = require('child_process').execSync,
  4. expect = require('expect.js'),
  5. path = require('path'),
  6. util = require('util'),
  7. webdriver = require('selenium-webdriver');
  8. var by = webdriver.By,
  9. until = webdriver.until;
  10. process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
  11. if (!process.env.USERNAME || !process.env.PASSWORD) {
  12. console.log('USERNAME and PASSWORD env vars need to be set');
  13. process.exit(1);
  14. }
  15. describe('Application life cycle test', function () {
  16. this.timeout(0);
  17. var chrome = require('selenium-webdriver/chrome');
  18. var server, browser = new chrome.Driver();
  19. before(function (done) {
  20. var seleniumJar= require('selenium-server-standalone-jar');
  21. var SeleniumServer = require('selenium-webdriver/remote').SeleniumServer;
  22. server = new SeleniumServer(seleniumJar.path, { port: 4444 });
  23. server.start();
  24. done();
  25. });
  26. after(function (done) {
  27. browser.quit();
  28. server.stop();
  29. done();
  30. });
  31. var LOCATION = 'test';
  32. var TEST_TIMEOUT = 50000;
  33. var app;
  34. function waitForElement(elem, callback) {
  35. browser.wait(until.elementLocated(elem), TEST_TIMEOUT).then(function () {
  36. browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT).then(function () {
  37. callback();
  38. });
  39. });
  40. }
  41. function welcomePage(callback) {
  42. browser.get('https://' + app.fqdn);
  43. waitForElement(by.xpath('//*[text()="Cloudron LAMP App"]'), function () {
  44. waitForElement(by.xpath('//*[text()="PHP Version 7.0.15-0ubuntu0.16.04.4"]'), callback);
  45. });
  46. }
  47. function uploadedFileExists(callback) {
  48. browser.get('https://' + app.fqdn + '/test.php');
  49. waitForElement(by.xpath('//*[text()="this works"]'), function () {
  50. waitForElement(by.xpath('//*[text()="' + app.fqdn + '"]'), callback);
  51. });
  52. }
  53. function checkPhpMyAdmin(callback) {
  54. browser.get('https://' + app.fqdn + '/phpmyadmin');
  55. browser.wait(by.xpath('//h2[text()="General settings"]'), TEST_TIMEOUT)
  56. .catch(function () {
  57. // let's assume we could not login
  58. browser.get('https://' + process.env.USERNAME + ':' + process.env.PASSWORD + '@' + app.fqdn + '/phpmyadmin');
  59. waitForElement(by.xpath('//h2[text()="General settings"]'), callback);
  60. });
  61. }
  62. xit('build app', function () {
  63. execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  64. });
  65. it('install app', function () {
  66. execSync('cloudron install --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  67. });
  68. it('can get app information', function () {
  69. var inspect = JSON.parse(execSync('cloudron inspect'));
  70. app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
  71. expect(app).to.be.an('object');
  72. });
  73. it('can view welcome page', welcomePage);
  74. it('can upload file with sftp', function () {
  75. // remove from known hosts in case this test was run on other apps with the same domain already
  76. execSync(util.format('sed -i \'/%s/d\' -i ~/.ssh/known_hosts', app.fqdn));
  77. execSync(util.format('lftp sftp://%s:%s@%s:%s -e "set sftp:auto-confirm yes; cd public/; put test.php; bye"', process.env.USERNAME, process.env.PASSWORD, app.fqdn, app.portBindings.SFTP_PORT));
  78. });
  79. it('can get uploaded file', uploadedFileExists);
  80. it('can access phpmyadmin', checkPhpMyAdmin);
  81. it('backup app', function () {
  82. execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  83. });
  84. it('restore app', function () {
  85. execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  86. });
  87. it('can get uploaded file', uploadedFileExists);
  88. it('move to different location', function () {
  89. browser.manage().deleteAllCookies();
  90. execSync('cloudron configure --wait --location ' + LOCATION + '2 --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  91. var inspect = JSON.parse(execSync('cloudron inspect'));
  92. app = inspect.apps.filter(function (a) { return a.location === LOCATION + '2'; })[0];
  93. expect(app).to.be.an('object');
  94. });
  95. it('can get uploaded file', uploadedFileExists);
  96. it('uninstall app', function () {
  97. execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  98. });
  99. });