docbrown/spec/system/user_logs_in_with_password_spec.rb
Michael Kohl 5406b0576e
Split Settings::Authentication from SiteConfig (#13095)
* Split Settings::Authentication from SiteConfig

* Move specs

* Sort fields

* Update settings usages

* Update recaptcha usages

* Add data update script

* Update spec

* Rename SiteConfigParams concern

* Fixes, new route, new controller

* Controller and service refactoring

* More controller and service updates

* Spec updates

* More spec fixes

* Move file

* Fix FeedbackMessagesController

* Update admin/configs_spec

* Fix remaining specs in admin/configs_spec

* Fix configs API

* Formatting

* Clean up old service object

* Various fixes

* Update DUS

* Add model argument to admin_config_label

* Fix key name

* Fix specs

* Add distinct request caches for settings classes

* Fix e2e tests

* Fix remaining system spec

* Make DUS idempotent

* Move routes block

* Cleanup

* Switch to ActiveSupport::CurrentAttributes

* Pinned rails-settings-cached

* Update e2e test

* Update lib/data_update_scripts/20210316091354_move_authentication_settings.rb

Co-authored-by: rhymes <rhymes@hey.com>

* Add guard to DUS

* Temporarily re-add two SiteConfig fields

* Fix config show view

Co-authored-by: rhymes <rhymes@hey.com>
2021-04-12 09:41:09 +02:00

61 lines
1.9 KiB
Ruby

require "rails_helper"
RSpec.describe "Authenticating with a password" do
def submit_login_form(email, password)
fill_in "Email", with: email
fill_in "Password", with: password
click_button "Continue"
end
let(:password) { "p4assw0rd" }
let!(:user) { create(:user, password: password, password_confirmation: password) }
before do
allow(Settings::Authentication).to receive(:providers).and_return(Authentication::Providers.available)
visit sign_up_path
end
context "when logging in with incorrect credentials" do
it "displays an error when the email address is wrong" do
submit_login_form("wrong@example.com", password)
expect(page).to have_text("Invalid Email or password.")
end
it "displays an error when the password is wrong" do
submit_login_form(user.email, "wr0ng")
expect(page).to have_text("Invalid Email or password.")
end
it "sends an email with the unlock link if the uset gets locked out" do
allow(User).to receive(:maximum_attempts).and_return(1)
expect do
submit_login_form(user.email, "wr0ng")
end.to change { Devise.mailer.deliveries.count }.by(1)
end
end
context "when the user's account is locked" do
it "allows the user to unlock their account via social logins" do
omniauth_mock_github_payload
auth_payload = OmniAuth.config.mock_auth[:github]
create(:user, :with_identity, identities: [:github])
auth_payload.info.email = user.email
user.lock_access!
visit sign_up_path
click_on("Continue with GitHub", match: :first)
expect(page).to have_current_path("/?signin=true")
expect(page).not_to have_text("Your account is locked.")
end
end
context "when logging in with the correct credentials" do
it "allows the user to sign in with the correct password" do
submit_login_form(user.email, password)
expect(page).to have_current_path("/?signin=true")
end
end
end