test.js 9.2 KB

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