Skip to content

Commit 33c2b78

Browse files
committed
Enhance TestHandler response to include received environment data in the payload
1 parent a3a178e commit 33c2b78

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

spec/acceptance/acceptance_tests.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,13 +388,26 @@ def expired_unix_timestamp(seconds_ago = 600)
388388

389389
it "successfully validates using a custom auth plugin" do
390390
payload = {}.to_json
391-
headers = { "Authorization" => "Bearer octoawesome-shared-secret" }
392-
response = make_request(:post, "/webhooks/with_custom_auth_plugin", payload, headers)
391+
headers = { "Authorization" => "Bearer octoawesome-shared-secret", "Content-Type" => "application/json" }
392+
response = make_request(:post, "/webhooks/with_custom_auth_plugin?foo=bar&bar=baz", payload, headers)
393393

394394
expect_response(response, Net::HTTPSuccess)
395395
body = parse_json_response(response)
396396
expect(body["status"]).to eq("test_success")
397397
expect(body["handler"]).to eq("TestHandler")
398+
expect(body["payload_received"]).to eq({})
399+
expect(body["env_received"]).to have_key("REQUEST_METHOD")
400+
401+
env = body["env_received"]
402+
expect(env["hooks.request_id"]).to be_a(String)
403+
expect(env["hooks.handler"]).to eq("TestHandler")
404+
expect(env["hooks.endpoint_config"]).to be_a(Hash)
405+
expect(env["hooks.start_time"]).to be_a(String)
406+
expect(env["hooks.full_path"]).to eq("/webhooks/with_custom_auth_plugin")
407+
expect(env["HTTP_AUTHORIZATION"]).to eq("Bearer octoawesome-shared-secret")
408+
expect(env["CONTENT_TYPE"]).to eq("application/json")
409+
expect(env["CONTENT_LENGTH"]).to eq("2") # length of "{}"
410+
expect(env["QUERY_STRING"]).to eq("foo=bar&bar=baz")
398411
end
399412

400413
it "rejects requests with invalid credentials using custom auth plugin" do

spec/acceptance/plugins/handlers/test_handler.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ def call(payload:, headers:, env:, config:)
66
status: "test_success",
77
handler: "TestHandler",
88
payload_received: payload,
9+
env_received: env,
910
config_opts: config[:opts],
1011
timestamp: Time.now.utc.iso8601
1112
}

0 commit comments

Comments
 (0)