fix(album): enforce signed upload MIME, map duplicate folders, and optimize HEAD
This commit is contained in:
@@ -171,9 +171,19 @@ func TestFolderCRUDAndNonEmptyDelete(t *testing.T) {
|
||||
t.Fatalf("EnsureFolder created duplicate id %d != %d", ensured.ID, root.ID)
|
||||
}
|
||||
|
||||
// Duplicate sibling slug fails unique index.
|
||||
if _, err := svc.CreateFolder(ctx, gdb, "Press Kit", nil); err == nil {
|
||||
t.Fatal("expected duplicate sibling folder error")
|
||||
// Duplicate sibling slug returns ErrFolderExists.
|
||||
if _, err := svc.CreateFolder(ctx, gdb, "Press Kit", nil); !errors.Is(err, album.ErrFolderExists) {
|
||||
t.Fatalf("duplicate CreateFolder err = %v, want ErrFolderExists", err)
|
||||
}
|
||||
other, err := svc.CreateFolder(ctx, gdb, "Archive", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("CreateFolder other: %v", err)
|
||||
}
|
||||
if _, err := svc.UpdateFolder(ctx, gdb, other.ID, "press-kit", nil, false); !errors.Is(err, album.ErrFolderExists) {
|
||||
t.Fatalf("duplicate rename UpdateFolder err = %v, want ErrFolderExists", err)
|
||||
}
|
||||
if err := svc.DeleteFolder(ctx, gdb, other.ID); err != nil {
|
||||
t.Fatalf("DeleteFolder other: %v", err)
|
||||
}
|
||||
|
||||
child, err := svc.CreateFolder(ctx, gdb, "Logos", &root.ID)
|
||||
@@ -421,6 +431,21 @@ func TestConsumeUploadTokenSingleUse(t *testing.T) {
|
||||
if rec2.Code != http.StatusUnauthorized {
|
||||
t.Fatalf("replay PUT status = %d, want 401", rec2.Code)
|
||||
}
|
||||
|
||||
// 6. ExpectedContentType mismatch is rejected with 422.
|
||||
prep3, err := svc.PrepareUpload(ctx, gdb, album.PrepareUploadInput{
|
||||
CreatedBy: 7,
|
||||
ExpectedFilename: "expected-jpeg.png",
|
||||
ExpectedContentType: "image/jpeg",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rec3 := httptest.NewRecorder()
|
||||
mux.ServeHTTP(rec3, httptest.NewRequest(http.MethodPut, "/media/upload/"+prep3.Token, bytes.NewReader(pngBytes)))
|
||||
if rec3.Code != http.StatusUnprocessableEntity {
|
||||
t.Fatalf("mismatched content type PUT status = %d, want 422, body=%s", rec3.Code, rec3.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteItemInTxAfterCommit(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user