Add negative and boundary tests for blobgen and types (closes #170)
check / check (pull_request) Successful in 2m20s
check / check (pull_request) Successful in 2m20s
Test-only. internal/blobgen and internal/types had no negative or boundary coverage. Adds, in package blobgen_test: Writer-to-Reader round trips at the 64 KiB age-segment edges for random and compressible data, checking plaintext, byte counts and the reader/writer hashes by decrypting; a wrong-identity open; truncation and single-byte corruption of a multi-segment blob at every region; trailing bytes, empty input and garbage; rejected and accepted compression levels; nil, empty and invalid recipients; and a failing destination. In package types_test: Value/Scan round trips, NULL, wrong-type and malformed Scan, Parse and IsZero for FileID and BlobID. internal/crypto and CompressStream/CompressData no longer exist and are skipped. The "cut right after the age header and nonce" truncation is excluded: it reads as valid and empty today and belongs to #152. Reworded two writer_test.go messages that overstated what the double hash prevents. Model: opus-4-8
This commit is contained in:
@@ -13,8 +13,9 @@ import (
|
||||
)
|
||||
|
||||
// TestWriterHashIsDoubleHash verifies that Writer.ContentID() returns
|
||||
// the double hash SHA256(SHA256(plaintext)) for security.
|
||||
// Double hashing prevents attackers from confirming existence of known content.
|
||||
// SHA256(SHA256(plaintext)). Stored objects are named by this second hash so a
|
||||
// name is not the plaintext's own SHA-256; this does not stop someone who
|
||||
// already holds the plaintext from confirming it.
|
||||
func TestWriterHashIsDoubleHash(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@@ -60,11 +61,11 @@ func TestWriterHashIsDoubleHash(t *testing.T) {
|
||||
|
||||
// The writer hash should match the double hash
|
||||
assert.Equal(t, expectedDoubleHash, writerHash,
|
||||
"Writer.ContentID() should return SHA256(SHA256(plaintext)) for security")
|
||||
"Writer.ContentID() must be SHA256(SHA256(plaintext))")
|
||||
|
||||
// Verify it's NOT the single hash (would leak information)
|
||||
// It must be the second hash, not the plaintext's own SHA-256.
|
||||
assert.NotEqual(t, singleHashStr, writerHash,
|
||||
"Writer hash should not be single hash (would allow content confirmation attacks)")
|
||||
"Writer hash must be the double hash, not the single SHA-256")
|
||||
}
|
||||
|
||||
// TestWriterDeterministicHash verifies that the same input always produces
|
||||
|
||||
Reference in New Issue
Block a user