fix(14): WR-02 derive the screenshot extension from the sniffed image type

The public screenshot kept the client file's extension, so a valid image
named x.html or x.svg was stored and served under that type. The disk
name now carries the client extension only when it names the sniffed
type, else the type's own; file_name keeps only the client's base name.
This commit is contained in:
Jakub Zych
2026-10-04 07:59:59 +02:00
parent 3057719fa1
commit 5a8b7f816f
2 changed files with 75 additions and 12 deletions

View File

@@ -617,6 +617,30 @@ func TestFeedbackSubmit(t *testing.T) {
}
})
t.Run("client-extension-never-names-the-public-file", func(t *testing.T) {
_, app, gdb := newHandler(t)
bucket, err := blob.OpenBucket(t.Context(), "mem://")
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = bucket.Close() })
for name, want := range map[string]string{
"x.html": ".png", "../../x.svg": ".png", "noext": ".png", "Shot.PNG": ".png",
} {
sub := &models.Submission{Message: "x", Type: "bug", PageURL: "https://widget.example.test/"}
if err := classes.StoreSubmission(t.Context(), app, gdb, bucket, sub, &classes.Screenshot{Filename: name, Data: pngBytes(t, 0)}); err != nil {
t.Fatal(err)
}
file, err := classes.ScreenshotOf(t.Context(), gdb, sub.ID)
if err != nil || file == nil {
t.Fatalf("screenshot %v %v", file, err)
}
if !strings.HasSuffix(file.DiskName, want) || strings.Contains(file.FileName, "/") {
t.Fatalf("%q stored as %q (file_name %q)", name, file.DiskName, file.FileName)
}
}
})
t.Run("rolled-back-write-queues-nothing", func(t *testing.T) {
_, app, gdb := newHandler(t)
subsBefore := countRows(t, gdb, `SELECT COUNT(*) FROM golem15_feedback_submissions`)