2018-03-17 18:26:18 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::Auth::BlockedUserTracker do
|
|
|
|
set(:user) { create(:user) }
|
|
|
|
|
|
|
|
describe '.log_if_user_blocked' do
|
|
|
|
it 'does not log if user failed to login due to undefined reason' do
|
|
|
|
expect_any_instance_of(SystemHooksService).not_to receive(:execute_hooks_for)
|
|
|
|
|
|
|
|
expect(described_class.log_if_user_blocked({})).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'gracefully handles malformed environment variables' do
|
|
|
|
env = { 'warden.options' => 'test' }
|
|
|
|
|
|
|
|
expect(described_class.log_if_user_blocked(env)).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'failed login due to blocked user' do
|
2018-10-15 14:42:47 +05:30
|
|
|
let(:base_env) { { 'warden.options' => { message: User::BLOCKED_MESSAGE } } }
|
|
|
|
let(:env) { base_env.merge(request_env) }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
subject { described_class.log_if_user_blocked(env) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
expect_any_instance_of(SystemHooksService).to receive(:execute_hooks_for).with(user, :failed_login)
|
|
|
|
end
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
context 'via GitLab login' do
|
|
|
|
let(:request_env) { { described_class::ACTIVE_RECORD_REQUEST_PARAMS => { 'user' => { 'login' => user.username } } } }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
it 'logs a blocked user' do
|
|
|
|
user.block!
|
|
|
|
|
|
|
|
expect(subject).to be_truthy
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
it 'logs a blocked user by e-mail' do
|
|
|
|
user.block!
|
|
|
|
env[described_class::ACTIVE_RECORD_REQUEST_PARAMS]['user']['login'] = user.email
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
expect(subject).to be_truthy
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
context 'via LDAP login' do
|
|
|
|
let(:request_env) { { described_class::ACTIVE_RECORD_REQUEST_PARAMS => { 'username' => user.username } } }
|
|
|
|
|
|
|
|
it 'logs a blocked user' do
|
|
|
|
user.block!
|
|
|
|
|
|
|
|
expect(subject).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'logs a LDAP blocked user' do
|
|
|
|
user.ldap_block!
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
expect(subject).to be_truthy
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|