quo_vadis 1.4.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +11 -7
- data/CHANGELOG.md +31 -0
- data/Gemfile +11 -1
- data/LICENSE.txt +21 -0
- data/README.md +455 -127
- data/Rakefile +15 -9
- data/app/controllers/quo_vadis/confirmations_controller.rb +102 -0
- data/app/controllers/quo_vadis/logs_controller.rb +20 -0
- data/app/controllers/quo_vadis/password_resets_controller.rb +68 -0
- data/app/controllers/quo_vadis/passwords_controller.rb +28 -0
- data/app/controllers/quo_vadis/recovery_codes_controller.rb +54 -0
- data/app/controllers/quo_vadis/sessions_controller.rb +50 -132
- data/app/controllers/quo_vadis/totps_controller.rb +72 -0
- data/app/controllers/quo_vadis/twofas_controller.rb +26 -0
- data/app/mailers/quo_vadis/mailer.rb +73 -0
- data/app/models/quo_vadis/account.rb +59 -0
- data/app/models/quo_vadis/account_confirmation_token.rb +17 -0
- data/app/models/quo_vadis/log.rb +57 -0
- data/app/models/quo_vadis/password.rb +52 -0
- data/app/models/quo_vadis/password_reset_token.rb +17 -0
- data/app/models/quo_vadis/recovery_code.rb +26 -0
- data/app/models/quo_vadis/session.rb +55 -0
- data/app/models/quo_vadis/token.rb +42 -0
- data/app/models/quo_vadis/totp.rb +56 -0
- data/bin/console +15 -0
- data/bin/rails +21 -0
- data/bin/setup +8 -0
- data/config/locales/quo_vadis.en.yml +79 -24
- data/config/routes.rb +46 -12
- data/db/migrate/202102150904_setup.rb +48 -0
- data/lib/generators/quo_vadis/install_generator.rb +4 -23
- data/lib/quo_vadis.rb +103 -97
- data/lib/quo_vadis/controller.rb +227 -0
- data/lib/quo_vadis/crypt.rb +43 -0
- data/lib/quo_vadis/current_request_details.rb +11 -0
- data/lib/quo_vadis/defaults.rb +18 -0
- data/lib/quo_vadis/encrypted_type.rb +17 -0
- data/lib/quo_vadis/engine.rb +9 -11
- data/lib/quo_vadis/hmacable.rb +26 -0
- data/lib/quo_vadis/ip_masking.rb +31 -0
- data/lib/quo_vadis/model.rb +79 -0
- data/lib/quo_vadis/version.rb +3 -1
- data/quo_vadis.gemspec +20 -25
- data/test/dummy/README.markdown +1 -0
- data/test/dummy/Rakefile +2 -6
- data/test/dummy/app/controllers/application_controller.rb +0 -1
- data/test/dummy/app/controllers/articles_controller.rb +8 -11
- data/test/dummy/app/controllers/sign_ups_controller.rb +42 -0
- data/test/dummy/app/controllers/users_controller.rb +13 -5
- data/test/dummy/app/models/application_record.rb +3 -0
- data/test/dummy/app/models/article.rb +2 -1
- data/test/dummy/app/models/person.rb +5 -2
- data/test/dummy/app/models/user.rb +4 -1
- data/test/dummy/app/views/articles/also_secret.html.erb +1 -0
- data/test/dummy/app/views/articles/index.html.erb +1 -1
- data/test/dummy/app/views/articles/secret.html.erb +1 -0
- data/test/dummy/app/views/articles/very_secret.html.erb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +41 -25
- data/test/dummy/app/views/quo_vadis/confirmations/edit.html.erb +10 -0
- data/test/dummy/app/views/quo_vadis/confirmations/edit_email.html.erb +14 -0
- data/test/dummy/app/views/quo_vadis/confirmations/index.html.erb +14 -0
- data/test/dummy/app/views/quo_vadis/confirmations/new.html.erb +16 -0
- data/test/dummy/app/views/quo_vadis/logs/index.html.erb +30 -0
- data/test/dummy/app/views/quo_vadis/mailer/account_confirmation.text.erb +4 -0
- data/test/dummy/app/views/quo_vadis/mailer/email_change_notification.text.erb +8 -0
- data/test/dummy/app/views/quo_vadis/mailer/identifier_change_notification.text.erb +8 -0
- data/test/dummy/app/views/quo_vadis/mailer/password_change_notification.text.erb +8 -0
- data/test/dummy/app/views/quo_vadis/mailer/password_reset_notification.text.erb +8 -0
- data/test/dummy/app/views/quo_vadis/mailer/recovery_codes_generation_notification.text.erb +8 -0
- data/test/dummy/app/views/quo_vadis/mailer/reset_password.text.erb +4 -0
- data/test/dummy/app/views/quo_vadis/mailer/totp_reuse_notification.text.erb +6 -0
- data/test/dummy/app/views/quo_vadis/mailer/totp_setup_notification.text.erb +8 -0
- data/test/dummy/app/views/quo_vadis/mailer/twofa_deactivated_notification.text.erb +8 -0
- data/test/dummy/app/views/quo_vadis/password_resets/edit.html.erb +17 -0
- data/test/dummy/app/views/quo_vadis/password_resets/index.html.erb +5 -0
- data/test/dummy/app/views/quo_vadis/password_resets/new.html.erb +12 -0
- data/test/dummy/app/views/quo_vadis/passwords/edit.html.erb +22 -0
- data/test/dummy/app/views/quo_vadis/recovery_codes/challenge.html.erb +11 -0
- data/test/dummy/app/views/quo_vadis/recovery_codes/index.html.erb +25 -0
- data/test/dummy/app/views/quo_vadis/sessions/index.html.erb +26 -0
- data/test/dummy/app/views/quo_vadis/sessions/new.html.erb +24 -0
- data/test/dummy/app/views/quo_vadis/totps/challenge.html.erb +11 -0
- data/test/dummy/app/views/quo_vadis/totps/new.html.erb +17 -0
- data/test/dummy/app/views/quo_vadis/twofas/show.html.erb +20 -0
- data/test/dummy/app/views/sign_ups/new.html.erb +37 -0
- data/test/dummy/app/views/sign_ups/show.html.erb +5 -0
- data/test/dummy/app/views/users/new.html.erb +32 -9
- data/test/dummy/config.ru +6 -3
- data/test/dummy/config/application.rb +18 -9
- data/test/dummy/config/boot.rb +3 -9
- data/test/dummy/config/database.yml +2 -14
- data/test/dummy/config/environment.rb +2 -3
- data/test/dummy/config/initializers/quo_vadis.rb +2 -76
- data/test/dummy/config/routes.rb +11 -3
- data/test/dummy/db/migrate/202102121932_create_users.rb +10 -0
- data/test/dummy/db/migrate/202102121935_create_people.rb +10 -0
- data/test/dummy/db/schema.rb +80 -21
- data/test/fixtures/quo_vadis/mailer/account_confirmation.text +4 -0
- data/test/fixtures/quo_vadis/mailer/email_change_notification.text +8 -0
- data/test/fixtures/quo_vadis/mailer/identifier_change_notification.text +8 -0
- data/test/fixtures/quo_vadis/mailer/password_change_notification.text +8 -0
- data/test/fixtures/quo_vadis/mailer/password_reset_notification.text +8 -0
- data/test/fixtures/quo_vadis/mailer/recovery_codes_generation_notification.text +8 -0
- data/test/fixtures/quo_vadis/mailer/reset_password.text +4 -0
- data/test/fixtures/quo_vadis/mailer/totp_reuse_notification.text +6 -0
- data/test/fixtures/quo_vadis/mailer/totp_setup_notification.text +8 -0
- data/test/fixtures/quo_vadis/mailer/twofa_deactivated_notification.text +8 -0
- data/test/integration/account_confirmation_test.rb +145 -0
- data/test/integration/controller_test.rb +280 -0
- data/test/integration/logging_test.rb +235 -0
- data/test/integration/password_change_test.rb +99 -0
- data/test/integration/password_login_test.rb +137 -0
- data/test/integration/password_reset_test.rb +136 -0
- data/test/integration/recovery_codes_test.rb +48 -0
- data/test/integration/sessions_test.rb +86 -0
- data/test/integration/sign_up_test.rb +26 -12
- data/test/integration/totps_test.rb +96 -0
- data/test/integration/twofa_test.rb +82 -0
- data/test/mailers/mailer_test.rb +200 -0
- data/test/models/account_test.rb +34 -0
- data/test/models/crypt_test.rb +22 -0
- data/test/models/log_test.rb +16 -0
- data/test/models/mask_ip_test.rb +27 -0
- data/test/models/model_test.rb +66 -0
- data/test/models/password_test.rb +166 -0
- data/test/models/recovery_code_test.rb +54 -0
- data/test/models/session_test.rb +67 -0
- data/test/models/token_test.rb +70 -0
- data/test/models/totp_test.rb +68 -0
- data/test/quo_vadis_test.rb +39 -3
- data/test/test_helper.rb +42 -70
- metadata +120 -204
- data/app/controllers/controller_mixin.rb +0 -109
- data/app/mailers/quo_vadis/notifier.rb +0 -30
- data/app/models/model_mixin.rb +0 -128
- data/lib/generators/quo_vadis/templates/migration.rb.erb +0 -18
- data/lib/generators/quo_vadis/templates/quo_vadis.rb.erb +0 -96
- data/test/dummy/.gitignore +0 -2
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/helpers/articles_helper.rb +0 -2
- data/test/dummy/app/views/articles/new.html.erb +0 -11
- data/test/dummy/app/views/layouts/sessions.html.erb +0 -3
- data/test/dummy/app/views/quo_vadis/notifier/change_password.text.erb +0 -9
- data/test/dummy/app/views/quo_vadis/notifier/invite.text.erb +0 -8
- data/test/dummy/app/views/sessions/edit.html.erb +0 -11
- data/test/dummy/app/views/sessions/forgotten.html.erb +0 -13
- data/test/dummy/app/views/sessions/invite.html.erb +0 -31
- data/test/dummy/app/views/sessions/new.html.erb +0 -15
- data/test/dummy/config/environments/development.rb +0 -26
- data/test/dummy/config/environments/production.rb +0 -49
- data/test/dummy/config/environments/test.rb +0 -37
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/inflections.rb +0 -10
- data/test/dummy/config/initializers/mime_types.rb +0 -5
- data/test/dummy/config/initializers/rack_patch.rb +0 -16
- data/test/dummy/config/initializers/secret_token.rb +0 -7
- data/test/dummy/config/initializers/session_store.rb +0 -8
- data/test/dummy/config/locales/en.yml +0 -5
- data/test/dummy/config/locales/quo_vadis.en.yml +0 -21
- data/test/dummy/db/migrate/20110124125037_create_users.rb +0 -13
- data/test/dummy/db/migrate/20110124131535_create_articles.rb +0 -14
- data/test/dummy/db/migrate/20110127094709_add_authentication_to_users.rb +0 -18
- data/test/dummy/db/migrate/20111004112209_create_people.rb +0 -13
- data/test/dummy/db/migrate/20111004132342_add_authentication_to_people.rb +0 -18
- data/test/dummy/public/404.html +0 -26
- data/test/dummy/public/422.html +0 -26
- data/test/dummy/public/500.html +0 -26
- data/test/dummy/public/javascripts/application.js +0 -2
- data/test/dummy/public/javascripts/controls.js +0 -965
- data/test/dummy/public/javascripts/dragdrop.js +0 -974
- data/test/dummy/public/javascripts/effects.js +0 -1123
- data/test/dummy/public/javascripts/prototype.js +0 -6001
- data/test/dummy/public/javascripts/rails.js +0 -175
- data/test/dummy/public/stylesheets/.gitkeep +0 -0
- data/test/dummy/script/rails +0 -6
- data/test/integration/activation_test.rb +0 -108
- data/test/integration/authenticate_test.rb +0 -39
- data/test/integration/blocked_test.rb +0 -23
- data/test/integration/config_test.rb +0 -118
- data/test/integration/cookie_test.rb +0 -67
- data/test/integration/csrf_test.rb +0 -41
- data/test/integration/forgotten_test.rb +0 -93
- data/test/integration/helper_test.rb +0 -18
- data/test/integration/locale_test.rb +0 -197
- data/test/integration/navigation_test.rb +0 -7
- data/test/integration/sign_in_person_test.rb +0 -26
- data/test/integration/sign_in_test.rb +0 -24
- data/test/integration/sign_out_test.rb +0 -20
- data/test/support/integration_case.rb +0 -11
- data/test/unit/user_test.rb +0 -75
@@ -1,77 +1,3 @@
|
|
1
|
-
QuoVadis.configure do
|
2
|
-
|
3
|
-
#
|
4
|
-
# Sign in
|
5
|
-
#
|
6
|
-
|
7
|
-
# The URL to redirect the user to after s/he signs in.
|
8
|
-
# Use a proc if the URL depends on the user. E.g.:
|
9
|
-
#
|
10
|
-
# config.signed_in_url = Proc.new do |user|
|
11
|
-
# user.admin? ? :admin : :root
|
12
|
-
# end
|
13
|
-
#
|
14
|
-
# See also `:override_original_url`.
|
15
|
-
config.signed_in_url = :root
|
16
|
-
|
17
|
-
# Whether the `:signed_in_url` should override the URL the user was trying
|
18
|
-
# to reach when they were made to authenticate.
|
19
|
-
config.override_original_url = false
|
20
|
-
|
21
|
-
# Code to run when the user has signed in. E.g.:
|
22
|
-
#
|
23
|
-
# config.signed_in_hook = Proc.new do |user, controller|
|
24
|
-
# user.increment! :sign_in_count # assuming this attribute exists
|
25
|
-
# end
|
26
|
-
config.signed_in_hook = nil
|
27
|
-
|
28
|
-
# Code to run when someone has tried but failed to sign in. E.g.:
|
29
|
-
#
|
30
|
-
# config.failed_sign_in_hook = Proc.new do |controller|
|
31
|
-
# Rails.logger.info "Failed sign in from #{controller.request.remote_ip}"
|
32
|
-
# end
|
33
|
-
config.failed_sign_in_hook = nil
|
34
|
-
|
35
|
-
# How long to remember user across browser sessions.
|
36
|
-
# Set to <tt>nil</tt> to never remember user.
|
37
|
-
config.remember_for = 2.weeks
|
38
|
-
|
39
|
-
# Code to run to determine whether the sign-in process is blocked to the user. E.g.:
|
40
|
-
#
|
41
|
-
# config.blocked = Proc.new do |controller|
|
42
|
-
# # Assuming a SignIn model with scopes for `failed`, `last_day`, `for_ip`.
|
43
|
-
# SignIn.failed.last_day.for_ip(controller.request.remote_ip) >= 5
|
44
|
-
# end
|
45
|
-
config.blocked = false
|
46
|
-
|
47
|
-
|
48
|
-
#
|
49
|
-
# Sign out
|
50
|
-
#
|
51
|
-
|
52
|
-
# The URL to redirect the user to after s/he signs out.
|
53
|
-
config.signed_out_url = :root
|
54
|
-
|
55
|
-
# Code to run just before the user has signed out. E.g.:
|
56
|
-
#
|
57
|
-
# config.signed_out_hook = Proc.new do |user, controller|
|
58
|
-
# controller.session.reset
|
59
|
-
# end
|
60
|
-
config.signed_out_hook = nil
|
61
|
-
|
62
|
-
|
63
|
-
#
|
64
|
-
# Forgotten-password Mailer
|
65
|
-
#
|
66
|
-
|
67
|
-
# From whom the forgotten-password email should be sent.
|
68
|
-
config.from = 'noreply@example.com'
|
69
|
-
|
70
|
-
#
|
71
|
-
# Miscellaneous
|
72
|
-
#
|
73
|
-
|
74
|
-
# Layout for the sign-in view. Pass a string or a symbol.
|
75
|
-
config.layout = 'application'
|
76
|
-
|
1
|
+
QuoVadis.configure do
|
2
|
+
session_lifetime 1.week
|
77
3
|
end
|
data/test/dummy/config/routes.rb
CHANGED
@@ -1,5 +1,13 @@
|
|
1
|
-
|
2
|
-
resources :articles
|
1
|
+
Rails.application.routes.draw do
|
3
2
|
resources :users
|
4
|
-
|
3
|
+
resources :sign_ups
|
4
|
+
resources :articles do
|
5
|
+
collection do
|
6
|
+
get 'secret'
|
7
|
+
get 'also_secret'
|
8
|
+
get 'very_secret'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
get '/articles/secret', as: 'after_login'
|
12
|
+
root 'articles#index'
|
5
13
|
end
|
data/test/dummy/db/schema.rb
CHANGED
@@ -2,32 +2,91 @@
|
|
2
2
|
# of editing this file, please use the migrations feature of Active Record to
|
3
3
|
# incrementally modify your database, and then regenerate this schema definition.
|
4
4
|
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
# from scratch.
|
9
|
-
#
|
5
|
+
# This file is the source Rails uses to define your schema when running `bin/rails
|
6
|
+
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
|
7
|
+
# be faster and is potentially less error prone than running all of your
|
8
|
+
# migrations from scratch. Old migrations may fail to apply correctly if those
|
9
|
+
# migrations use external dependencies or application code.
|
10
10
|
#
|
11
|
-
# It's strongly recommended
|
11
|
+
# It's strongly recommended that you check this file into your version control system.
|
12
12
|
|
13
|
-
ActiveRecord::Schema.define(:
|
13
|
+
ActiveRecord::Schema.define(version: 202102150904) do
|
14
14
|
|
15
|
-
create_table "
|
16
|
-
t.string
|
17
|
-
t.
|
18
|
-
t.datetime "created_at"
|
19
|
-
t.datetime "updated_at"
|
15
|
+
create_table "people", force: :cascade do |t|
|
16
|
+
t.string "username", null: false
|
17
|
+
t.string "email", null: false
|
18
|
+
t.datetime "created_at", precision: 6, null: false
|
19
|
+
t.datetime "updated_at", precision: 6, null: false
|
20
20
|
end
|
21
21
|
|
22
|
-
create_table "
|
23
|
-
t.string
|
24
|
-
t.
|
25
|
-
t.
|
26
|
-
t.
|
27
|
-
t.
|
28
|
-
t.
|
29
|
-
t.
|
30
|
-
t.
|
22
|
+
create_table "qv_accounts", force: :cascade do |t|
|
23
|
+
t.string "model_type", null: false
|
24
|
+
t.bigint "model_id", null: false
|
25
|
+
t.string "identifier", null: false
|
26
|
+
t.datetime "confirmed_at"
|
27
|
+
t.datetime "created_at", precision: 6, null: false
|
28
|
+
t.datetime "updated_at", precision: 6, null: false
|
29
|
+
t.index ["identifier"], name: "index_qv_accounts_on_identifier", unique: true
|
30
|
+
t.index ["model_type", "model_id"], name: "index_qv_accounts_on_model_type_and_model_id", unique: true
|
31
31
|
end
|
32
32
|
|
33
|
+
create_table "qv_logs", force: :cascade do |t|
|
34
|
+
t.bigint "account_id"
|
35
|
+
t.string "action", null: false
|
36
|
+
t.string "ip", null: false
|
37
|
+
t.json "metadata", default: {}, null: false
|
38
|
+
t.datetime "created_at", precision: 6, null: false
|
39
|
+
t.datetime "updated_at", precision: 6, null: false
|
40
|
+
t.index ["account_id"], name: "index_qv_logs_on_account_id"
|
41
|
+
end
|
42
|
+
|
43
|
+
create_table "qv_passwords", force: :cascade do |t|
|
44
|
+
t.bigint "account_id", null: false
|
45
|
+
t.string "password_digest", null: false
|
46
|
+
t.datetime "created_at", precision: 6, null: false
|
47
|
+
t.datetime "updated_at", precision: 6, null: false
|
48
|
+
t.index ["account_id"], name: "index_qv_passwords_on_account_id"
|
49
|
+
end
|
50
|
+
|
51
|
+
create_table "qv_recovery_codes", force: :cascade do |t|
|
52
|
+
t.bigint "account_id", null: false
|
53
|
+
t.string "code_digest", null: false
|
54
|
+
t.datetime "created_at", precision: 6, null: false
|
55
|
+
t.datetime "updated_at", precision: 6, null: false
|
56
|
+
t.index ["account_id"], name: "index_qv_recovery_codes_on_account_id"
|
57
|
+
end
|
58
|
+
|
59
|
+
create_table "qv_sessions", force: :cascade do |t|
|
60
|
+
t.bigint "account_id", null: false
|
61
|
+
t.string "ip", null: false
|
62
|
+
t.string "user_agent", null: false
|
63
|
+
t.datetime "lifetime_expires_at"
|
64
|
+
t.datetime "last_seen_at"
|
65
|
+
t.datetime "second_factor_at"
|
66
|
+
t.datetime "created_at", precision: 6, null: false
|
67
|
+
t.datetime "updated_at", precision: 6, null: false
|
68
|
+
t.index ["account_id"], name: "index_qv_sessions_on_account_id"
|
69
|
+
end
|
70
|
+
|
71
|
+
create_table "qv_totps", force: :cascade do |t|
|
72
|
+
t.bigint "account_id", null: false
|
73
|
+
t.string "key", null: false
|
74
|
+
t.integer "last_used_at", null: false
|
75
|
+
t.datetime "created_at", precision: 6, null: false
|
76
|
+
t.datetime "updated_at", precision: 6, null: false
|
77
|
+
t.index ["account_id"], name: "index_qv_totps_on_account_id"
|
78
|
+
end
|
79
|
+
|
80
|
+
create_table "users", force: :cascade do |t|
|
81
|
+
t.string "name", null: false
|
82
|
+
t.string "email", null: false
|
83
|
+
t.datetime "created_at", precision: 6, null: false
|
84
|
+
t.datetime "updated_at", precision: 6, null: false
|
85
|
+
end
|
86
|
+
|
87
|
+
add_foreign_key "qv_logs", "qv_accounts", column: "account_id"
|
88
|
+
add_foreign_key "qv_passwords", "qv_accounts", column: "account_id"
|
89
|
+
add_foreign_key "qv_recovery_codes", "qv_accounts", column: "account_id"
|
90
|
+
add_foreign_key "qv_sessions", "qv_accounts", column: "account_id"
|
91
|
+
add_foreign_key "qv_totps", "qv_accounts", column: "account_id"
|
33
92
|
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class AccountConfirmationTest < IntegrationTest
|
4
|
+
|
5
|
+
setup do
|
6
|
+
QuoVadis.accounts_require_confirmation true
|
7
|
+
end
|
8
|
+
|
9
|
+
teardown do
|
10
|
+
QuoVadis.accounts_require_confirmation false
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
test 'new signup requiring confirmation' do
|
15
|
+
assert_emails 1 do
|
16
|
+
post sign_ups_path(user: {name: 'Bob', email: 'bob@example.com', password: '123456789abc'})
|
17
|
+
end
|
18
|
+
refute QuoVadis::Account.last.confirmed?
|
19
|
+
|
20
|
+
# verify response
|
21
|
+
assert_response :redirect
|
22
|
+
follow_redirect!
|
23
|
+
assert_equal 'A link to confirm your account has been emailed to you.', flash[:notice]
|
24
|
+
|
25
|
+
# click link in email
|
26
|
+
url = extract_url_from_email
|
27
|
+
get url
|
28
|
+
assert_response :success
|
29
|
+
action_path = extract_path_from_email
|
30
|
+
assert_select "form[action='#{action_path}']"
|
31
|
+
|
32
|
+
# click button on confirmation page
|
33
|
+
put action_path
|
34
|
+
|
35
|
+
# verify logged in
|
36
|
+
assert_redirected_to '/articles/secret'
|
37
|
+
assert_equal 'Thanks for confirming your account. You are now logged in.', flash[:notice]
|
38
|
+
assert controller.logged_in?
|
39
|
+
assert QuoVadis::Account.last.confirmed?
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
test 'new signup updates email' do
|
44
|
+
assert_emails 1 do
|
45
|
+
post sign_ups_path(user: {name: 'Bob', email: 'bob@example.com', password: '123456789abc'})
|
46
|
+
end
|
47
|
+
|
48
|
+
get quo_vadis.edit_email_confirmations_path
|
49
|
+
assert_response :success
|
50
|
+
|
51
|
+
# First email: changed-email notifier sent to original address
|
52
|
+
# Second email: confirmation email sent to new address
|
53
|
+
assert_emails 2 do
|
54
|
+
put quo_vadis.update_email_confirmations_path(email: 'bobby@example.com')
|
55
|
+
end
|
56
|
+
assert_equal ['bobby@example.com'], ActionMailer::Base.deliveries.last.to
|
57
|
+
assert_redirected_to quo_vadis.confirmations_path
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
test 'resend confirmation email in same session' do
|
62
|
+
assert_emails 1 do
|
63
|
+
post sign_ups_path(user: {name: 'Bob', email: 'bob@example.com', password: '123456789abc'})
|
64
|
+
end
|
65
|
+
|
66
|
+
assert_emails 1 do
|
67
|
+
post quo_vadis.resend_confirmations_path
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
test 'resend confirmation email: valid identifier' do
|
73
|
+
User.create! name: 'bob', email: 'bob@example.com', password: '123456789abc'
|
74
|
+
|
75
|
+
get quo_vadis.new_confirmation_path
|
76
|
+
assert_response :success
|
77
|
+
|
78
|
+
assert_emails 1 do
|
79
|
+
post quo_vadis.confirmations_path(email: 'bob@example.com')
|
80
|
+
end
|
81
|
+
|
82
|
+
assert_redirected_to '/confirmations'
|
83
|
+
assert_equal 'A link to confirm your account has been emailed to you.', flash[:notice]
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
test 'resend confirmation email: unknown identifier' do
|
88
|
+
assert_no_emails do
|
89
|
+
post quo_vadis.confirmations_path(email: 'bob@example.com')
|
90
|
+
end
|
91
|
+
|
92
|
+
assert_redirected_to quo_vadis.new_confirmation_path
|
93
|
+
assert_equal 'Sorry, your account could not be found. Please try again.', flash[:alert]
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
test 'reusing a token' do
|
98
|
+
assert_emails 1 do
|
99
|
+
post sign_ups_path(user: {name: 'Bob', email: 'bob@example.com', password: '123456789abc'})
|
100
|
+
end
|
101
|
+
|
102
|
+
put extract_path_from_email
|
103
|
+
|
104
|
+
assert_redirected_to '/articles/secret'
|
105
|
+
assert_equal 'Thanks for confirming your account. You are now logged in.', flash[:notice]
|
106
|
+
|
107
|
+
put extract_path_from_email
|
108
|
+
assert_redirected_to quo_vadis.new_confirmation_path
|
109
|
+
assert_equal 'Either the link has expired or your account has already been confirmed.', flash[:alert]
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
test 'token expired' do
|
114
|
+
assert_emails 1 do
|
115
|
+
post sign_ups_path(user: {name: 'Bob', email: 'bob@example.com', password: '123456789abc'})
|
116
|
+
end
|
117
|
+
|
118
|
+
travel QuoVadis.account_confirmation_token_lifetime + 1.minute
|
119
|
+
get extract_url_from_email
|
120
|
+
|
121
|
+
assert_redirected_to quo_vadis.new_confirmation_path
|
122
|
+
assert_equal 'Either the link has expired or your account has already been confirmed.', flash[:alert]
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
test 'accounts requiring confirmation cannot log in' do
|
127
|
+
User.create! name: 'bob', email: 'bob@example.com', password: '123456789abc'
|
128
|
+
post quo_vadis.login_path(email: 'bob@example.com', password: '123456789abc')
|
129
|
+
assert_redirected_to quo_vadis.new_confirmation_path
|
130
|
+
assert_equal 'Please confirm your account first.', flash[:notice]
|
131
|
+
refute controller.logged_in?
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
private
|
136
|
+
|
137
|
+
def extract_url_from_email
|
138
|
+
ActionMailer::Base.deliveries.last.decoded[%r{^http://.*$}, 0]
|
139
|
+
end
|
140
|
+
|
141
|
+
def extract_path_from_email
|
142
|
+
extract_url_from_email.sub 'http://www.example.com', ''
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|