blob: 960b6bcd3bbbff1f6811c9fe8aca7d51495f0848 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Users::ValidatePushOtpService do
let_it_be(:user) { create(:user) }
subject(:validate) { described_class.new(user).execute }
context 'FortiAuthenticator' do
before do
stub_feature_flags(forti_authenticator: user)
allow(::Gitlab.config.forti_authenticator).to receive(:enabled).and_return(true)
end
it 'calls PushOtp strategy' do
expect_next_instance_of(::Gitlab::Auth::Otp::Strategies::FortiAuthenticator::PushOtp) do |strategy|
expect(strategy).to receive(:validate).once
end
validate
end
end
context 'unexpected error' do
before do
stub_feature_flags(forti_authenticator: user)
allow(::Gitlab.config.forti_authenticator).to receive(:enabled).and_return(true)
end
it 'returns error' do
error_message = "boom!"
expect_next_instance_of(::Gitlab::Auth::Otp::Strategies::FortiAuthenticator::PushOtp) do |strategy|
expect(strategy).to receive(:validate).once.and_raise(StandardError, error_message)
end
expect(Gitlab::ErrorTracking).to receive(:log_exception)
result = validate
expect(result[:status]).to eq(:error)
expect(result[:message]).to eq(error_message)
end
end
end
|