test.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #!/usr/bin/env node
  2. 'use strict';
  3. var execSync = require('child_process').execSync,
  4. ejs = require('ejs'),
  5. expect = require('expect.js'),
  6. fs = require('fs'),
  7. mkdirp = require('mkdirp'),
  8. path = require('path'),
  9. rimraf = require('rimraf'),
  10. superagent = require('superagent'),
  11. webdriver = require('selenium-webdriver');
  12. var firefox = require('selenium-webdriver/firefox');
  13. var server, browser = new firefox.Driver();
  14. var by = require('selenium-webdriver').By,
  15. until = require('selenium-webdriver').until;
  16. process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
  17. describe('Application life cycle test', function () {
  18. this.timeout(0);
  19. var server, browser = new require('selenium-webdriver/firefox').Driver();
  20. before(function (done) {
  21. if (!process.env.USERNAME) return done(new Error('USERNAME env var not set'));
  22. if (!process.env.PASSWORD) return done(new Error('PASSWORD env var not set'));
  23. var seleniumJar= require('selenium-server-standalone-jar');
  24. var SeleniumServer = require('selenium-webdriver/remote').SeleniumServer;
  25. server = new SeleniumServer(seleniumJar.path, { port: 4444 });
  26. server.start();
  27. });
  28. after(function () {
  29. browser.quit();
  30. server.stop();
  31. });
  32. var LOCATION = 'test' + Date.now();
  33. var app, reponame = 'testrepo';
  34. var username = process.env.USERNAME;
  35. var password = process.env.PASSWORD;
  36. it('build app', function () {
  37. execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  38. });
  39. it('install app', function () {
  40. execSync('cloudron install --new --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  41. });
  42. it('can get app information', function () {
  43. var inspect = JSON.parse(execSync('cloudron inspect'));
  44. app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
  45. expect(app).to.be.an('object');
  46. });
  47. it('can get the main page', function (done) {
  48. superagent.get('https://' + app.fqdn).end(function (error, result) {
  49. expect(error).to.be(null);
  50. expect(result.status).to.eql(200);
  51. done();
  52. });
  53. });
  54. it('can login', function (done) {
  55. browser.get('https://' + app.fqdn + '/user/login');
  56. browser.findElement(by.id('user_name')).sendKeys(username);
  57. browser.findElement(by.id('password')).sendKeys(password);
  58. browser.findElement(by.tagName('form')).submit();
  59. browser.wait(until.elementLocated(by.linkText('Dashboard')), 4000);
  60. done();
  61. });
  62. it('can add public key', function (done) {
  63. browser.get('https://' + app.fqdn + '/user/settings/ssh');
  64. var publicKey = fs.readFileSync(__dirname + '/id_rsa.pub', 'utf8');
  65. browser.findElement(by.xpath('//div[text()="Add Key"]')).click();
  66. browser.findElement(by.id('title')).sendKeys('testkey');
  67. browser.findElement(by.id('content')).sendKeys(publicKey);
  68. browser.findElement(by.xpath('//button[contains(text(), "Add Key")]')).click();
  69. browser.wait(until.elementLocated(by.xpath('p[contains(text(), "added successfully!")]')), 4000);
  70. done();
  71. });
  72. it('can create repo', function (done) {
  73. browser.get('https://' + app.fqdn);
  74. browser.findElement(by.linkText('New Repository')).click();
  75. browser.wait(until.elementLocated(by.xpath('//*[contains(text(), "New Repository")]')), 4000);
  76. browser.findElement(by.id('repo_name')).sendKeys(reponame);
  77. browser.findElement(by.id('auto-init')).click();
  78. browser.findElement(by.xpath('//button[contains(text(), "Create Repository")]')).click();
  79. browser.wait(function () {
  80. return browser.getCurrentUrl().then(function (url) {
  81. return url === 'https://' + app.fqdn + '/' + username + '/' + reponame;
  82. });
  83. }, 4000);
  84. done();
  85. });
  86. it('displays correct clone url', function (done) {
  87. browser.get('https://' + app.fqdn + '/' + username + '/' + reponame);
  88. browser.findElement(by.id('repo-clone-url')).getAttribute('value').then(function (cloneUrl) {
  89. expect(cloneUrl).to.be('ssh://cloudron@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git');
  90. done();
  91. });
  92. });
  93. it('can clone the url', function (done) {
  94. execSync('git clone ssh://cloudron@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git /tmp/testrepo', { env: { GIT_SSH : __dirname + '/git_ssh_wrapper.sh' } });
  95. rimraf.sync('/tmp/testrepo');
  96. done();
  97. });
  98. it('backup app', function () {
  99. execSync('cloudron backup --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  100. });
  101. it('restore app', function () {
  102. execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  103. });
  104. it('can clone the url', function (done) {
  105. execSync('git clone ssh://cloudron@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git /tmp/testrepo', { env: { GIT_SSH : __dirname + '/git_ssh_wrapper.sh' } });
  106. rimraf.sync('/tmp/testrepo');
  107. done();
  108. });
  109. it('uninstall app', function () {
  110. execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  111. });
  112. });