signup_password_change_and_reset_test.rb 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. require 'browser_test_helper'
  2. class SignupPasswordChangeAndResetTest < TestCase
  3. def test_signup
  4. signup_user_email = "signup-test-#{rand(999_999)}@example.com"
  5. @browser = browser_instance
  6. location(url: browser_url)
  7. click(css: 'a[href="#signup"]')
  8. exists(css: '.signup')
  9. # signup
  10. set(
  11. css: 'input[name="firstname"]',
  12. value: 'Signup Firstname',
  13. )
  14. set(
  15. css: 'input[name="lastname"]',
  16. value: 'Signup Lastname',
  17. )
  18. set(
  19. css: 'input[name="email"]',
  20. value: signup_user_email,
  21. )
  22. set(
  23. css: 'input[name="password"]',
  24. value: 'SOme-pass1',
  25. )
  26. set(
  27. css: 'input[name="password_confirm"]',
  28. value: 'SOme-pass1',
  29. )
  30. click(css: 'button.js-submit')
  31. watch_for(
  32. css: '.signup',
  33. value: 'Registration successful!',
  34. )
  35. # auto login via token trick in dev mode
  36. click(css: '.signup .js-submitResend')
  37. watch_for(
  38. css: '#login',
  39. )
  40. login(
  41. username: signup_user_email,
  42. password: 'SOme-pass1',
  43. )
  44. watch_for(
  45. css: '.content.active',
  46. value: 'Welcome!',
  47. )
  48. # change password
  49. click(css: '.navbar-items-personal .user a')
  50. sleep 1
  51. click(css: 'a[href="#profile"]')
  52. click(css: 'a[href="#profile/password"]')
  53. set(
  54. css: 'input[name="password_old"]',
  55. value: 'nonexisiting',
  56. )
  57. set(
  58. css: 'input[name="password_new"]',
  59. value: 'some',
  60. )
  61. set(
  62. css: 'input[name="password_new_confirm"]',
  63. value: 'some',
  64. )
  65. click(css: '.content .btn--primary')
  66. watch_for(
  67. css: 'body',
  68. value: 'current password is wrong',
  69. )
  70. set(
  71. css: 'input[name="password_old"]',
  72. value: 'SOme-pass1',
  73. )
  74. set(
  75. css: 'input[name="password_new_confirm"]',
  76. value: 'some2',
  77. )
  78. click(css: '.content .btn--primary')
  79. watch_for(
  80. css: 'body',
  81. value: 'passwords do not match',
  82. )
  83. set(
  84. css: 'input[name="password_new"]',
  85. value: 'SOme-1',
  86. )
  87. set(
  88. css: 'input[name="password_new_confirm"]',
  89. value: 'SOme-1',
  90. )
  91. click(css: '.content .btn--primary')
  92. watch_for(
  93. css: 'body',
  94. value: 'it must be at least',
  95. )
  96. set(
  97. css: 'input[name="password_new"]',
  98. value: 'SOme-pass-new',
  99. )
  100. set(
  101. css: 'input[name="password_new_confirm"]',
  102. value: 'SOme-pass-new',
  103. )
  104. click(css: '.content .btn--primary')
  105. watch_for(
  106. css: 'body',
  107. value: 'must contain at least 1 digit',
  108. )
  109. set(
  110. css: 'input[name="password_new"]',
  111. value: 'SOme-pass-new2',
  112. )
  113. set(
  114. css: 'input[name="password_new_confirm"]',
  115. value: 'SOme-pass-new2',
  116. )
  117. click(css: '.content .btn--primary')
  118. watch_for(
  119. css: 'body',
  120. value: 'Password changed successfully',
  121. )
  122. logout()
  123. # check login with new pw
  124. login(
  125. username: signup_user_email,
  126. password: 'SOme-pass-new2',
  127. )
  128. logout()
  129. # reset password (not possible)
  130. location(url: "#{browser_url}/#password_reset_verify/not_existing_token")
  131. watch_for(
  132. css: 'body',
  133. value: 'Token is invalid',
  134. )
  135. # reset password (with valid session - should not be possible)
  136. login(
  137. username: signup_user_email,
  138. password: 'SOme-pass-new2',
  139. url: browser_url,
  140. )
  141. location(url: "#{browser_url}/#password_reset")
  142. sleep 1
  143. match_not(
  144. css: 'body',
  145. value: 'password',
  146. )
  147. logout()
  148. # reset password (correct way)
  149. click(css: 'a[href="#password_reset"]')
  150. set(
  151. css: 'input[name="username"]',
  152. value: 'nonexisiting',
  153. )
  154. click(css: '.reset_password .btn--primary')
  155. watch_for(
  156. css: 'body',
  157. value: 'sent password reset instructions',
  158. )
  159. click(css: '.reset_password .btn--primary')
  160. set(
  161. css: 'input[name="username"]',
  162. value: signup_user_email,
  163. )
  164. click(css: '.reset_password .btn--primary')
  165. watch_for(
  166. css: 'body',
  167. value: 'sent password reset instructions',
  168. )
  169. # redirect to "#password_reset_verify/#{token}" url by app, because of "developer_mode"
  170. watch_for(
  171. css: 'body',
  172. value: 'Choose your new password',
  173. )
  174. # set new password
  175. set(
  176. css: 'input[name="password"]',
  177. value: 'some',
  178. )
  179. set(
  180. css: 'input[name="password_confirm"]',
  181. value: 'some2',
  182. )
  183. click(css: '.js-passwordForm .js-submit')
  184. watch_for(
  185. css: 'body',
  186. value: 'passwords do not match',
  187. )
  188. set(
  189. css: 'input[name="password"]',
  190. value: 'SOme-1',
  191. )
  192. set(
  193. css: 'input[name="password_confirm"]',
  194. value: 'SOme-1',
  195. )
  196. click(css: '.js-passwordForm .js-submit')
  197. watch_for(
  198. css: 'body',
  199. value: 'it must be at least',
  200. )
  201. set(
  202. css: 'input[name="password"]',
  203. value: 'SOme-pass-new',
  204. )
  205. set(
  206. css: 'input[name="password_confirm"]',
  207. value: 'SOme-pass-new',
  208. )
  209. click(css: '.js-passwordForm .js-submit')
  210. watch_for(
  211. css: 'body',
  212. value: 'must contain at least 1 digit',
  213. )
  214. set(
  215. css: 'input[name="password"]',
  216. value: 'SOme-pass-new2',
  217. )
  218. set(
  219. css: 'input[name="password_confirm"]',
  220. value: 'SOme-pass-new2',
  221. )
  222. click(css: '.js-passwordForm .js-submit')
  223. watch_for(
  224. css: 'body',
  225. value: 'Your password has been changed',
  226. )
  227. # check if user is logged in
  228. sleep 5
  229. match(
  230. css: '.user-menu .user a',
  231. value: signup_user_email,
  232. attribute: 'title',
  233. )
  234. end
  235. end