signup_password_change_and_reset_test.rb 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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: '#content',
  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: '.content.active',
  39. value: 'Welcome!',
  40. )
  41. # change password
  42. click(css: '.navbar-items-personal .user a')
  43. sleep 1
  44. click(css: 'a[href="#profile"]')
  45. click(css: 'a[href="#profile/password"]')
  46. set(
  47. css: 'input[name="password_old"]',
  48. value: 'nonexisiting',
  49. )
  50. set(
  51. css: 'input[name="password_new"]',
  52. value: 'some',
  53. )
  54. set(
  55. css: 'input[name="password_new_confirm"]',
  56. value: 'some',
  57. )
  58. click(css: '.content .btn--primary')
  59. watch_for(
  60. css: 'body',
  61. value: 'current password is wrong',
  62. )
  63. set(
  64. css: 'input[name="password_old"]',
  65. value: 'SOme-pass1',
  66. )
  67. set(
  68. css: 'input[name="password_new_confirm"]',
  69. value: 'some2',
  70. )
  71. click(css: '.content .btn--primary')
  72. watch_for(
  73. css: 'body',
  74. value: 'passwords do not match',
  75. )
  76. set(
  77. css: 'input[name="password_new"]',
  78. value: 'SOme-1',
  79. )
  80. set(
  81. css: 'input[name="password_new_confirm"]',
  82. value: 'SOme-1',
  83. )
  84. click(css: '.content .btn--primary')
  85. watch_for(
  86. css: 'body',
  87. value: 'it must be at least',
  88. )
  89. set(
  90. css: 'input[name="password_new"]',
  91. value: 'SOme-pass-new',
  92. )
  93. set(
  94. css: 'input[name="password_new_confirm"]',
  95. value: 'SOme-pass-new',
  96. )
  97. click(css: '.content .btn--primary')
  98. watch_for(
  99. css: 'body',
  100. value: 'must contain at least 1 digit',
  101. )
  102. set(
  103. css: 'input[name="password_new"]',
  104. value: 'SOme-pass-new2',
  105. )
  106. set(
  107. css: 'input[name="password_new_confirm"]',
  108. value: 'SOme-pass-new2',
  109. )
  110. click(css: '.content .btn--primary')
  111. watch_for(
  112. css: 'body',
  113. value: 'Password changed successfully',
  114. )
  115. logout()
  116. # check login with new pw
  117. login(
  118. username: signup_user_email,
  119. password: 'SOme-pass-new2',
  120. )
  121. logout()
  122. # reset password (not possible)
  123. location(url: "#{browser_url}/#password_reset_verify/not_existing_token")
  124. watch_for(
  125. css: 'body',
  126. value: 'Token is invalid',
  127. )
  128. # reset password (with valid session - should not be possible)
  129. login(
  130. username: signup_user_email,
  131. password: 'SOme-pass-new2',
  132. url: browser_url,
  133. )
  134. location(url: "#{browser_url}/#password_reset")
  135. sleep 1
  136. match_not(
  137. css: 'body',
  138. value: 'password',
  139. )
  140. logout()
  141. # reset password (correct way)
  142. click(css: 'a[href="#password_reset"]')
  143. set(
  144. css: 'input[name="username"]',
  145. value: 'nonexisiting',
  146. )
  147. click(css: '.content .btn--primary')
  148. watch_for(
  149. css: 'body',
  150. value: 'sent password reset instructions',
  151. )
  152. click(css: '.content .btn--primary')
  153. set(
  154. css: 'input[name="username"]',
  155. value: signup_user_email,
  156. )
  157. click(css: '.content .btn--primary')
  158. watch_for(
  159. css: 'body',
  160. value: 'sent password reset instructions',
  161. )
  162. # redirect to "#password_reset_verify/#{token}" url by app, because of "developer_mode"
  163. watch_for(
  164. css: 'body',
  165. value: 'Choose your new password',
  166. )
  167. # set new password
  168. set(
  169. css: 'input[name="password"]',
  170. value: 'some',
  171. )
  172. set(
  173. css: 'input[name="password_confirm"]',
  174. value: 'some2',
  175. )
  176. click(css: '.content .btn--primary')
  177. watch_for(
  178. css: 'body',
  179. value: 'passwords do not match',
  180. )
  181. set(
  182. css: 'input[name="password"]',
  183. value: 'SOme-1',
  184. )
  185. set(
  186. css: 'input[name="password_confirm"]',
  187. value: 'SOme-1',
  188. )
  189. click(css: '.content .btn--primary')
  190. watch_for(
  191. css: 'body',
  192. value: 'it must be at least',
  193. )
  194. set(
  195. css: 'input[name="password"]',
  196. value: 'SOme-pass-new',
  197. )
  198. set(
  199. css: 'input[name="password_confirm"]',
  200. value: 'SOme-pass-new',
  201. )
  202. click(css: '.content .btn--primary')
  203. watch_for(
  204. css: 'body',
  205. value: 'must contain at least 1 digit',
  206. )
  207. set(
  208. css: 'input[name="password"]',
  209. value: 'SOme-pass-new2',
  210. )
  211. set(
  212. css: 'input[name="password_confirm"]',
  213. value: 'SOme-pass-new2',
  214. )
  215. click(css: '.content .btn--primary')
  216. watch_for(
  217. css: 'body',
  218. value: 'Your password has been changed',
  219. )
  220. # check if user is logged in
  221. sleep 5
  222. match(
  223. css: '.user-menu .user a',
  224. value: signup_user_email,
  225. attribute: 'title',
  226. )
  227. end
  228. end