Skip to content

Commit

Permalink
put trailing slash in EVP_PROXY_PATH_PREFIX as it is returned like th…
Browse files Browse the repository at this point in the history
…at by agent in "endpoints" list
  • Loading branch information
anmarchenko committed Oct 18, 2023
1 parent b394bc9 commit e67e618
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/datadog/ci/configuration/components.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def activate_ci!(settings)

def can_use_evp_proxy?(settings, agent_settings)
Datadog::Core::Remote::Negotiation.new(settings, agent_settings).endpoint?(
"#{Ext::Transport::EVP_PROXY_PATH_PREFIX}/"
Ext::Transport::EVP_PROXY_PATH_PREFIX
)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/ci/ext/transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Transport
HEADER_EVP_SUBDOMAIN = "X-Datadog-EVP-Subdomain"
HEADER_CONTAINER_ID = "Datadog-Container-ID"

EVP_PROXY_PATH_PREFIX = "/evp_proxy/v2"
EVP_PROXY_PATH_PREFIX = "/evp_proxy/v2/"
TEST_VISIBILITY_INTAKE_HOST_PREFIX = "citestcycle-intake"
TEST_VISIBILITY_INTAKE_PATH = "/api/v2/citestcycle"

Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/ci/transport/api/evp_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def initialize(host:, port:, ssl:, timeout:)
end

def request(path:, payload:, verb: "post")
path = "#{Ext::Transport::EVP_PROXY_PATH_PREFIX}#{path}"
path = "#{Ext::Transport::EVP_PROXY_PATH_PREFIX}#{path.sub(/^\//, "")}"

http.request(
path: path,
Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/ci/transport/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def request(path:, payload:, headers:, verb: "post")
"compression_enabled=#{compress}; path=#{path}; payload_size=#{payload.size}"
end

Datadog.logger.debug(headers)

ResponseDecorator.new(
adapter.call(
build_env(path: path, payload: payload, headers: headers, verb: verb)
Expand Down
2 changes: 1 addition & 1 deletion sig/datadog/ci/ext/transport.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Datadog

HEADER_CONTAINER_ID: "Datadog-Container-ID"

EVP_PROXY_PATH_PREFIX: "/evp_proxy/v2"
EVP_PROXY_PATH_PREFIX: "/evp_proxy/v2/"

TEST_VISIBILITY_INTAKE_HOST_PREFIX: "citestcycle-intake"

Expand Down
40 changes: 29 additions & 11 deletions spec/datadog/ci/transport/api/evp_proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,36 @@
context "without container id" do
let(:container_id) { nil }

it "produces correct headers and forwards request to HTTP layer prepending path with evp_proxy" do
expect(http).to receive(:request).with(
path: "/evp_proxy/v2/path",
payload: "payload",
verb: "post",
headers: {
"Content-Type" => "application/msgpack",
"X-Datadog-EVP-Subdomain" => "citestcycle-intake"
}
)
context "with path starting from / character" do
it "produces correct headers and forwards request to HTTP layer prepending path with evp_proxy" do
expect(http).to receive(:request).with(
path: "/evp_proxy/v2/path",
payload: "payload",
verb: "post",
headers: {
"Content-Type" => "application/msgpack",
"X-Datadog-EVP-Subdomain" => "citestcycle-intake"
}
)

subject.request(path: "/path", payload: "payload")
subject.request(path: "/path", payload: "payload")
end
end

context "with path without / in the beginning" do
it "constructs evp proxy path correctly" do
expect(http).to receive(:request).with(
path: "/evp_proxy/v2/path",
payload: "payload",
verb: "post",
headers: {
"Content-Type" => "application/msgpack",
"X-Datadog-EVP-Subdomain" => "citestcycle-intake"
}
)

subject.request(path: "path", payload: "payload")
end
end
end

Expand Down

0 comments on commit e67e618

Please sign in to comment.