diff options
Diffstat (limited to 'spec/requests/product_analytics')
-rw-r--r-- | spec/requests/product_analytics/collector_app_attack_spec.rb | 41 | ||||
-rw-r--r-- | spec/requests/product_analytics/collector_app_spec.rb | 58 |
2 files changed, 0 insertions, 99 deletions
diff --git a/spec/requests/product_analytics/collector_app_attack_spec.rb b/spec/requests/product_analytics/collector_app_attack_spec.rb deleted file mode 100644 index 6f86e39c295..00000000000 --- a/spec/requests/product_analytics/collector_app_attack_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe 'ProductAnalytics::CollectorApp throttle' do - include RackAttackSpecHelpers - - include_context 'rack attack cache store' - - let(:project1) { create(:project) } - let(:project2) { create(:project) } - - before do - allow(ProductAnalyticsEvent).to receive(:create).and_return(true) - end - - context 'per application id' do - let(:params) do - { - aid: project1.id, - eid: SecureRandom.uuid - } - end - - it 'throttles the endpoint' do - # Allow requests under the rate limit. - 100.times do - expect_ok { get '/-/collector/i', params: params } - end - - # Ensure its not related to ip address - random_next_ip - - # Reject request over the limit - expect_rejection { get '/-/collector/i', params: params } - - # But allows request for different aid - expect_ok { get '/-/collector/i', params: params.merge(aid: project2.id) } - end - end -end diff --git a/spec/requests/product_analytics/collector_app_spec.rb b/spec/requests/product_analytics/collector_app_spec.rb deleted file mode 100644 index 0d55d167a6f..00000000000 --- a/spec/requests/product_analytics/collector_app_spec.rb +++ /dev/null @@ -1,58 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe 'ProductAnalytics::CollectorApp' do - let_it_be(:project) { create(:project) } - - let(:params) { {} } - let(:raw_event) { Gitlab::Json.parse(fixture_file('product_analytics/event.json')) } - - subject { get '/-/collector/i', params: params } - - RSpec.shared_examples 'not found' do - it 'repond with 404' do - expect { subject }.not_to change { ProductAnalyticsEvent.count } - - expect(response).to have_gitlab_http_status(:not_found) - end - end - - context 'correct event params' do - let(:params) { raw_event.merge(aid: project.id) } - - it 'repond with 200' do - expect { subject }.to change { ProductAnalyticsEvent.count }.by(1) - - expect(response).to have_gitlab_http_status(:ok) - end - - context 'feature disabled' do - before do - stub_feature_flags(product_analytics: false) - end - - it_behaves_like 'not found' - end - end - - context 'empty event params' do - it_behaves_like 'not found' - end - - context 'invalid project id in params' do - let(:params) do - { - aid: '-1', - p: 'web', - tna: 'sp', - tv: 'js-2.14.0', - eid: SecureRandom.uuid, - duid: SecureRandom.uuid, - sid: SecureRandom.uuid - } - end - - it_behaves_like 'not found' - end -end |