MCPcopy Create free account
hub / github.com/buggregator/server / TestHandler_SDKv3_PlainJSON

Function TestHandler_SDKv3_PlainJSON

modules/sentry/handler_test.go:290–338  ·  view source on GitHub ↗

TestHandler_SDKv3_PlainJSON tests Sentry PHP SDK v3 without tracing. v3 sends plain JSON to /api/{project}/store with event_id in payload.

(t *testing.T)

Source from the content-addressed store, hash-verified

288// TestHandler_SDKv3_PlainJSON tests Sentry PHP SDK v3 without tracing.
289// v3 sends plain JSON to /api/{project}/store with event_id in payload.
290func TestHandler_SDKv3_PlainJSON(t *testing.T) {
291 h := &handler{}
292
293 // Real payload structure from sentry/sentry 3.22.1 (no tracing → plain JSON to /store).
294 payload := `{"event_id":"8f78970685be481994063baacda75197","timestamp":1774960590.323397,"platform":"php","sdk":{"name":"sentry.php","version":"3.22.1"},"level":"error","server_name":"web-01","release":"1.0.0","environment":"production","exception":{"values":[{"type":"RuntimeException","value":"Something went wrong"}]}}`
295
296 r := httptest.NewRequest("POST", "/api/1/store", strings.NewReader(payload))
297 r.Header.Set("X-Sentry-Auth", "Sentry sentry_version=7, sentry_client=sentry.php/3.22.1, sentry_key=test")
298
299 inc, err := h.Handle(r)
300 if err != nil {
301 t.Fatalf("Handle() error: %v", err)
302 }
303 if inc == nil {
304 t.Fatal("Handle() returned nil, want non-nil incoming event")
305 }
306 if inc.Type != "sentry" {
307 t.Errorf("Type = %q, want %q", inc.Type, "sentry")
308 }
309 if inc.UUID != "8f78970685be481994063baacda75197" {
310 t.Errorf("UUID = %q, want %q", inc.UUID, "8f78970685be481994063baacda75197")
311 }
312 // A numeric DSN project id (forced by the Sentry SDKs) resolves to empty so
313 // the event lands in the default project downstream — see issue #338.
314 if inc.Project != "" {
315 t.Errorf("Project = %q, want %q", inc.Project, "")
316 }
317
318 // Payload must contain event_id so the frontend can identify the event.
319 var parsed map[string]any
320 if err := json.Unmarshal(inc.Payload, &parsed); err != nil {
321 t.Fatalf("failed to parse payload: %v", err)
322 }
323 if parsed["event_id"] != "8f78970685be481994063baacda75197" {
324 t.Errorf("payload event_id = %v, want %q", parsed["event_id"], "8f78970685be481994063baacda75197")
325 }
326 if parsed["level"] != "error" {
327 t.Errorf("payload level = %v, want %q", parsed["level"], "error")
328 }
329
330 exc, ok := parsed["exception"].(map[string]any)
331 if !ok {
332 t.Fatal("payload missing exception")
333 }
334 vals, ok := exc["values"].([]any)
335 if !ok || len(vals) == 0 {
336 t.Fatal("payload exception.values is empty")
337 }
338}
339
340// TestHandler_SDKv3_Envelope tests Sentry PHP SDK v3 with tracing enabled.
341// v3 sends envelope to /api/{project}/envelope with event_id in BOTH envelope header AND item payload.

Callers

nothing calls this directly

Calls 1

HandleMethod · 0.95

Tested by

no test coverage detected