From 94fef30c6d091e343e346cc63d7ca5c5a35c731b Mon Sep 17 00:00:00 2001 From: Jeff Park Date: Mon, 17 Mar 2025 14:40:51 -0400 Subject: [PATCH 1/2] Fix: use standard cloud connector headers for workflow Lowercasing keys so LSP will accept Addressing feedback Using fake headers for test --- ee/lib/ai/duo_workflow/duo_workflow_service/client.rb | 11 ++++++----- .../duo_workflow/duo_workflow_service/client_spec.rb | 8 +++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/ee/lib/ai/duo_workflow/duo_workflow_service/client.rb b/ee/lib/ai/duo_workflow/duo_workflow_service/client.rb index 463c654ef0c8c1..270152fd707c1d 100644 --- a/ee/lib/ai/duo_workflow/duo_workflow_service/client.rb +++ b/ee/lib/ai/duo_workflow/duo_workflow_service/client.rb @@ -38,13 +38,14 @@ def generate_token attr_reader :duo_workflow_service_url, :current_user def metadata - { + auth_headers = { "authorization" => "Bearer #{token}", - "x-gitlab-authentication-type" => "oidc", - 'x-gitlab-instance-id' => ::Gitlab::GlobalAnonymousId.instance_id, - 'x-gitlab-realm' => ::CloudConnector.gitlab_realm, - 'x-gitlab-global-user-id' => ::Gitlab::GlobalAnonymousId.user_id(current_user) + "x-gitlab-authentication-type" => "oidc" } + ai_headers = ::CloudConnector.ai_headers(current_user) + lowercase_ai_headers = ai_headers.transform_keys(&:downcase) + + auth_headers.merge(lowercase_ai_headers) end def token diff --git a/ee/spec/lib/ai/duo_workflow/duo_workflow_service/client_spec.rb b/ee/spec/lib/ai/duo_workflow/duo_workflow_service/client_spec.rb index ea51e0dbdecc6d..db673e4ff3b94d 100644 --- a/ee/spec/lib/ai/duo_workflow/duo_workflow_service/client_spec.rb +++ b/ee/spec/lib/ai/duo_workflow/duo_workflow_service/client_spec.rb @@ -11,6 +11,7 @@ let(:response) { double(token: 'a user jwt', expiresAt: 'a timestamp') } # rubocop:disable RSpec/VerifiedDoubles -- instance_double keeps raising error the DuoWorkflowService::GenerateTokenResponse class does not implement the class method: token let(:channel_credentials) { instance_of(GRPC::Core::ChannelCredentials) } let(:cloud_connector_service_data_double) { instance_of(CloudConnector::SelfSigned::AvailableServiceData) } + let(:fake_headers) { { 'X-Fake-Header1' => 'Value1', 'X-Fake-Header2' => 'Value2' } } subject(:client) do described_class.new( @@ -28,20 +29,21 @@ allow(DuoWorkflowService::DuoWorkflow::Stub).to receive(:new).with(anything, channel_credentials).and_return(stub) allow(stub).to receive(:generate_token).and_return(response) allow(DuoWorkflowService::GenerateTokenRequest).to receive(:new).and_return(request) + allow(::CloudConnector).to receive(:ai_headers).with(current_user).and_return(fake_headers) end describe '#generate_token' do it 'sends the correct metadata hash' do client.generate_token + expect(::CloudConnector).to have_received(:ai_headers).with(current_user) expect(stub).to have_received(:generate_token).with( request, metadata: { "authorization" => "Bearer instance jwt", "x-gitlab-authentication-type" => "oidc", - 'x-gitlab-instance-id' => ::Gitlab::GlobalAnonymousId.instance_id, - 'x-gitlab-realm' => ::CloudConnector.gitlab_realm, - 'x-gitlab-global-user-id' => ::Gitlab::GlobalAnonymousId.user_id(current_user) + 'x-fake-header1' => 'Value1', + 'x-fake-header2' => 'Value2' } ) end -- GitLab From 286cc4b93425ca019212e93a8be8b4b06d0ed732 Mon Sep 17 00:00:00 2001 From: Jeff Park Date: Wed, 19 Mar 2025 09:59:43 -0400 Subject: [PATCH 2/2] Removing lowercase logic --- ee/lib/ai/duo_workflow/duo_workflow_service/client.rb | 8 ++------ .../ai/duo_workflow/duo_workflow_service/client_spec.rb | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/ee/lib/ai/duo_workflow/duo_workflow_service/client.rb b/ee/lib/ai/duo_workflow/duo_workflow_service/client.rb index 270152fd707c1d..6ab1ac8d76ccd8 100644 --- a/ee/lib/ai/duo_workflow/duo_workflow_service/client.rb +++ b/ee/lib/ai/duo_workflow/duo_workflow_service/client.rb @@ -38,14 +38,10 @@ def generate_token attr_reader :duo_workflow_service_url, :current_user def metadata - auth_headers = { + { "authorization" => "Bearer #{token}", "x-gitlab-authentication-type" => "oidc" - } - ai_headers = ::CloudConnector.ai_headers(current_user) - lowercase_ai_headers = ai_headers.transform_keys(&:downcase) - - auth_headers.merge(lowercase_ai_headers) + }.merge(::CloudConnector.ai_headers(current_user)) end def token diff --git a/ee/spec/lib/ai/duo_workflow/duo_workflow_service/client_spec.rb b/ee/spec/lib/ai/duo_workflow/duo_workflow_service/client_spec.rb index db673e4ff3b94d..ebe28db569bbe3 100644 --- a/ee/spec/lib/ai/duo_workflow/duo_workflow_service/client_spec.rb +++ b/ee/spec/lib/ai/duo_workflow/duo_workflow_service/client_spec.rb @@ -11,7 +11,7 @@ let(:response) { double(token: 'a user jwt', expiresAt: 'a timestamp') } # rubocop:disable RSpec/VerifiedDoubles -- instance_double keeps raising error the DuoWorkflowService::GenerateTokenResponse class does not implement the class method: token let(:channel_credentials) { instance_of(GRPC::Core::ChannelCredentials) } let(:cloud_connector_service_data_double) { instance_of(CloudConnector::SelfSigned::AvailableServiceData) } - let(:fake_headers) { { 'X-Fake-Header1' => 'Value1', 'X-Fake-Header2' => 'Value2' } } + let(:fake_headers) { { 'x-fake-header1' => 'Value1', 'x-fake-header2' => 'Value2' } } subject(:client) do described_class.new( -- GitLab