summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/middleware/webhook_recursion_detection_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-01-20 09:16:11 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-01-20 09:16:11 +0000
commitedaa33dee2ff2f7ea3fac488d41558eb5f86d68c (patch)
tree11f143effbfeba52329fb7afbd05e6e2a3790241 /spec/lib/gitlab/middleware/webhook_recursion_detection_spec.rb
parentd8a5691316400a0f7ec4f83832698f1988eb27c1 (diff)
downloadgitlab-ce-edaa33dee2ff2f7ea3fac488d41558eb5f86d68c.tar.gz
Add latest changes from gitlab-org/gitlab@14-7-stable-eev14.7.0-rc42
Diffstat (limited to 'spec/lib/gitlab/middleware/webhook_recursion_detection_spec.rb')
-rw-r--r--spec/lib/gitlab/middleware/webhook_recursion_detection_spec.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/lib/gitlab/middleware/webhook_recursion_detection_spec.rb b/spec/lib/gitlab/middleware/webhook_recursion_detection_spec.rb
new file mode 100644
index 00000000000..c8dbc990f8c
--- /dev/null
+++ b/spec/lib/gitlab/middleware/webhook_recursion_detection_spec.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+require 'fast_spec_helper'
+require 'action_dispatch'
+require 'rack'
+require 'request_store'
+
+RSpec.describe Gitlab::Middleware::WebhookRecursionDetection do
+ let(:app) { double(:app) }
+ let(:middleware) { described_class.new(app) }
+ let(:env) { Rack::MockRequest.env_for("/").merge(headers) }
+
+ around do |example|
+ Gitlab::WithRequestStore.with_request_store { example.run }
+ end
+
+ describe '#call' do
+ subject(:call) { described_class.new(app).call(env) }
+
+ context 'when the recursion detection header is present' do
+ let(:new_uuid) { SecureRandom.uuid }
+ let(:headers) { { 'HTTP_X_GITLAB_EVENT_UUID' => new_uuid } }
+
+ it 'sets the request UUID from the header' do
+ expect(app).to receive(:call)
+ expect { call }.to change { Gitlab::WebHooks::RecursionDetection::UUID.instance.request_uuid }.to(new_uuid)
+ end
+ end
+
+ context 'when recursion headers are not present' do
+ let(:headers) { {} }
+
+ it 'works without errors' do
+ expect(app).to receive(:call)
+
+ call
+
+ expect(Gitlab::WebHooks::RecursionDetection::UUID.instance.request_uuid).to be_nil
+ end
+ end
+ end
+end