Commit 7423627f authored by Kerri Miller's avatar Kerri Miller

Merge branch 'pedropombeiro/326248-external-pvs-token-in-header' into 'master'

Send token in header to external validation service

See merge request gitlab-org/gitlab!57855
parents 8165db74 535d7076
...@@ -69,8 +69,12 @@ module Gitlab ...@@ -69,8 +69,12 @@ module Gitlab
end end
def validate_service_request def validate_service_request
headers = {}
headers['X-Gitlab-Token'] = validation_service_token if validation_service_token
Gitlab::HTTP.post( Gitlab::HTTP.post(
validation_service_url, timeout: validation_service_timeout, validation_service_url, timeout: validation_service_timeout,
headers: headers,
body: validation_service_payload.to_json body: validation_service_payload.to_json
) )
end end
...@@ -86,6 +90,10 @@ module Gitlab ...@@ -86,6 +90,10 @@ module Gitlab
ENV['EXTERNAL_VALIDATION_SERVICE_URL'] ENV['EXTERNAL_VALIDATION_SERVICE_URL']
end end
def validation_service_token
ENV['EXTERNAL_VALIDATION_SERVICE_TOKEN']
end
def validation_service_payload def validation_service_payload
{ {
project: { project: {
......
...@@ -63,6 +63,7 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Validate::External do ...@@ -63,6 +63,7 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Validate::External do
expect(::Gitlab::HTTP).to receive(:post) do |_url, params| expect(::Gitlab::HTTP).to receive(:post) do |_url, params|
expect(params[:body]).to match_schema('/external_validation') expect(params[:body]).to match_schema('/external_validation')
expect(params[:timeout]).to eq(described_class::DEFAULT_VALIDATION_REQUEST_TIMEOUT) expect(params[:timeout]).to eq(described_class::DEFAULT_VALIDATION_REQUEST_TIMEOUT)
expect(params[:headers]).to eq({})
end end
perform! perform!
...@@ -119,6 +120,20 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Validate::External do ...@@ -119,6 +120,20 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Validate::External do
end end
end end
context 'when EXTERNAL_VALIDATION_SERVICE_TOKEN is set' do
before do
stub_env('EXTERNAL_VALIDATION_SERVICE_TOKEN', '123')
end
it 'passes token in X-Gitlab-Token header' do
expect(::Gitlab::HTTP).to receive(:post) do |_url, params|
expect(params[:headers]).to eq({ 'X-Gitlab-Token' => '123' })
end
perform!
end
end
context 'when validation returns 200 OK' do context 'when validation returns 200 OK' do
before do before do
stub_request(:post, validation_service_url).to_return(status: 200, body: "{}") stub_request(:post, validation_service_url).to_return(status: 200, body: "{}")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment