test.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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 waitForElement(by.xpath('//a[@title="Sign up"]'));
  60. }).then(function () {
  61. return browser.findElement(by.xpath('//a[@title="Sign up"]')).click();
  62. }).then(function () {
  63. return waitForElement(by.name('username'));
  64. }).then(function () {
  65. return browser.findElement(by.name('username')).sendKeys(process.env.USERNAME);
  66. }).then(function () {
  67. return browser.findElement(by.name('full_name')).sendKeys(process.env.USERNAME + ' Name');
  68. }).then(function () {
  69. return browser.findElement(by.name('email')).sendKeys('test@cloudron.io');
  70. }).then(function () {
  71. return browser.findElement(by.name('password')).sendKeys(process.env.PASSWORD);
  72. }).then(function () {
  73. return browser.findElement(by.xpath('//button[@title="Sign up"]')).click();
  74. }).then(function () {
  75. return waitForElement(by.xpath('//p[contains(text(), "Welcome! Here you will find the projects you are involved on.")]'));
  76. }).then(function () {
  77. callback();
  78. });
  79. }
  80. function adminLogin(callback) {
  81. browser.get('https://' + app.fqdn + '/admin/login/').then(function () {
  82. return browser.findElement(by.name('username')).sendKeys('admin');
  83. }).then(function () {
  84. return browser.findElement(by.name('password')).sendKeys('123123');
  85. }).then(function () {
  86. return browser.findElement(by.id('login-form')).submit();
  87. }).then(function () {
  88. return waitForElement(by.xpath('//h1[text()="Site administration"]'));
  89. }).then(function () {
  90. return browser.findElement(by.xpath('//a[text()="Log out"]')).click();
  91. }).then(function () {
  92. return browser.sleep(2000);
  93. }).then(function () {
  94. callback();
  95. });
  96. }
  97. function userStoryExists(callback) {
  98. browser.get('https://' + app.fqdn + '/project/' + process.env.USERNAME + '-' + PROJECT_NAME + '/us/1').then(function () {
  99. return waitForElement(by.xpath('//span[text()="' + USER_STORY_SUBJECT + '"]'));
  100. }).then(function () {
  101. callback();
  102. });
  103. }
  104. function getAppInfo() {
  105. var inspect = JSON.parse(execSync('cloudron inspect'));
  106. app = inspect.apps.filter(function (a) { return a.location === LOCATION || a.location === LOCATION + '2'; })[0];
  107. expect(app).to.be.an('object');
  108. }
  109. function dismissTutorial(done) {
  110. browser.get('https://' + app.fqdn);
  111. waitForElement(by.className('introjs-skipbutton')).then(function () {
  112. return browser.findElement(by.className('introjs-skipbutton')).sendKeys(Keys.ENTER);
  113. }).then(function () {
  114. // give some time to ack
  115. setTimeout(done, 5000);
  116. });
  117. }
  118. function createProject(done) {
  119. browser.get('https://' + app.fqdn + '/project/new/scrum').then(function () {
  120. return waitForElement(by.name('project-name'));
  121. }).then(function () {
  122. return browser.findElement(by.name('project-name')).sendKeys(PROJECT_NAME);
  123. }).then(function () {
  124. return browser.sleep(1000); // it needs some time to change focus!!
  125. }).then(function () {
  126. return browser.findElement(by.xpath('//textarea[@placeholder="Project Description"]')).sendKeys(PROJECT_DESCRIPTION);
  127. }).then(function () {
  128. return browser.sleep(1000);
  129. }).then(function () {
  130. return browser.findElement(by.xpath('//button[text()="Create Project"]')).click();
  131. }).then(function () {
  132. return browser.wait(until.elementLocated(by.xpath('//span[text()[contains(., "' + PROJECT_NAME + '")]]')), TEST_TIMEOUT);
  133. }).then(function () {
  134. done();
  135. });
  136. }
  137. function createUserStory(done) {
  138. browser.get('https://' + app.fqdn + '/project/' + process.env.USERNAME + '-' + PROJECT_NAME + '/backlog').then(function () {
  139. return waitForElement(by.xpath('//a[@tg-check-permission="add_us"]'));
  140. }).then(function () {
  141. // clicks don't work with taiga
  142. return browser.findElement(by.xpath('//a[@tg-check-permission="add_us"]')).sendKeys(Keys.ENTER);
  143. }).then(function () {
  144. return waitForElement(by.name('subject'));
  145. }).then(function () {
  146. return browser.findElement(by.name('subject')).sendKeys(USER_STORY_SUBJECT);
  147. }).then(function () {
  148. return waitForElement(by.xpath('/html/body/div[2]/div/div/div[1]/form/div[2]/button'));
  149. }).then(function () {
  150. return browser.findElement(by.xpath('/html/body/div[2]/div/div/div[1]/form/div[2]/button')).sendKeys(Keys.ENTER);
  151. }).then(function () {
  152. return waitForElement(by.xpath('//span[text()[contains(., "' + USER_STORY_SUBJECT + '")]]'));
  153. }).then(function () {
  154. done();
  155. });
  156. }
  157. function deleteProject(done) {
  158. browser.get('https://' + app.fqdn + '/project/' + process.env.USERNAME + '-' + PROJECT_NAME + '/admin/project-profile/details').then(function () {
  159. return waitForElement(by.className('delete-project'));
  160. }).then(function () {
  161. return browser.findElement(by.className('delete-project')).click();
  162. }).then(function () {
  163. return waitForElement(by.xpath('//a[@title="Yes, I\'m really sure"]'));
  164. }).then(function () {
  165. return browser.findElement(by.xpath('//a[@title="Yes, I\'m really sure"]')).click();
  166. }).then(function () {
  167. // give some time to redirect
  168. setTimeout(done, 5000);
  169. });
  170. }
  171. xit('build app', function () {
  172. execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  173. });
  174. it('install app', function () {
  175. execSync('cloudron install --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  176. });
  177. it('can get app information', getAppInfo);
  178. it('can admin login', adminLogin);
  179. it('can login', login);
  180. it('can dismiss tutorial', dismissTutorial);
  181. it('can create project', createProject);
  182. it('can create user story', createUserStory);
  183. it('user story exists', userStoryExists);
  184. it('can restart app', function (done) {
  185. execSync('cloudron restart --wait --app ' + app.id);
  186. done();
  187. });
  188. it('user story is still present', userStoryExists);
  189. it('backup app', function () {
  190. execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  191. });
  192. it('restore app', function () {
  193. execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  194. });
  195. it('user story is still present', userStoryExists);
  196. it('move to different location', function (done) {
  197. // ensure we don't hit NXDOMAIN in the mean time
  198. browser.get('about:blank').then(function () {
  199. execSync('cloudron configure --wait --location ' + LOCATION + '2 --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  200. done();
  201. });
  202. });
  203. it('can get app information', getAppInfo);
  204. it('can admin login', adminLogin);
  205. // origin change requires new login
  206. it('can login', login);
  207. it('user story is still present', userStoryExists);
  208. it('can delete project', deleteProject);
  209. it('uninstall app', function (done) {
  210. // ensure we don't hit NXDOMAIN in the mean time
  211. browser.get('about:blank').then(function () {
  212. execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  213. done();
  214. });
  215. });
  216. // no sso
  217. it('install app', function () {
  218. execSync('cloudron install --no-sso --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  219. });
  220. it('can get app information', getAppInfo);
  221. it('can admin login', adminLogin);
  222. it('can sign up', signUp);
  223. it('can dismiss tutorial', dismissTutorial);
  224. it('can create project', createProject);
  225. it('can create user story', createUserStory);
  226. it('user story exists', userStoryExists);
  227. it('can restart app', function (done) {
  228. execSync('cloudron restart --wait --app ' + app.id);
  229. done();
  230. });
  231. it('user story is still present', userStoryExists);
  232. it('uninstall app', function (done) {
  233. // ensure we don't hit NXDOMAIN in the mean time
  234. browser.get('about:blank').then(function () {
  235. execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  236. done();
  237. });
  238. });
  239. // test update
  240. it('can install app', function () {
  241. execSync('cloudron install --new --wait --appstore-id ' + app.manifest.id + ' --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  242. });
  243. it('can get app information', getAppInfo);
  244. it('can admin login', adminLogin);
  245. it('can login', login);
  246. it('can dismiss tutorial', dismissTutorial);
  247. it('can create project', createProject);
  248. it('can create user story', createUserStory);
  249. it('user story exists', userStoryExists);
  250. it('can update', function () {
  251. execSync('cloudron install --wait --app ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  252. });
  253. it('can admin login', adminLogin);
  254. it('user story exists', userStoryExists);
  255. it('uninstall app', function (done) {
  256. // ensure we don't hit NXDOMAIN in the mean time
  257. browser.get('about:blank').then(function () {
  258. execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  259. done();
  260. });
  261. });
  262. });