Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
894603059b |
+27
-52
@@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/sha256"
|
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -474,64 +473,40 @@ func TestLoadRowsCountAgreeDuringScan(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestLoadRowsRefuseWrongSizeHash stores a record whose head, tail or
|
// TestLoadRowsRefuseShortHash stores a record whose head is one byte,
|
||||||
// content is not the 32 bytes of a SHA-256: either one byte, or the 64
|
// not the 32 bytes of a SHA-256: loadFileRows and loadSignatureRows
|
||||||
// bytes of a SHA-256 written as hex text. loadFileRows and
|
// must each fail on it with an error naming its path.
|
||||||
// loadSignatureRows must each fail on it with an error naming its path.
|
func TestLoadRowsRefuseShortHash(t *testing.T) {
|
||||||
func TestLoadRowsRefuseWrongSizeHash(t *testing.T) {
|
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
hexText := strings.Repeat("ab", sha256.Size)
|
db := openTestDB(t)
|
||||||
|
|
||||||
cases := []struct {
|
err := applyChanges(t.Context(), db, []scanRec{{path: "/a/f"}}, nil, nil)
|
||||||
name string
|
if err != nil {
|
||||||
update string
|
t.Fatal(err)
|
||||||
value any
|
|
||||||
}{
|
|
||||||
{"one-byte head", "UPDATE files SET head = ?", []byte{0}},
|
|
||||||
{"hex-text head", "UPDATE files SET head = ?", hexText},
|
|
||||||
{"one-byte tail", "UPDATE files SET tail = ?", []byte{0}},
|
|
||||||
{"hex-text tail", "UPDATE files SET tail = ?", hexText},
|
|
||||||
{"one-byte content", "UPDATE files SET content = ?", []byte{0}},
|
|
||||||
{"hex-text content", "UPDATE files SET content = ?", hexText},
|
|
||||||
}
|
}
|
||||||
for _, c := range cases {
|
|
||||||
t.Run(c.name, func(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
db := openTestDB(t)
|
_, err = db.ExecContext(t.Context(), "UPDATE files SET head = x'00'")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
err := applyChanges(t.Context(), db,
|
loads := map[string]func() error{
|
||||||
[]scanRec{{path: "/a/f"}}, nil, nil)
|
"loadFileRows": func() error {
|
||||||
if err != nil {
|
return loadFileRows(t.Context(), db, func(int64) {},
|
||||||
t.Fatal(err)
|
func(scanRec) {})
|
||||||
}
|
},
|
||||||
|
"loadSignatureRows": func() error {
|
||||||
|
return loadSignatureRows(t.Context(), db, func(int64) {},
|
||||||
|
func(scanRec) error { return nil })
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
_, err = db.ExecContext(t.Context(), c.update, c.value)
|
for name, load := range loads {
|
||||||
if err != nil {
|
err := load()
|
||||||
t.Fatal(err)
|
if !errors.Is(err, errHashSize) || !strings.Contains(err.Error(), "/a/f") {
|
||||||
}
|
t.Errorf("%s: err = %v, want %v naming /a/f", name, err, errHashSize)
|
||||||
|
}
|
||||||
loads := map[string]func() error{
|
|
||||||
"loadFileRows": func() error {
|
|
||||||
return loadFileRows(t.Context(), db, func(int64) {},
|
|
||||||
func(scanRec) {})
|
|
||||||
},
|
|
||||||
"loadSignatureRows": func() error {
|
|
||||||
return loadSignatureRows(t.Context(), db, func(int64) {},
|
|
||||||
func(scanRec) error { return nil })
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for name, load := range loads {
|
|
||||||
err := load()
|
|
||||||
if !errors.Is(err, errHashSize) ||
|
|
||||||
!strings.Contains(err.Error(), "/a/f") {
|
|
||||||
t.Errorf("%s: err = %v, want %v naming /a/f",
|
|
||||||
name, err, errHashSize)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user