test.js 12 KB

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