debian-mirror-gitlab/spec/services/users/validate_push_otp_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

46 lines
1.3 KiB
Ruby
Raw Permalink Normal View History

2022-07-16 23:28:13 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe Users::ValidatePushOtpService, feature_category: :user_profile do
2022-07-16 23:28:13 +05:30
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