|
|
@ -55,55 +55,53 @@ RSpec.describe Auth::SessionsController, type: :controller do |
|
|
|
request.env['devise.mapping'] = Devise.mappings[:user] |
|
|
|
request.env['devise.mapping'] = Devise.mappings[:user] |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
if ENV['PAM_ENABLED'] == 'true' |
|
|
|
context 'using PAM authentication', if: ENV['PAM_ENABLED'] == 'true' do |
|
|
|
context 'using PAM authentication' do |
|
|
|
context 'using a valid password' do |
|
|
|
context 'using a valid password' do |
|
|
|
before do |
|
|
|
before do |
|
|
|
post :create, params: { user: { email: "pam_user1", password: '123456' } } |
|
|
|
post :create, params: { user: { email: "pam_user1", password: '123456' } } |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it 'redirects to home' do |
|
|
|
it 'redirects to home' do |
|
|
|
expect(response).to redirect_to(root_path) |
|
|
|
expect(response).to redirect_to(root_path) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it 'logs the user in' do |
|
|
|
it 'logs the user in' do |
|
|
|
expect(controller.current_user).to be_instance_of(User) |
|
|
|
expect(controller.current_user).to be_instance_of(User) |
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context 'using an invalid password' do |
|
|
|
context 'using an invalid password' do |
|
|
|
before do |
|
|
|
before do |
|
|
|
post :create, params: { user: { email: "pam_user1", password: 'WRONGPW' } } |
|
|
|
post :create, params: { user: { email: "pam_user1", password: 'WRONGPW' } } |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it 'shows a login error' do |
|
|
|
it 'shows a login error' do |
|
|
|
expect(flash[:alert]).to match I18n.t('devise.failure.invalid', authentication_keys: 'Email') |
|
|
|
expect(flash[:alert]).to match I18n.t('devise.failure.invalid', authentication_keys: 'Email') |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "doesn't log the user in" do |
|
|
|
it "doesn't log the user in" do |
|
|
|
expect(controller.current_user).to be_nil |
|
|
|
expect(controller.current_user).to be_nil |
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context 'using a valid email and existing user' do |
|
|
|
context 'using a valid email and existing user' do |
|
|
|
let(:user) do |
|
|
|
let(:user) do |
|
|
|
account = Fabricate.build(:account, username: 'pam_user1') |
|
|
|
account = Fabricate.build(:account, username: 'pam_user1') |
|
|
|
account.save!(validate: false) |
|
|
|
account.save!(validate: false) |
|
|
|
user = Fabricate(:user, email: 'pam@example.com', password: nil, account: account) |
|
|
|
user = Fabricate(:user, email: 'pam@example.com', password: nil, account: account) |
|
|
|
user |
|
|
|
user |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
before do |
|
|
|
post :create, params: { user: { email: user.email, password: '123456' } } |
|
|
|
post :create, params: { user: { email: user.email, password: '123456' } } |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it 'redirects to home' do |
|
|
|
it 'redirects to home' do |
|
|
|
expect(response).to redirect_to(root_path) |
|
|
|
expect(response).to redirect_to(root_path) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it 'logs the user in' do |
|
|
|
it 'logs the user in' do |
|
|
|
expect(controller.current_user).to eq user |
|
|
|
expect(controller.current_user).to eq user |
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|