Send only the Referer's scheme and host to Sentry (closes #548)
check / check (push) Waiting to run
check / check (push) Waiting to run
A Sentry event kept the Referer header verbatim, and a Referer can be an entrypoint URL: a sender that follows the README's http:// to https:// redirect sends the URL it was redirected from, and a browser sends the 404 page's URL under /h/ when it fetches that page's stylesheet. The Sentry hook now keeps only the Referer's scheme and host. The access log's reduction moves, unchanged, into a new package, internal/referer, as SchemeAndHost; the access log and the Sentry hook both call it there. The comment above sentryKeepsHeader and the README's Sentry passage say so, and the README's Package Layout lists the new package. Model: opus-5-5
This commit was merged in pull request #549.
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package referer_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"sneak.berlin/go/webhooker/internal/referer"
|
||||
)
|
||||
|
||||
// entrypointUUID is the secret part of an entrypoint URL; no case may
|
||||
// return it.
|
||||
const entrypointUUID = "0b6f7d3e-6a39-4e3c-9f0a-2c4d8e1b5a77"
|
||||
|
||||
// redacted is what SchemeAndHost returns for a Referer it cannot
|
||||
// reduce to a scheme and host.
|
||||
const redacted = "(redacted)"
|
||||
|
||||
func TestSchemeAndHost(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
referer string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "no Referer",
|
||||
referer: "",
|
||||
want: "",
|
||||
},
|
||||
{
|
||||
name: "entrypoint URL with a query",
|
||||
referer: "http://webhooker.example/h/" + entrypointUUID +
|
||||
"?src=ci",
|
||||
want: "http://webhooker.example",
|
||||
},
|
||||
{
|
||||
name: "host with a port",
|
||||
referer: "https://webhooker.example:8443/h/" + entrypointUUID,
|
||||
want: "https://webhooker.example:8443",
|
||||
},
|
||||
{
|
||||
name: "path without a scheme or host",
|
||||
referer: "/h/" + entrypointUUID,
|
||||
want: redacted,
|
||||
},
|
||||
{
|
||||
name: "host without a scheme",
|
||||
referer: "webhooker.example/h/" + entrypointUUID,
|
||||
want: redacted,
|
||||
},
|
||||
{
|
||||
name: "not a URL",
|
||||
referer: "http://[::1/h/" + entrypointUUID,
|
||||
want: redacted,
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
got := referer.SchemeAndHost(tc.referer)
|
||||
|
||||
assert.Equal(t, tc.want, got)
|
||||
assert.NotContains(t, got, entrypointUUID)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user