Do not test PAM authentication by default (#9027)

* Do not test PAM authentication by default

* Disable PAM tests if PAM is not enabled
This commit is contained in:
Eugen Rochko 2018-10-20 07:32:26 +02:00 committed by GitHub
parent 9486f0ca77
commit d5bfba3262
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 44 deletions

View file

@ -3,7 +3,3 @@ NODE_ENV=test
# Federation # Federation
LOCAL_DOMAIN=cb6e6126.ngrok.io LOCAL_DOMAIN=cb6e6126.ngrok.io
LOCAL_HTTPS=true LOCAL_HTTPS=true
# test pam authentication
PAM_ENABLED=true
PAM_DEFAULT_SERVICE=pam_test
PAM_CONTROLLED_SERVICE=pam_test_controlled

View file

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