rodauth 1.22.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +190 -0
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +210 -80
  5. data/doc/account_expiration.rdoc +12 -26
  6. data/doc/active_sessions.rdoc +49 -0
  7. data/doc/audit_logging.rdoc +44 -0
  8. data/doc/base.rdoc +75 -128
  9. data/doc/change_login.rdoc +7 -14
  10. data/doc/change_password.rdoc +9 -13
  11. data/doc/change_password_notify.rdoc +2 -2
  12. data/doc/close_account.rdoc +9 -16
  13. data/doc/confirm_password.rdoc +12 -5
  14. data/doc/create_account.rdoc +11 -22
  15. data/doc/disallow_password_reuse.rdoc +6 -13
  16. data/doc/email_auth.rdoc +15 -14
  17. data/doc/email_base.rdoc +6 -15
  18. data/doc/guides/admin_activation.rdoc +46 -0
  19. data/doc/guides/already_authenticated.rdoc +10 -0
  20. data/doc/guides/alternative_login.rdoc +46 -0
  21. data/doc/guides/create_account_programmatically.rdoc +38 -0
  22. data/doc/guides/delay_password.rdoc +25 -0
  23. data/doc/guides/email_only.rdoc +16 -0
  24. data/doc/guides/i18n.rdoc +26 -0
  25. data/doc/{internals.rdoc → guides/internals.rdoc} +0 -0
  26. data/doc/guides/links.rdoc +12 -0
  27. data/doc/guides/login_return.rdoc +37 -0
  28. data/doc/guides/password_column.rdoc +25 -0
  29. data/doc/guides/password_confirmation.rdoc +37 -0
  30. data/doc/guides/password_requirements.rdoc +30 -0
  31. data/doc/guides/paths.rdoc +36 -0
  32. data/doc/guides/query_params.rdoc +9 -0
  33. data/doc/guides/redirects.rdoc +17 -0
  34. data/doc/guides/registration_field.rdoc +68 -0
  35. data/doc/guides/require_mfa.rdoc +30 -0
  36. data/doc/guides/reset_password_autologin.rdoc +21 -0
  37. data/doc/guides/status_column.rdoc +28 -0
  38. data/doc/guides/totp_or_recovery.rdoc +16 -0
  39. data/doc/http_basic_auth.rdoc +10 -1
  40. data/doc/jwt.rdoc +22 -22
  41. data/doc/jwt_cors.rdoc +2 -3
  42. data/doc/jwt_refresh.rdoc +23 -8
  43. data/doc/lockout.rdoc +17 -15
  44. data/doc/login.rdoc +17 -2
  45. data/doc/login_password_requirements_base.rdoc +18 -37
  46. data/doc/logout.rdoc +2 -2
  47. data/doc/otp.rdoc +25 -19
  48. data/doc/password_complexity.rdoc +10 -26
  49. data/doc/password_expiration.rdoc +11 -25
  50. data/doc/password_grace_period.rdoc +16 -2
  51. data/doc/recovery_codes.rdoc +18 -12
  52. data/doc/release_notes/1.23.0.txt +32 -0
  53. data/doc/release_notes/2.0.0.txt +361 -0
  54. data/doc/release_notes/2.1.0.txt +31 -0
  55. data/doc/release_notes/2.2.0.txt +39 -0
  56. data/doc/release_notes/2.3.0.txt +37 -0
  57. data/doc/remember.rdoc +40 -64
  58. data/doc/reset_password.rdoc +12 -9
  59. data/doc/session_expiration.rdoc +1 -0
  60. data/doc/single_session.rdoc +16 -25
  61. data/doc/sms_codes.rdoc +24 -14
  62. data/doc/two_factor_base.rdoc +60 -22
  63. data/doc/verify_account.rdoc +14 -12
  64. data/doc/verify_account_grace_period.rdoc +6 -2
  65. data/doc/verify_login_change.rdoc +9 -8
  66. data/doc/webauthn.rdoc +115 -0
  67. data/doc/webauthn_login.rdoc +15 -0
  68. data/doc/webauthn_verify_account.rdoc +9 -0
  69. data/javascript/webauthn_auth.js +45 -0
  70. data/javascript/webauthn_setup.js +35 -0
  71. data/lib/roda/plugins/rodauth.rb +1 -1
  72. data/lib/rodauth.rb +36 -28
  73. data/lib/rodauth/features/account_expiration.rb +5 -5
  74. data/lib/rodauth/features/active_sessions.rb +158 -0
  75. data/lib/rodauth/features/audit_logging.rb +98 -0
  76. data/lib/rodauth/features/base.rb +144 -43
  77. data/lib/rodauth/features/change_password_notify.rb +2 -2
  78. data/lib/rodauth/features/close_account.rb +8 -6
  79. data/lib/rodauth/features/confirm_password.rb +40 -2
  80. data/lib/rodauth/features/create_account.rb +8 -13
  81. data/lib/rodauth/features/disallow_common_passwords.rb +1 -1
  82. data/lib/rodauth/features/disallow_password_reuse.rb +1 -1
  83. data/lib/rodauth/features/email_auth.rb +31 -30
  84. data/lib/rodauth/features/email_base.rb +9 -4
  85. data/lib/rodauth/features/http_basic_auth.rb +55 -35
  86. data/lib/rodauth/features/jwt.rb +63 -16
  87. data/lib/rodauth/features/jwt_cors.rb +15 -15
  88. data/lib/rodauth/features/jwt_refresh.rb +42 -13
  89. data/lib/rodauth/features/lockout.rb +12 -14
  90. data/lib/rodauth/features/login.rb +64 -15
  91. data/lib/rodauth/features/login_password_requirements_base.rb +13 -8
  92. data/lib/rodauth/features/otp.rb +77 -80
  93. data/lib/rodauth/features/password_complexity.rb +8 -13
  94. data/lib/rodauth/features/password_expiration.rb +2 -2
  95. data/lib/rodauth/features/password_grace_period.rb +17 -10
  96. data/lib/rodauth/features/recovery_codes.rb +49 -53
  97. data/lib/rodauth/features/remember.rb +11 -27
  98. data/lib/rodauth/features/reset_password.rb +26 -26
  99. data/lib/rodauth/features/session_expiration.rb +7 -10
  100. data/lib/rodauth/features/single_session.rb +8 -6
  101. data/lib/rodauth/features/sms_codes.rb +62 -72
  102. data/lib/rodauth/features/two_factor_base.rb +134 -30
  103. data/lib/rodauth/features/verify_account.rb +29 -21
  104. data/lib/rodauth/features/verify_account_grace_period.rb +18 -9
  105. data/lib/rodauth/features/verify_login_change.rb +12 -11
  106. data/lib/rodauth/features/webauthn.rb +505 -0
  107. data/lib/rodauth/features/webauthn_login.rb +70 -0
  108. data/lib/rodauth/features/webauthn_verify_account.rb +46 -0
  109. data/lib/rodauth/migrations.rb +16 -5
  110. data/lib/rodauth/version.rb +2 -2
  111. data/templates/button.str +1 -3
  112. data/templates/change-login.str +1 -2
  113. data/templates/change-password.str +3 -5
  114. data/templates/close-account.str +2 -2
  115. data/templates/confirm-password.str +1 -1
  116. data/templates/create-account.str +1 -1
  117. data/templates/email-auth-request-form.str +2 -3
  118. data/templates/email-auth.str +1 -1
  119. data/templates/global-logout-field.str +6 -0
  120. data/templates/login-confirm-field.str +2 -4
  121. data/templates/login-display.str +3 -2
  122. data/templates/login-field.str +2 -4
  123. data/templates/login-form-footer.str +6 -0
  124. data/templates/login-form.str +7 -0
  125. data/templates/login.str +1 -9
  126. data/templates/logout.str +1 -1
  127. data/templates/multi-phase-login.str +3 -0
  128. data/templates/otp-auth-code-field.str +5 -3
  129. data/templates/otp-auth.str +1 -1
  130. data/templates/otp-disable.str +1 -1
  131. data/templates/otp-setup.str +3 -3
  132. data/templates/password-confirm-field.str +2 -4
  133. data/templates/password-field.str +2 -4
  134. data/templates/recovery-auth.str +3 -6
  135. data/templates/recovery-codes.str +1 -1
  136. data/templates/remember.str +15 -20
  137. data/templates/reset-password-request.str +3 -3
  138. data/templates/reset-password.str +1 -2
  139. data/templates/sms-auth.str +1 -1
  140. data/templates/sms-code-field.str +5 -3
  141. data/templates/sms-confirm.str +1 -2
  142. data/templates/sms-disable.str +1 -2
  143. data/templates/sms-request.str +1 -1
  144. data/templates/sms-setup.str +6 -4
  145. data/templates/two-factor-auth.str +5 -0
  146. data/templates/two-factor-disable.str +6 -0
  147. data/templates/two-factor-manage.str +16 -0
  148. data/templates/unlock-account-request.str +4 -4
  149. data/templates/unlock-account.str +1 -1
  150. data/templates/verify-account-resend.str +3 -3
  151. data/templates/verify-account.str +1 -2
  152. data/templates/verify-login-change.str +1 -1
  153. data/templates/webauthn-auth.str +11 -0
  154. data/templates/webauthn-remove.str +14 -0
  155. data/templates/webauthn-setup.str +12 -0
  156. metadata +94 -54
  157. data/Rakefile +0 -179
  158. data/doc/verify_change_login.rdoc +0 -11
  159. data/lib/rodauth/features/verify_change_login.rb +0 -20
  160. data/spec/account_expiration_spec.rb +0 -225
  161. data/spec/all.rb +0 -1
  162. data/spec/change_login_spec.rb +0 -156
  163. data/spec/change_password_notify_spec.rb +0 -33
  164. data/spec/change_password_spec.rb +0 -202
  165. data/spec/close_account_spec.rb +0 -162
  166. data/spec/confirm_password_spec.rb +0 -70
  167. data/spec/create_account_spec.rb +0 -127
  168. data/spec/disallow_common_passwords_spec.rb +0 -93
  169. data/spec/disallow_password_reuse_spec.rb +0 -179
  170. data/spec/email_auth_spec.rb +0 -285
  171. data/spec/http_basic_auth_spec.rb +0 -143
  172. data/spec/jwt_cors_spec.rb +0 -57
  173. data/spec/jwt_refresh_spec.rb +0 -256
  174. data/spec/jwt_spec.rb +0 -235
  175. data/spec/lockout_spec.rb +0 -250
  176. data/spec/login_spec.rb +0 -328
  177. data/spec/migrate/001_tables.rb +0 -184
  178. data/spec/migrate/002_account_password_hash_column.rb +0 -11
  179. data/spec/migrate_password/001_tables.rb +0 -73
  180. data/spec/migrate_travis/001_tables.rb +0 -141
  181. data/spec/password_complexity_spec.rb +0 -109
  182. data/spec/password_expiration_spec.rb +0 -244
  183. data/spec/password_grace_period_spec.rb +0 -93
  184. data/spec/remember_spec.rb +0 -451
  185. data/spec/reset_password_spec.rb +0 -229
  186. data/spec/rodauth_spec.rb +0 -343
  187. data/spec/session_expiration_spec.rb +0 -58
  188. data/spec/single_session_spec.rb +0 -127
  189. data/spec/spec_helper.rb +0 -327
  190. data/spec/two_factor_spec.rb +0 -1462
  191. data/spec/update_password_hash_spec.rb +0 -40
  192. data/spec/verify_account_grace_period_spec.rb +0 -171
  193. data/spec/verify_account_spec.rb +0 -240
  194. data/spec/verify_change_login_spec.rb +0 -46
  195. data/spec/verify_login_change_spec.rb +0 -232
  196. data/spec/views/layout-other.str +0 -11
  197. data/spec/views/layout.str +0 -11
  198. data/spec/views/login.str +0 -21
@@ -1,11 +0,0 @@
1
- Sequel.migration do
2
- up do
3
- # Only for testing of account_password_hash_column, not recommended for new
4
- # applications
5
- add_column :accounts, :ph, String
6
- end
7
-
8
- down do
9
- drop_column :accounts, :ph
10
- end
11
- end
@@ -1,73 +0,0 @@
1
- require 'rodauth/migrations'
2
-
3
- Sequel.migration do
4
- up do
5
- create_table(:account_password_hashes) do
6
- foreign_key :id, :accounts, :primary_key=>true, :type=>:Bignum
7
- String :password_hash, :null=>false
8
- end
9
- Rodauth.create_database_authentication_functions(self)
10
- case database_type
11
- when :postgres
12
- user = get(Sequel.lit('current_user')).sub(/_password\z/, '')
13
- run "REVOKE ALL ON account_password_hashes FROM public"
14
- run "REVOKE ALL ON FUNCTION rodauth_get_salt(int8) FROM public"
15
- run "REVOKE ALL ON FUNCTION rodauth_valid_password_hash(int8, text) FROM public"
16
- run "GRANT INSERT, UPDATE, DELETE ON account_password_hashes TO #{user}"
17
- run "GRANT SELECT(id) ON account_password_hashes TO #{user}"
18
- run "GRANT EXECUTE ON FUNCTION rodauth_get_salt(int8) TO #{user}"
19
- run "GRANT EXECUTE ON FUNCTION rodauth_valid_password_hash(int8, text) TO #{user}"
20
- when :mysql
21
- user = get(Sequel.lit('current_user')).sub(/_password@/, '@')
22
- db_name = get(Sequel.function(:database))
23
- run "GRANT EXECUTE ON #{db_name}.* TO #{user}"
24
- run "GRANT INSERT, UPDATE, DELETE ON account_password_hashes TO #{user}"
25
- run "GRANT SELECT (id) ON account_password_hashes TO #{user}"
26
- when :mssql
27
- user = get(Sequel.function(:DB_NAME))
28
- run "GRANT EXECUTE ON rodauth_get_salt TO #{user}"
29
- run "GRANT EXECUTE ON rodauth_valid_password_hash TO #{user}"
30
- run "GRANT INSERT, UPDATE, DELETE ON account_password_hashes TO #{user}"
31
- run "GRANT SELECT ON account_password_hashes(id) TO #{user}"
32
- end
33
-
34
- # Used by the disallow_password_reuse feature
35
- create_table(:account_previous_password_hashes) do
36
- primary_key :id, :type=>:Bignum
37
- foreign_key :account_id, :accounts, :type=>:Bignum
38
- String :password_hash, :null=>false
39
- end
40
- Rodauth.create_database_previous_password_check_functions(self)
41
-
42
- case database_type
43
- when :postgres
44
- user = get(Sequel.lit('current_user')).sub(/_password\z/, '')
45
- run "REVOKE ALL ON account_previous_password_hashes FROM public"
46
- run "REVOKE ALL ON FUNCTION rodauth_get_previous_salt(int8) FROM public"
47
- run "REVOKE ALL ON FUNCTION rodauth_previous_password_hash_match(int8, text) FROM public"
48
- run "GRANT INSERT, UPDATE, DELETE ON account_previous_password_hashes TO #{user}"
49
- run "GRANT SELECT(id, account_id) ON account_previous_password_hashes TO #{user}"
50
- run "GRANT USAGE ON account_previous_password_hashes_id_seq TO #{user}"
51
- run "GRANT EXECUTE ON FUNCTION rodauth_get_previous_salt(int8) TO #{user}"
52
- run "GRANT EXECUTE ON FUNCTION rodauth_previous_password_hash_match(int8, text) TO #{user}"
53
- when :mysql
54
- user = get(Sequel.lit('current_user')).sub(/_password@/, '@')
55
- db_name = get(Sequel.function(:database))
56
- run "GRANT EXECUTE ON #{db_name}.* TO #{user}"
57
- run "GRANT INSERT, UPDATE, DELETE ON account_previous_password_hashes TO #{user}"
58
- run "GRANT SELECT (id, account_id) ON account_previous_password_hashes TO #{user}"
59
- when :mssql
60
- user = get(Sequel.function(:DB_NAME))
61
- run "GRANT EXECUTE ON rodauth_get_previous_salt TO #{user}"
62
- run "GRANT EXECUTE ON rodauth_previous_password_hash_match TO #{user}"
63
- run "GRANT INSERT, UPDATE, DELETE ON account_previous_password_hashes TO #{user}"
64
- run "GRANT SELECT ON account_previous_password_hashes(id, account_id) TO #{user}"
65
- end
66
- end
67
-
68
- down do
69
- Rodauth.drop_database_previous_password_check_functions(self)
70
- Rodauth.drop_database_authentication_functions(self)
71
- drop_table(:account_previous_password_hashes, :account_password_hashes)
72
- end
73
- end
@@ -1,141 +0,0 @@
1
- require 'rodauth/migrations'
2
-
3
- Sequel.migration do
4
- up do
5
- extension :date_arithmetic
6
-
7
- create_table(:account_statuses) do
8
- Integer :id, :primary_key=>true
9
- String :name, :null=>false, :unique=>true
10
- end
11
- from(:account_statuses).import([:id, :name], [[1, 'Unverified'], [2, 'Verified'], [3, 'Closed']])
12
-
13
- db = self
14
- create_table(:accounts) do
15
- primary_key :id, :type=>:Bignum
16
- foreign_key :status_id, :account_statuses, :null=>false, :default=>1
17
- if db.database_type == :postgres
18
- citext :email, :null=>false
19
- constraint :valid_email, :email=>/^[^,;@ \r\n]+@[^,@; \r\n]+\.[^,@; \r\n]+$/
20
- index :email, :unique=>true, :where=>{:status_id=>[1, 2]}
21
- else
22
- String :email, :null=>false
23
- index :email, :unique=>true
24
- end
25
-
26
- String :ph
27
- end
28
-
29
- create_table(:account_password_hashes) do
30
- foreign_key :id, :accounts, :primary_key=>true, :type=>:Bignum
31
- String :password_hash, :null=>false
32
- end
33
- Rodauth.create_database_authentication_functions(self)
34
-
35
- deadline_opts = proc do |days|
36
- if database_type == :mysql
37
- {:null=>false}
38
- else
39
- {:null=>false, :default=>Sequel.date_add(Sequel::CURRENT_TIMESTAMP, :days=>days)}
40
- end
41
- end
42
-
43
- create_table(:account_password_reset_keys) do
44
- foreign_key :id, :accounts, :primary_key=>true, :type=>:Bignum
45
- String :key, :null=>false
46
- DateTime :deadline, deadline_opts[1]
47
- DateTime :email_last_sent, :null=>false, :default=>Sequel::CURRENT_TIMESTAMP
48
- end
49
-
50
- # Used by the refresh token feature
51
- create_table(:account_jwt_refresh_keys) do
52
- primary_key :id, :type=>:Bignum
53
- foreign_key :account_id, :accounts, :type=>:Bignum
54
- String :key, :null=>false
55
- DateTime :deadline, deadline_opts[1]
56
- end
57
-
58
- create_table(:account_verification_keys) do
59
- foreign_key :id, :accounts, :primary_key=>true, :type=>:Bignum
60
- String :key, :null=>false
61
- DateTime :requested_at, :null=>false, :default=>Sequel::CURRENT_TIMESTAMP
62
- DateTime :email_last_sent, :null=>false, :default=>Sequel::CURRENT_TIMESTAMP
63
- end
64
-
65
- create_table(:account_login_change_keys) do
66
- foreign_key :id, :accounts, :primary_key=>true, :type=>:Bignum
67
- String :key, :null=>false
68
- String :login, :null=>false
69
- DateTime :deadline, deadline_opts[1]
70
- end
71
-
72
- create_table(:account_remember_keys) do
73
- foreign_key :id, :accounts, :primary_key=>true, :type=>:Bignum
74
- String :key, :null=>false
75
- DateTime :deadline, deadline_opts[14]
76
- end
77
-
78
- create_table(:account_email_auth_keys) do
79
- foreign_key :id, :accounts, :primary_key=>true, :type=>:Bignum
80
- String :key, :null=>false
81
- DateTime :deadline, deadline_opts[1]
82
- DateTime :email_last_sent, :null=>false, :default=>Sequel::CURRENT_TIMESTAMP
83
- end
84
-
85
- create_table(:account_login_failures) do
86
- foreign_key :id, :accounts, :primary_key=>true, :type=>:Bignum
87
- Integer :number, :null=>false, :default=>1
88
- end
89
- create_table(:account_lockouts) do
90
- foreign_key :id, :accounts, :primary_key=>true, :type=>:Bignum
91
- String :key, :null=>false
92
- DateTime :deadline, deadline_opts[1]
93
- DateTime :email_last_sent
94
- end
95
-
96
- create_table(:account_password_change_times) do
97
- foreign_key :id, :accounts, :primary_key=>true, :type=>:Bignum
98
- DateTime :changed_at, :null=>false, :default=>Sequel::CURRENT_TIMESTAMP
99
- end
100
-
101
- create_table(:account_activity_times) do
102
- foreign_key :id, :accounts, :primary_key=>true, :type=>:Bignum
103
- DateTime :last_activity_at, :null=>false
104
- DateTime :last_login_at, :null=>false
105
- DateTime :expired_at
106
- end
107
-
108
- create_table(:account_session_keys) do
109
- foreign_key :id, :accounts, :primary_key=>true, :type=>:Bignum
110
- String :key, :null=>false
111
- end
112
-
113
- create_table(:account_otp_keys) do
114
- foreign_key :id, :accounts, :primary_key=>true, :type=>:Bignum
115
- String :key, :null=>false
116
- Integer :num_failures, :null=>false, :default=>0
117
- Time :last_use, :null=>false, :default=>Sequel::CURRENT_TIMESTAMP
118
- end
119
-
120
- create_table(:account_recovery_codes) do
121
- foreign_key :id, :accounts, :type=>:Bignum
122
- String :code
123
- primary_key [:id, :code]
124
- end
125
-
126
- create_table(:account_sms_codes) do
127
- foreign_key :id, :accounts, :primary_key=>true, :type=>:Bignum
128
- String :phone_number, :null=>false
129
- Integer :num_failures
130
- String :code
131
- DateTime :code_issued_at, :null=>false, :default=>Sequel::CURRENT_TIMESTAMP
132
- end
133
-
134
- create_table(:account_previous_password_hashes) do
135
- primary_key :id, :type=>:Bignum
136
- foreign_key :account_id, :accounts, :type=>:Bignum
137
- String :password_hash, :null=>false
138
- end
139
- Rodauth.create_database_previous_password_check_functions(self)
140
- end
141
- end
@@ -1,109 +0,0 @@
1
- require File.expand_path("spec_helper", File.dirname(__FILE__))
2
-
3
- describe 'Rodauth password complexity feature' do
4
- it "should do additional password complexity checks" do
5
- rodauth do
6
- enable :login, :change_password, :password_complexity
7
- change_password_requires_password? false
8
- password_dictionary_file 'spec/words'
9
- end
10
- roda do |r|
11
- r.rodauth
12
- r.root{view :content=>""}
13
- end
14
-
15
- login
16
- page.current_path.must_equal '/'
17
-
18
- visit '/change-password'
19
-
20
- bad_passwords = [
21
- ["minimum 6 characters", %w"a1OX"],
22
- ["does not include uppercase letters, lowercase letters, and numbers",
23
- %w'sdflksdfl sdflks!fl Sdflksdfl dfl1sdfl DFL1SDFL DFL!SDFL'],
24
- ["includes common character sequence",
25
- %w"Aqwerty12 Aazerty12 HA123ha HA234ha HA345ha HA456ha HA567ha HA678ha HA789ha HA890ha"],
26
- ["contains 3 or more of the same character in a row", %w"Helll0 Hellllll0"],
27
- ["is a word in a dictionary",
28
- %w"Password1 1Password1 1PaSSword1 1P@$5w0Rd1 2398|3@$+7809 2|!7+1e l4$7$124 N!88|e56"]
29
- ]
30
-
31
-
32
- bad_passwords.each do |message, passwords|
33
- passwords.each do |pass|
34
- fill_in 'New Password', :with=>pass
35
- fill_in 'Confirm Password', :with=>pass
36
- click_button 'Change Password'
37
- page.html.must_include("invalid password, does not meet requirements (#{message})")
38
- page.find('#error_flash').text.must_equal "There was an error changing your password"
39
- end
40
- end
41
-
42
- fill_in 'New Password', :with=>'footpassword'
43
- fill_in 'Confirm Password', :with=>'footpassword'
44
- click_button 'Change Password'
45
- page.find('#notice_flash').text.must_equal "Your password has been changed"
46
- end
47
-
48
- it "should support default dictionary" do
49
- default_dictionary = '/usr/share/dict/words'
50
- skip("#{default_dictionary} not present") unless File.file?(default_dictionary)
51
- pass = File.read(default_dictionary).split.sort_by{|w| w.length}.last
52
- skip("#{default_dictionary} empty") unless pass
53
- pass = pass.downcase.gsub(/[^a-z]/, '')
54
-
55
- rodauth do
56
- enable :login, :change_password, :password_complexity
57
- change_password_requires_password? false
58
- end
59
- roda do |r|
60
- r.rodauth
61
- r.root{view :content=>""}
62
- end
63
-
64
- login
65
- page.current_path.must_equal '/'
66
-
67
- visit '/change-password'
68
- fill_in 'New Password', :with=>"135#{pass}135"
69
- fill_in 'Confirm Password', :with=>"135#{pass}135"
70
- click_button 'Change Password'
71
- page.html.must_include("invalid password")
72
- page.find('#error_flash').text.must_equal "There was an error changing your password"
73
-
74
- fill_in 'New Password', :with=>'footpassword'
75
- fill_in 'Confirm Password', :with=>'footpassword'
76
- click_button 'Change Password'
77
- page.find('#notice_flash').text.must_equal "Your password has been changed"
78
- end
79
-
80
- it "should support no dictionary" do
81
- default_dictionary = '/usr/share/dict/words'
82
- skip("#{default_dictionary} not present") unless File.file?(default_dictionary)
83
-
84
- rodauth do
85
- enable :login, :change_password, :password_complexity
86
- change_password_requires_password? false
87
- password_dictionary_file false
88
- end
89
- roda do |r|
90
- r.rodauth
91
- r.root{view :content=>""}
92
- end
93
-
94
- login
95
- page.current_path.must_equal '/'
96
-
97
- visit '/change-password'
98
- fill_in 'New Password', :with=>"password123"
99
- fill_in 'Confirm Password', :with=>"password123"
100
- click_button 'Change Password'
101
- page.html.must_include("invalid password")
102
- page.find('#error_flash').text.must_equal "There was an error changing your password"
103
-
104
- fill_in 'New Password', :with=>'Password1'
105
- fill_in 'Confirm Password', :with=>'Password1'
106
- click_button 'Change Password'
107
- page.find('#notice_flash').text.must_equal "Your password has been changed"
108
- end
109
- end
@@ -1,244 +0,0 @@
1
- require File.expand_path("spec_helper", File.dirname(__FILE__))
2
-
3
- describe 'Rodauth password expiration feature' do
4
- it "should force password changes after x number of days" do
5
- rodauth do
6
- enable :login, :logout, :change_password, :reset_password, :password_expiration
7
- allow_password_change_after 1000
8
- change_password_requires_password? false
9
- end
10
- roda do |r|
11
- r.rodauth
12
- rodauth.require_current_password if rodauth.logged_in?
13
- r.root{view :content=>""}
14
- end
15
-
16
- login(:pass=>'01234567')
17
- click_button 'Request Password Reset'
18
- link = email_link(/(\/reset-password\?key=.+)$/)
19
-
20
- visit link
21
- page.current_path.must_equal '/reset-password'
22
-
23
- login
24
- page.current_path.must_equal '/'
25
-
26
- visit '/change-password'
27
- fill_in 'New Password', :with=>'banana'
28
- fill_in 'Confirm Password', :with=>'banana'
29
- click_button 'Change Password'
30
- page.current_path.must_equal '/'
31
-
32
- visit '/change-password'
33
- page.current_path.must_equal '/'
34
- page.find('#error_flash').text.must_equal "Your password cannot be changed yet"
35
-
36
- logout
37
-
38
- visit link
39
- page.current_path.must_equal '/'
40
- page.find('#error_flash').text.must_equal "Your password cannot be changed yet"
41
-
42
- DB[:account_password_change_times].update(:changed_at=>Time.now - 1100)
43
-
44
- visit link
45
- page.current_path.must_equal '/reset-password'
46
-
47
- login(:pass=>'banana')
48
- page.current_path.must_equal '/'
49
-
50
- visit '/change-password'
51
- page.current_path.must_equal '/change-password'
52
-
53
- logout
54
-
55
- DB[:account_password_change_times].update(:changed_at=>Time.now - 91*86400)
56
-
57
- login(:pass=>'banana')
58
- page.current_path.must_equal '/change-password'
59
- page.find('#error_flash').text.must_equal "Your password has expired and needs to be changed"
60
-
61
- visit '/foo'
62
- page.current_path.must_equal '/change-password'
63
- page.find('#error_flash').text.must_equal "Your password has expired and needs to be changed"
64
-
65
- fill_in 'New Password', :with=>'banana2'
66
- fill_in 'Confirm Password', :with=>'banana2'
67
- click_button 'Change Password'
68
- page.current_path.must_equal '/'
69
-
70
- visit '/change-password'
71
- page.current_path.must_equal '/'
72
- page.find('#error_flash').text.must_equal "Your password cannot be changed yet"
73
-
74
- logout
75
-
76
- visit link
77
- page.current_path.must_equal '/'
78
- page.find('#error_flash').text.must_equal "Your password cannot be changed yet"
79
- end
80
-
81
- it "should update password changed at when creating accounts" do
82
- rodauth do
83
- enable :login, :change_password, :password_expiration
84
- password_expiration_default true
85
- change_password_requires_password? false
86
- end
87
- roda do |r|
88
- r.rodauth
89
- rodauth.require_current_password
90
- r.root{view :content=>""}
91
- end
92
-
93
- login
94
- page.current_path.must_equal '/change-password'
95
-
96
- visit '/'
97
- page.current_path.must_equal '/change-password'
98
- fill_in 'New Password', :with=>'banana'
99
- fill_in 'Confirm Password', :with=>'banana'
100
- click_button 'Change Password'
101
- page.current_path.must_equal '/'
102
- end
103
-
104
- it "should update password changed at when creating accounts" do
105
- rodauth do
106
- enable :login, :create_account, :password_expiration
107
- allow_password_change_after 1000
108
- account_password_hash_column :ph
109
- end
110
- roda do |r|
111
- r.rodauth
112
- r.root{view :content=>""}
113
- end
114
-
115
- visit '/create-account'
116
- fill_in 'Login', :with=>'foo2@example.com'
117
- fill_in 'Confirm Login', :with=>'foo2@example.com'
118
- fill_in 'Password', :with=>'apple2'
119
- fill_in 'Confirm Password', :with=>'apple2'
120
- click_button 'Create Account'
121
-
122
- visit '/change-password'
123
- page.current_path.must_equal '/'
124
- page.find('#error_flash').text.must_equal "Your password cannot be changed yet"
125
- end
126
-
127
- it "should remove password expiration data when closing accounts" do
128
- rodauth do
129
- enable :create_account, :close_account, :password_expiration
130
- close_account_requires_password? false
131
- create_account_autologin? true
132
- end
133
- roda do |r|
134
- r.rodauth
135
- r.root{view :content=>""}
136
- end
137
-
138
- visit '/create-account'
139
- fill_in 'Login', :with=>'foo2@example.com'
140
- fill_in 'Confirm Login', :with=>'foo2@example.com'
141
- fill_in 'Password', :with=>'apple2'
142
- fill_in 'Confirm Password', :with=>'apple2'
143
- click_button 'Create Account'
144
-
145
- DB[:account_password_change_times].count.must_equal 1
146
- visit '/close-account'
147
- click_button 'Close Account'
148
- DB[:account_password_change_times].count.must_equal 0
149
- end
150
-
151
- it "should handle the case where the password is expired while the user has logged in" do
152
- rodauth do
153
- enable :login, :change_password, :password_expiration
154
- password_expiration_default true
155
- allow_password_change_after(-1000)
156
- change_password_requires_password? false
157
- require_password_change_after 3600
158
- end
159
- roda do |r|
160
- r.rodauth
161
- rodauth.require_current_password
162
- r.get("expire", :d){|d| session[:password_changed_at] = Time.now.to_i - d.to_i; r.redirect '/'}
163
- r.root{view :content=>""}
164
- end
165
-
166
- login
167
- page.current_path.must_equal '/change-password'
168
-
169
- visit '/'
170
- page.current_path.must_equal '/change-password'
171
- fill_in 'New Password', :with=>'banana'
172
- fill_in 'Confirm Password', :with=>'banana'
173
- click_button 'Change Password'
174
- page.current_path.must_equal '/'
175
-
176
- visit "/expire/90"
177
- page.current_path.must_equal '/'
178
-
179
- visit "/expire/7200"
180
- page.current_path.must_equal '/change-password'
181
- end
182
-
183
- it "should force password changes via jwt" do
184
- rodauth do
185
- enable :login, :logout, :change_password, :reset_password, :password_expiration
186
- allow_password_change_after 1000
187
- change_password_requires_password? false
188
- reset_password_email_body{reset_password_email_link}
189
- end
190
- roda(:jwt) do |r|
191
- r.rodauth
192
- rodauth.require_current_password
193
- if rodauth.authenticated?
194
- [1]
195
- else
196
- [2]
197
- end
198
- end
199
-
200
- json_request.must_equal [200, [2]]
201
-
202
- res = json_request('/reset-password-request', :login=>'foo@example.com')
203
- res.must_equal [200, {"success"=>"An email has been sent to you with a link to reset the password for your account"}]
204
- link = email_link(/key=.+$/)
205
-
206
- json_login
207
-
208
- res = json_request('/change-password', :password=>'0123456789', "new-password"=>'0123456', "password-confirm"=>'0123456')
209
- res.must_equal [200, {'success'=>"Your password has been changed"}]
210
-
211
- json_request.must_equal [200, [1]]
212
-
213
- res = json_request('/change-password', :password=>'0123456', "new-password"=>'01234567', "password-confirm"=>'01234567')
214
- res.must_equal [400, {'error'=>"Your password cannot be changed yet"}]
215
-
216
- json_logout
217
-
218
- res = json_request('/reset-password', :key=>link[4..-1], :password=>'01234567', "password-confirm"=>'01234567')
219
- res.must_equal [400, {'error'=>"Your password cannot be changed yet"}]
220
-
221
- DB[:account_password_change_times].update(:changed_at=>Time.now - 1100)
222
- res = json_request('/reset-password', :key=>link[4..-1], :password=>'01234567', "password-confirm"=>'01234567')
223
- res.must_equal [200, {"success"=>"Your password has been reset"}]
224
-
225
- DB[:account_password_change_times].update(:changed_at=>Time.now - 1100)
226
- json_login(:pass=>'01234567')
227
- res = json_request('/change-password', :password=>'01234567', "new-password"=>'012345678', "password-confirm"=>'012345678')
228
- res.must_equal [200, {'success'=>"Your password has been changed"}]
229
-
230
- DB[:account_password_change_times].update(:changed_at=>Time.now - 91*86400)
231
-
232
- json_logout
233
- json_request.must_equal [200, [2]]
234
-
235
- res = json_login(:pass=>'012345678', :no_check=>true)
236
- res.must_equal [400, {'error'=>"Your password has expired and needs to be changed"}]
237
- json_request.must_equal [400, {'error'=>"Your password has expired and needs to be changed"}]
238
-
239
- res = json_request('/change-password', :password=>'012345678', "new-password"=>'012345678a', "password-confirm"=>'012345678a')
240
- res.must_equal [200, {'success'=>"Your password has been changed"}]
241
-
242
- json_request.must_equal [200, [1]]
243
- end
244
- end