2021-01-27 04:09:01 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Captcha::CaptchaVerificationService do
|
|
|
|
describe '#execute' do
|
2021-06-21 08:07:45 -04:00
|
|
|
let(:captcha_response) { 'abc123' }
|
|
|
|
let(:fake_ip) { '1.2.3.4' }
|
|
|
|
let(:spam_params) do
|
|
|
|
::Spam::SpamParams.new(
|
|
|
|
captcha_response: captcha_response,
|
|
|
|
spam_log_id: double,
|
|
|
|
ip_address: fake_ip,
|
|
|
|
user_agent: double,
|
|
|
|
referer: double
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:service) { described_class.new(spam_params: spam_params) }
|
2021-01-27 04:09:01 -05:00
|
|
|
|
2021-06-21 08:07:45 -04:00
|
|
|
subject { service.execute }
|
2021-01-27 04:09:01 -05:00
|
|
|
|
|
|
|
context 'when there is no captcha_response' do
|
2021-06-21 08:07:45 -04:00
|
|
|
let(:captcha_response) { nil }
|
|
|
|
|
2021-01-27 04:09:01 -05:00
|
|
|
it 'returns false' do
|
|
|
|
expect(subject).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a captcha_response' do
|
|
|
|
before do
|
|
|
|
expect(Gitlab::Recaptcha).to receive(:load_configurations!)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(service).to receive(:verify_recaptcha).with(response: captcha_response) { true }
|
|
|
|
|
|
|
|
expect(subject).to eq(true)
|
|
|
|
end
|
|
|
|
|
2021-06-21 08:07:45 -04:00
|
|
|
it 'has a request method which returns an object with the ip address #remote_ip' do
|
2021-01-27 04:09:01 -05:00
|
|
|
subject
|
|
|
|
|
2021-06-21 08:07:45 -04:00
|
|
|
request_struct = service.send(:request)
|
|
|
|
expect(request_struct).to respond_to(:remote_ip)
|
|
|
|
expect(request_struct.remote_ip).to eq(fake_ip)
|
2021-01-27 04:09:01 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|