diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-05 00:07:50 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-05 00:07:50 +0000 |
commit | 54cbcea92909e69248abc9e6b92c7d14db3308a5 (patch) | |
tree | 1276f1c57b5ab1064db7197c2d28a8837d68d02d /spec/lib/gitlab/throttle_spec.rb | |
parent | 71221554dd9ddf30f73035c89f78164e001aa96d (diff) | |
download | gitlab-ce-54cbcea92909e69248abc9e6b92c7d14db3308a5.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/throttle_spec.rb')
-rw-r--r-- | spec/lib/gitlab/throttle_spec.rb | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/spec/lib/gitlab/throttle_spec.rb b/spec/lib/gitlab/throttle_spec.rb new file mode 100644 index 00000000000..674646a5f06 --- /dev/null +++ b/spec/lib/gitlab/throttle_spec.rb @@ -0,0 +1,87 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Throttle do + describe '.protected_paths_enabled?' do + subject { described_class.protected_paths_enabled? } + + context 'when omnibus protected paths throttle should be used' do + before do + expect(described_class).to receive(:should_use_omnibus_protected_paths?).and_return(true) + end + + it { is_expected.to be_falsey } + end + + context 'when omnibus protected paths throttle should not be used' do + before do + expect(described_class).to receive(:should_use_omnibus_protected_paths?).and_return(false) + end + + it 'returns Application Settings throttle_protected_paths_enabled?' do + expect(Gitlab::CurrentSettings.current_application_settings).to receive(:throttle_protected_paths_enabled?) + + subject + end + end + end + + describe '.should_use_omnibus_protected_paths?' do + subject { described_class.should_use_omnibus_protected_paths? } + + context 'when rack_attack.admin_area_protected_paths_enabled config is unspecified' do + context 'when the omnibus protected paths throttle has been recently used (it has data)' do + before do + expect(described_class).to receive(:omnibus_protected_paths_present?).and_return(true) + end + + it { is_expected.to be_truthy } + end + + context 'when the omnibus protected paths throttle has not been recently used' do + before do + expect(described_class).to receive(:omnibus_protected_paths_present?).and_return(false) + end + + it { is_expected.to be_falsey } + end + end + + context 'when rack_attack.admin_area_protected_paths_enabled config is false' do + before do + stub_config(rack_attack: { + admin_area_protected_paths_enabled: false + }) + end + + context 'when the omnibus protected paths throttle has been recently used (it has data)' do + before do + expect(described_class).to receive(:omnibus_protected_paths_present?).and_return(true) + end + + it { is_expected.to be_truthy } + end + + context 'when the omnibus protected paths throttle has not been recently used' do + before do + expect(described_class).to receive(:omnibus_protected_paths_present?).and_return(false) + end + + it { is_expected.to be_falsey } + end + end + + context 'when rack_attack.admin_area_protected_paths_enabled config is true' do + before do + stub_config(rack_attack: { + admin_area_protected_paths_enabled: true + }) + + expect(described_class).not_to receive(:omnibus_protected_paths_present?) + end + + it { is_expected.to be_falsey } + end + end +end |