From 910a86194255f306001833830d37db28230567ec Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 13 Oct 2020 15:31:31 -0400 Subject: [PATCH] webhooks/legacy_test: verify headers are recorded --- webhooks/legacy_test.go | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/webhooks/legacy_test.go b/webhooks/legacy_test.go index 6146ba3c1bb1cf75e9b33115cc612ce412ffb196..2f13c4db26324142e76b3cfeff49826c3291ea33 100644 --- a/webhooks/legacy_test.go +++ b/webhooks/legacy_test.go @@ -2,6 +2,7 @@ package webhooks import ( "context" + "database/sql/driver" "io/ioutil" "net/http" "net/http/httptest" @@ -34,6 +35,27 @@ internal-ipnet=127.0.0.1/24,::1/64`)) crypto.InitCrypto(conf) } +type argContains struct { + matches []string +} + +func ArgMatchesAll(matches... string) *argContains { + return &argContains{matches} +} + +func (ac *argContains) Match(v driver.Value) bool { + str, ok := v.(string) + if !ok { + return false + } + for _, match := range ac.matches { + if !strings.Contains(str, match) { + return false + } + } + return true +} + func TestDelivery(t *testing.T) { var called bool srv := httptest.NewServer(http.HandlerFunc( @@ -101,7 +123,15 @@ func TestDelivery(t *testing.T) { mock.ExpectBegin() mock.ExpectExec(`UPDATE user_webhook_delivery`). - WithArgs("Thanks!", 200, sqlmock.AnyArg(), 4096) // Any => response headers + WithArgs("Thanks!", 200, + sqlmock.AnyArg(), // Response headers + ArgMatchesAll( + "X-Payload-Signature", + "X-Payload-Nonce", + "X-Webhook-Event", + "X-Webhook-Delivery", + ), // Final request headers + 4096) mock.ExpectCommit() ctx = database.Context(context.Background(), db)