test.js 5.1 KB

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