test.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. #!/usr/bin/env node
  2. /* global describe */
  3. /* global after */
  4. /* global it */
  5. 'use strict';
  6. require('chromedriver');
  7. var execSync = require('child_process').execSync,
  8. expect = require('expect.js'),
  9. path = require('path'),
  10. webdriver = require('selenium-webdriver');
  11. var by = webdriver.By,
  12. Keys = webdriver.Key,
  13. until = webdriver.until;
  14. process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
  15. if (!process.env.USERNAME || !process.env.PASSWORD) {
  16. console.log('USERNAME and PASSWORD env vars need to be set');
  17. process.exit(1);
  18. }
  19. describe('Application life cycle test SSO', function () {
  20. this.timeout(0);
  21. var chrome = require('selenium-webdriver/chrome');
  22. var server, browser = new chrome.Driver();
  23. after(function () {
  24. browser.quit();
  25. });
  26. var LOCATION = 'test';
  27. var TEST_TIMEOUT = 100000;
  28. var PROJECT_NAME = 'testproject';
  29. var PROJECT_DESCRIPTION = 'testdescription';
  30. var USER_STORY_SUBJECT = 'someteststory';
  31. var app;
  32. function waitForElement(elem) {
  33. return browser.wait(until.elementLocated(elem), TEST_TIMEOUT).then(function () {
  34. return browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT);
  35. });
  36. }
  37. function login(callback) {
  38. browser.manage().deleteAllCookies();
  39. browser.get('https://' + app.fqdn).then(function () {
  40. return browser.executeScript('localStorage.clear();');
  41. }).then(function () {
  42. browser.executeScript('sessionStorage.clear();');
  43. }).then(function () {
  44. browser.get('https://' + app.fqdn + '/login?next=%252Fprofile');
  45. }).then(function () {
  46. return waitForElement(by.name('username'));
  47. }).then(function () {
  48. return browser.findElement(by.name('username')).sendKeys(process.env.USERNAME);
  49. }).then(function () {
  50. return browser.findElement(by.name('password')).sendKeys(process.env.PASSWORD);
  51. }).then(function () {
  52. return browser.findElement(by.className('login-form')).submit();
  53. }).then(function () {
  54. return waitForElement(by.xpath('//h4[text()="Your profile"]'));
  55. }).then(function () {
  56. callback();
  57. });
  58. }
  59. function signUp(callback) {
  60. browser.manage().deleteAllCookies();
  61. browser.get(`https://${app.fqdn}`).then(function () {
  62. return browser.executeScript('localStorage.clear();');
  63. }).then(function () {
  64. return browser.executeScript('sessionStorage.clear();');
  65. }).then(function () {
  66. return browser.get(`https://${app.fqdn}/register`);
  67. }).then(function () {
  68. return waitForElement(by.name('username'));
  69. }).then(function () {
  70. return browser.findElement(by.name('username')).sendKeys(process.env.USERNAME);
  71. }).then(function () {
  72. return browser.findElement(by.name('full_name')).sendKeys(process.env.USERNAME + ' Name');
  73. }).then(function () {
  74. return browser.findElement(by.name('email')).sendKeys('test@cloudron.io');
  75. }).then(function () {
  76. return browser.findElement(by.name('password')).sendKeys(process.env.PASSWORD);
  77. }).then(function () {
  78. return browser.findElement(by.xpath('//button[@title="Sign up"]')).click();
  79. }).then(function () {
  80. return waitForElement(by.xpath('//p[contains(text(), "Welcome! Here you will find the projects you are involved on.")]'));
  81. }).then(function () {
  82. callback();
  83. });
  84. }
  85. function adminLogin(callback) {
  86. browser.get('https://' + app.fqdn + '/admin/login/').then(function () {
  87. return browser.findElement(by.name('username')).sendKeys('admin');
  88. }).then(function () {
  89. return browser.findElement(by.name('password')).sendKeys('123123');
  90. }).then(function () {
  91. return browser.findElement(by.id('login-form')).submit();
  92. }).then(function () {
  93. return waitForElement(by.xpath('//h1[text()="Site administration"]'));
  94. }).then(function () {
  95. return browser.findElement(by.xpath('//a[text()="Log out"]')).click();
  96. }).then(function () {
  97. return browser.sleep(2000);
  98. }).then(function () {
  99. callback();
  100. });
  101. }
  102. function userStoryExists(callback) {
  103. browser.get('https://' + app.fqdn + '/project/' + process.env.USERNAME + '-' + PROJECT_NAME + '/us/1').then(function () {
  104. return waitForElement(by.xpath('//span[text()="' + USER_STORY_SUBJECT + '"]'));
  105. }).then(function () {
  106. callback();
  107. });
  108. }
  109. function getAppInfo() {
  110. var inspect = JSON.parse(execSync('cloudron inspect'));
  111. app = inspect.apps.filter(function (a) { return a.location === LOCATION || a.location === LOCATION + '2'; })[0];
  112. expect(app).to.be.an('object');
  113. }
  114. function dismissTutorial(done) {
  115. browser.get('https://' + app.fqdn);
  116. waitForElement(by.className('introjs-skipbutton')).then(function () {
  117. return browser.findElement(by.className('introjs-skipbutton')).sendKeys(Keys.ENTER);
  118. }).then(function () {
  119. // give some time to ack
  120. setTimeout(done, 5000);
  121. });
  122. }
  123. function createProject(done) {
  124. browser.get('https://' + app.fqdn + '/project/new/scrum').then(function () {
  125. return waitForElement(by.name('project-name'));
  126. }).then(function () {
  127. return browser.findElement(by.name('project-name')).sendKeys(PROJECT_NAME);
  128. }).then(function () {
  129. return browser.sleep(1000); // it needs some time to change focus!!
  130. }).then(function () {
  131. return browser.findElement(by.xpath('//textarea[@placeholder="Project Description"]')).sendKeys(PROJECT_DESCRIPTION);
  132. }).then(function () {
  133. return browser.sleep(1000);
  134. }).then(function () {
  135. return browser.findElement(by.xpath('//button[text()="Create Project"]')).click();
  136. }).then(function () {
  137. return browser.wait(until.elementLocated(by.xpath('//span[text()[contains(., "' + PROJECT_NAME + '")]]')), TEST_TIMEOUT);
  138. }).then(function () {
  139. done();
  140. });
  141. }
  142. function createUserStory(done) {
  143. browser.get('https://' + app.fqdn + '/project/' + process.env.USERNAME + '-' + PROJECT_NAME + '/backlog').then(function () {
  144. return waitForElement(by.xpath('//a[@tg-check-permission="add_us"]'));
  145. }).then(function () {
  146. // clicks don't work with taiga
  147. return browser.findElement(by.xpath('//a[@tg-check-permission="add_us"]')).sendKeys(Keys.ENTER);
  148. }).then(function () {
  149. return waitForElement(by.name('subject'));
  150. }).then(function () {
  151. return browser.findElement(by.name('subject')).sendKeys(USER_STORY_SUBJECT);
  152. }).then(function () {
  153. return waitForElement(by.xpath('/html/body/div[2]/div/div/div[1]/form/div[2]/button'));
  154. }).then(function () {
  155. return browser.findElement(by.xpath('/html/body/div[2]/div/div/div[1]/form/div[2]/button')).sendKeys(Keys.ENTER);
  156. }).then(function () {
  157. return waitForElement(by.xpath('//span[text()[contains(., "' + USER_STORY_SUBJECT + '")]]'));
  158. }).then(function () {
  159. done();
  160. });
  161. }
  162. function deleteProject(done) {
  163. browser.get('https://' + app.fqdn + '/project/' + process.env.USERNAME + '-' + PROJECT_NAME + '/admin/project-profile/details').then(function () {
  164. return waitForElement(by.className('delete-project'));
  165. }).then(function () {
  166. return browser.findElement(by.className('delete-project')).click();
  167. }).then(function () {
  168. return waitForElement(by.xpath('//a[@title="Yes, I\'m really sure"]'));
  169. }).then(function () {
  170. return browser.findElement(by.xpath('//a[@title="Yes, I\'m really sure"]')).click();
  171. }).then(function () {
  172. // give some time to redirect
  173. setTimeout(done, 5000);
  174. });
  175. }
  176. xit('build app', function () {
  177. execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  178. });
  179. it('install app with SSO', function () {
  180. execSync('cloudron install --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  181. });
  182. it('can get app information', getAppInfo);
  183. it('can admin login', adminLogin);
  184. it('can login', login);
  185. it('can dismiss tutorial', dismissTutorial);
  186. it('can create project', createProject);
  187. it('can create user story', createUserStory);
  188. it('user story exists', userStoryExists);
  189. it('can restart app', function (done) {
  190. execSync('cloudron restart --wait --app ' + app.id);
  191. done();
  192. });
  193. it('user story is still present', userStoryExists);
  194. it('backup app', function () {
  195. execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  196. });
  197. it('restore app', function () {
  198. execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  199. });
  200. it('user story is still present', userStoryExists);
  201. it('move to different location', function (done) {
  202. // ensure we don't hit NXDOMAIN in the mean time
  203. browser.get('about:blank').then(function () {
  204. execSync('cloudron configure --wait --location ' + LOCATION + '2 --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  205. done();
  206. });
  207. });
  208. it('can get app information', getAppInfo);
  209. it('can admin login', adminLogin);
  210. // origin change requires new login
  211. it('can login', login);
  212. it('user story is still present', userStoryExists);
  213. it('can delete project', deleteProject);
  214. it('uninstall app', function (done) {
  215. // ensure we don't hit NXDOMAIN in the mean time
  216. browser.get('about:blank').then(function () {
  217. execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  218. done();
  219. });
  220. });
  221. it('install app without SSO', function () {
  222. execSync('cloudron install --no-sso --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  223. });
  224. it('can get app information', getAppInfo);
  225. it('can admin login', adminLogin);
  226. it('can sign up', signUp);
  227. it('can dismiss tutorial', dismissTutorial);
  228. it('can create project', createProject);
  229. it('can create user story', createUserStory);
  230. it('user story exists', userStoryExists);
  231. it('can restart app', function (done) {
  232. execSync('cloudron restart --wait --app ' + app.id);
  233. done();
  234. });
  235. it('user story is still present', userStoryExists);
  236. it('uninstall app', function (done) {
  237. // ensure we don't hit NXDOMAIN in the mean time
  238. browser.get('about:blank').then(function () {
  239. execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  240. done();
  241. });
  242. });
  243. // test update
  244. it('can install app', function () {
  245. execSync('cloudron install --new --wait --appstore-id io.taiga.cloudronapp --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  246. });
  247. it('can get app information', getAppInfo);
  248. it('can admin login', adminLogin);
  249. it('can login', login);
  250. it('can dismiss tutorial', dismissTutorial);
  251. it('can create project', createProject);
  252. it('can create user story', createUserStory);
  253. it('user story exists', userStoryExists);
  254. it('can update', function () {
  255. execSync('cloudron install --wait --app ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  256. });
  257. it('can admin login', adminLogin);
  258. it('user story exists', userStoryExists);
  259. it('uninstall app', function (done) {
  260. // ensure we don't hit NXDOMAIN in the mean time
  261. browser.get('about:blank').then(function () {
  262. execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  263. done();
  264. });
  265. });
  266. });