Added authentication_zero
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
require "test_helper"
|
||||
|
||||
class Identity::EmailVerificationsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@user = sign_in_as(users(:lazaro_nixon))
|
||||
@user.update! verified: false
|
||||
end
|
||||
|
||||
test "should send a verification email" do
|
||||
assert_enqueued_email_with UserMailer, :email_verification, params: { user: @user } do
|
||||
post identity_email_verification_url
|
||||
end
|
||||
|
||||
assert_redirected_to root_url
|
||||
end
|
||||
|
||||
test "should verify email" do
|
||||
sid = @user.generate_token_for(:email_verification)
|
||||
|
||||
get identity_email_verification_url(sid: sid, email: @user.email)
|
||||
assert_redirected_to root_url
|
||||
end
|
||||
|
||||
test "should not verify email with expired token" do
|
||||
sid = @user.generate_token_for(:email_verification)
|
||||
|
||||
travel 3.days
|
||||
|
||||
get identity_email_verification_url(sid: sid, email: @user.email)
|
||||
|
||||
assert_redirected_to edit_identity_email_url
|
||||
assert_equal "That email verification link is invalid", flash[:alert]
|
||||
end
|
||||
end
|
||||
25
test/controllers/identity/emails_controller_test.rb
Normal file
25
test/controllers/identity/emails_controller_test.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
require "test_helper"
|
||||
|
||||
class Identity::EmailsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@user = sign_in_as(users(:lazaro_nixon))
|
||||
end
|
||||
|
||||
test "should get edit" do
|
||||
get edit_identity_email_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should update email" do
|
||||
patch identity_email_url, params: { email: "new_email@hey.com", password_challenge: "Secret1*3*5*" }
|
||||
assert_redirected_to root_url
|
||||
end
|
||||
|
||||
|
||||
test "should not update email with wrong password challenge" do
|
||||
patch identity_email_url, params: { email: "new_email@hey.com", password_challenge: "SecretWrong1*3" }
|
||||
|
||||
assert_response :unprocessable_entity
|
||||
assert_select "li", /Password challenge is invalid/
|
||||
end
|
||||
end
|
||||
65
test/controllers/identity/password_resets_controller_test.rb
Normal file
65
test/controllers/identity/password_resets_controller_test.rb
Normal file
@@ -0,0 +1,65 @@
|
||||
require "test_helper"
|
||||
|
||||
class Identity::PasswordResetsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@user = users(:lazaro_nixon)
|
||||
end
|
||||
|
||||
test "should get new" do
|
||||
get new_identity_password_reset_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get edit" do
|
||||
sid = @user.generate_token_for(:password_reset)
|
||||
|
||||
get edit_identity_password_reset_url(sid: sid)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should send a password reset email" do
|
||||
assert_enqueued_email_with UserMailer, :password_reset, params: { user: @user } do
|
||||
post identity_password_reset_url, params: { email: @user.email }
|
||||
end
|
||||
|
||||
assert_redirected_to sign_in_url
|
||||
end
|
||||
|
||||
test "should not send a password reset email to a nonexistent email" do
|
||||
assert_no_enqueued_emails do
|
||||
post identity_password_reset_url, params: { email: "invalid_email@hey.com" }
|
||||
end
|
||||
|
||||
assert_redirected_to new_identity_password_reset_url
|
||||
assert_equal "You can't reset your password until you verify your email", flash[:alert]
|
||||
end
|
||||
|
||||
test "should not send a password reset email to a unverified email" do
|
||||
@user.update! verified: false
|
||||
|
||||
assert_no_enqueued_emails do
|
||||
post identity_password_reset_url, params: { email: @user.email }
|
||||
end
|
||||
|
||||
assert_redirected_to new_identity_password_reset_url
|
||||
assert_equal "You can't reset your password until you verify your email", flash[:alert]
|
||||
end
|
||||
|
||||
test "should update password" do
|
||||
sid = @user.generate_token_for(:password_reset)
|
||||
|
||||
patch identity_password_reset_url, params: { sid: sid, password: "Secret6*4*2*", password_confirmation: "Secret6*4*2*" }
|
||||
assert_redirected_to sign_in_url
|
||||
end
|
||||
|
||||
test "should not update password with expired token" do
|
||||
sid = @user.generate_token_for(:password_reset)
|
||||
|
||||
travel 30.minutes
|
||||
|
||||
patch identity_password_reset_url, params: { sid: sid, password: "Secret6*4*2*", password_confirmation: "Secret6*4*2*" }
|
||||
|
||||
assert_redirected_to new_identity_password_reset_url
|
||||
assert_equal "That password reset link is invalid", flash[:alert]
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user