test.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #!/usr/bin/env node
  2. /* jslint node:true */
  3. /* global it:false */
  4. /* global xit:false */
  5. /* global describe:false */
  6. /* global before:false */
  7. /* global after:false */
  8. 'use strict';
  9. var execSync = require('child_process').execSync,
  10. ejs = require('ejs'),
  11. expect = require('expect.js'),
  12. fs = require('fs'),
  13. mkdirp = require('mkdirp'),
  14. path = require('path'),
  15. rimraf = require('rimraf'),
  16. superagent = require('superagent'),
  17. webdriver = require('selenium-webdriver');
  18. var by = require('selenium-webdriver').By,
  19. until = require('selenium-webdriver').until;
  20. process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
  21. describe('Application life cycle test', function () {
  22. this.timeout(0);
  23. var firefox = require('selenium-webdriver/firefox');
  24. var server, browser = new firefox.Driver();
  25. var LOCATION = 'gogstest';
  26. var repodir = '/tmp/testrepo';
  27. var app, reponame = 'testrepo';
  28. var username = process.env.USERNAME;
  29. var password = process.env.PASSWORD;
  30. before(function (done) {
  31. if (!process.env.USERNAME) return done(new Error('USERNAME env var not set'));
  32. if (!process.env.PASSWORD) return done(new Error('PASSWORD env var not set'));
  33. var seleniumJar= require('selenium-server-standalone-jar');
  34. var SeleniumServer = require('selenium-webdriver/remote').SeleniumServer;
  35. server = new SeleniumServer(seleniumJar.path, { port: 4444 });
  36. server.start();
  37. done();
  38. });
  39. after(function (done) {
  40. browser.quit();
  41. server.stop();
  42. rimraf.sync(repodir);
  43. done();
  44. });
  45. xit('build app', function () {
  46. execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  47. });
  48. it('install app', function () {
  49. execSync('cloudron install --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  50. });
  51. it('can get app information', function () {
  52. var inspect = JSON.parse(execSync('cloudron inspect'));
  53. app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
  54. expect(app).to.be.an('object');
  55. });
  56. it('can get the main page', function (done) {
  57. superagent.get('https://' + app.fqdn).end(function (error, result) {
  58. expect(error).to.be(null);
  59. expect(result.status).to.eql(200);
  60. done();
  61. });
  62. });
  63. it('can login', function (done) {
  64. browser.get('https://' + app.fqdn + '/user/login');
  65. browser.findElement(by.id('user_name')).sendKeys(username);
  66. browser.findElement(by.id('password')).sendKeys(password);
  67. browser.findElement(by.tagName('form')).submit();
  68. browser.wait(until.elementLocated(by.linkText('Dashboard')), 4000).then(function () { done(); });
  69. });
  70. it('can add public key', function (done) {
  71. browser.get('https://' + app.fqdn + '/user/settings/ssh');
  72. var publicKey = fs.readFileSync(__dirname + '/id_rsa.pub', 'utf8');
  73. browser.findElement(by.xpath('//div[text()="Add Key"]')).click();
  74. browser.findElement(by.id('title')).sendKeys('testkey');
  75. browser.findElement(by.id('content')).sendKeys(publicKey);
  76. browser.findElement(by.xpath('//button[contains(text(), "Add Key")]')).click();
  77. browser.wait(until.elementLocated(by.xpath('//p[contains(text(), "added successfully!")]')), 4000).then(function () { done(); });
  78. });
  79. it('can create repo', function (done) {
  80. browser.get('https://' + app.fqdn);
  81. browser.findElement(by.linkText('New Repository')).click();
  82. browser.wait(until.elementLocated(by.xpath('//*[contains(text(), "New Repository")]')), 4000);
  83. browser.findElement(by.id('repo_name')).sendKeys(reponame);
  84. browser.findElement(by.id('auto-init')).click();
  85. browser.findElement(by.xpath('//button[contains(text(), "Create Repository")]')).click();
  86. browser.wait(function () {
  87. return browser.getCurrentUrl().then(function (url) {
  88. return url === 'https://' + app.fqdn + '/' + username + '/' + reponame;
  89. });
  90. }, 4000).then(function () { done(); });
  91. });
  92. it('displays correct clone url', function (done) {
  93. browser.get('https://' + app.fqdn + '/' + username + '/' + reponame);
  94. browser.findElement(by.id('repo-clone-ssh')).click();
  95. browser.findElement(by.id('repo-clone-url')).getAttribute('value').then(function (cloneUrl) {
  96. expect(cloneUrl).to.be('ssh://cloudron@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git');
  97. done();
  98. });
  99. });
  100. it('can clone the url', function (done) {
  101. var env = Object.create(process.env);
  102. env.GIT_SSH = __dirname + '/git_ssh_wrapper.sh';
  103. execSync('git clone ssh://cloudron@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git ' + repodir, { env: env });
  104. done();
  105. });
  106. it('can add and push a file', function (done) {
  107. var env = Object.create(process.env);
  108. env.GIT_SSH = __dirname + '/git_ssh_wrapper.sh';
  109. execSync('touch newfile && git add newfile && git commit -a -mx && git push ssh://cloudron@' + app.fqdn + ':29418/' + username + '/' + reponame + ' master',
  110. { env: env, cwd: repodir });
  111. rimraf.sync('/tmp/testrepo');
  112. done();
  113. });
  114. it('can restart app', function (done) {
  115. execSync('cloudron restart');
  116. done();
  117. });
  118. it('can clone the url', function (done) {
  119. var env = Object.create(process.env);
  120. env.GIT_SSH = __dirname + '/git_ssh_wrapper.sh';
  121. execSync('git clone ssh://cloudron@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git ' + repodir, { env: env });
  122. expect(fs.existsSync(repodir + '/newfile')).to.be(true);
  123. rimraf.sync(repodir);
  124. done();
  125. });
  126. it('backup app', function () {
  127. execSync('cloudron backup --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  128. });
  129. it('restore app', function () {
  130. execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  131. });
  132. it('can clone the url', function (done) {
  133. var env = Object.create(process.env);
  134. env.GIT_SSH = __dirname + '/git_ssh_wrapper.sh';
  135. execSync('git clone ssh://cloudron@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git ' + repodir, { env: env });
  136. expect(fs.existsSync(repodir + '/newfile')).to.be(true);
  137. rimraf.sync(repodir);
  138. done();
  139. });
  140. it('move to different location', function () {
  141. browser.manage().deleteAllCookies();
  142. execSync('cloudron install --location ' + LOCATION + '2', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  143. var inspect = JSON.parse(execSync('cloudron inspect'));
  144. app = inspect.apps.filter(function (a) { return a.location === LOCATION + '2'; })[0];
  145. expect(app).to.be.an('object');
  146. });
  147. it('can login', function (done) {
  148. browser.get('https://' + app.fqdn + '/user/login');
  149. browser.findElement(by.id('user_name')).sendKeys(username);
  150. browser.findElement(by.id('password')).sendKeys(password);
  151. browser.findElement(by.tagName('form')).submit();
  152. browser.wait(until.elementLocated(by.linkText('Dashboard')), 4000).then(function () { done(); });
  153. });
  154. it('displays correct clone url', function (done) {
  155. browser.get('https://' + app.fqdn + '/' + username + '/' + reponame);
  156. browser.findElement(by.id('repo-clone-ssh')).click();
  157. browser.findElement(by.id('repo-clone-url')).getAttribute('value').then(function (cloneUrl) {
  158. expect(cloneUrl).to.be('ssh://cloudron@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git');
  159. done();
  160. });
  161. });
  162. it('can clone the url', function (done) {
  163. var env = Object.create(process.env);
  164. env.GIT_SSH = __dirname + '/git_ssh_wrapper.sh';
  165. execSync('git clone ssh://cloudron@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git ' + repodir, { env: env });
  166. expect(fs.existsSync(repodir + '/newfile')).to.be(true);
  167. rimraf.sync(repodir);
  168. done();
  169. });
  170. it('uninstall app', function () {
  171. execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  172. });
  173. });