more
This commit is contained in:
1 parent
8f670dfa2f
commit
2237fbda55
15 files changed
+594
-52
No files matched your search
@@ -106,3 +106,29 @@ func TestNormalizeHTTPRoutePrefersSpecificPathOverRootMount(t *testing.T) {
|
||||
t.Fatalf("expected specific URL path, got %q", events[0].Route)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeHTTPRequestMetadataIsSafeAndNormalized(t *testing.T) {
|
||||
data := []byte(`{"resourceSpans":[{"resource":{"attributes":[{"key":"service.name","value":{"stringValue":"preview"}}]},"scopeSpans":[{"spans":[{"traceId":"trace-1","name":"GET /","attributes":[{"key":"http.method","value":{"stringValue":"GET"}},{"key":"http.host","value":{"stringValue":"preview.example.test:443"}},{"key":"http.target","value":{"stringValue":"/"}},{"key":"http.user_agent","value":{"stringValue":"Chrome"}},{"key":"http.request.header.origin","value":{"stringValue":"https://app.example.test"}},{"key":"http.request.header.referer","value":{"stringValue":"https://app.example.test/dashboard?secret=1"}},{"key":"http.request.header.sec_fetch_site","value":{"stringValue":"same-origin"}},{"key":"http.request.header.sec_fetch_mode","value":{"stringValue":"navigate"}}]}]}]}]}`)
|
||||
events, err := NormalizeEntry("traces", 99, data)
|
||||
if err != nil || len(events) != 1 {
|
||||
t.Fatalf("normalize failed: %v %+v", err, events)
|
||||
}
|
||||
event := events[0]
|
||||
if event.Method != "GET" || event.Host != "preview.example.test" || event.UserAgent != "Chrome" {
|
||||
t.Fatalf("unexpected request metadata: %+v", event)
|
||||
}
|
||||
if event.OriginHost != "app.example.test" || event.RefererHost != "app.example.test" {
|
||||
t.Fatalf("request metadata must retain hosts without paths: %+v", event)
|
||||
}
|
||||
if event.FetchSite != "same-origin" || event.FetchMode != "navigate" {
|
||||
t.Fatalf("missing fetch metadata: %+v", event)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsErrorStatusIgnoresMissingResources(t *testing.T) {
|
||||
for code, want := range map[int]bool{200: false, 404: false, 410: false, 401: true, 500: true} {
|
||||
if got := isErrorStatus(code); got != want {
|
||||
t.Errorf("isErrorStatus(%d) = %v, want %v", code, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user