diff options
Diffstat (limited to 'spec/helpers/recaptcha_helper_spec.rb')
-rw-r--r-- | spec/helpers/recaptcha_helper_spec.rb | 69 |
1 files changed, 59 insertions, 10 deletions
diff --git a/spec/helpers/recaptcha_helper_spec.rb b/spec/helpers/recaptcha_helper_spec.rb index 8ad91a0a217..2c327431437 100644 --- a/spec/helpers/recaptcha_helper_spec.rb +++ b/spec/helpers/recaptcha_helper_spec.rb @@ -9,21 +9,70 @@ RSpec.describe RecaptchaHelper, type: :helper do allow(helper).to receive(:session) { session } end - describe '.show_recaptcha_sign_up?' do - context 'when reCAPTCHA is disabled' do - it 'returns false' do - stub_application_setting(recaptcha_enabled: false) + shared_examples 'Gitlab QA bypass' do + context 'when GITLAB_QA_USER_AGENT env var is present' do + using RSpec::Parameterized::TableSyntax - expect(helper.show_recaptcha_sign_up?).to be_falsey + where(:dot_com, :user_agent, :qa_user_agent, :result) do + false | 'qa_user_agent' | 'qa_user_agent' | true + true | nil | 'qa_user_agent' | true + true | '' | 'qa_user_agent' | true + true | 'qa_user_agent' | '' | true + true | 'qa_user_agent' | nil | true + true | 'qa_user_agent' | 'qa_user_agent' | false end - end - context 'when reCAPTCHA is enabled' do - it 'returns true' do - stub_application_setting(recaptcha_enabled: true) + with_them do + before do + allow(Gitlab).to receive(:com?).and_return(dot_com) + stub_env('GITLAB_QA_USER_AGENT', qa_user_agent) + + request_double = instance_double(ActionController::TestRequest, user_agent: user_agent) + allow(helper).to receive(:request).and_return(request_double) + end - expect(helper.show_recaptcha_sign_up?).to be_truthy + it { is_expected.to eq result } end end end + + describe '.show_recaptcha_sign_up?' do + let(:setting_state) { true } + + before do + stub_application_setting(recaptcha_enabled: setting_state) + end + + subject { helper.show_recaptcha_sign_up? } + + it { is_expected.to eq true } + + context 'when setting is disabled' do + let(:setting_state) { false } + + it { is_expected.to eq false } + end + + include_examples 'Gitlab QA bypass' + end + + describe '.recaptcha_enabled_on_login?' do + let(:setting_state) { true } + + before do + stub_application_setting(login_recaptcha_protection_enabled: setting_state) + end + + subject { helper.recaptcha_enabled_on_login? } + + it { is_expected.to eq true } + + context 'when setting is disabled' do + let(:setting_state) { false } + + it { is_expected.to eq false } + end + + include_examples 'Gitlab QA bypass' + end end |