package vaultik //nolint:testpackage // calls unexported verifyManifestAgainstDatabase import ( "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "sneak.berlin/go/vaultik/internal/log" "sneak.berlin/go/vaultik/internal/snapshot" ) // Blob hashes shared by the manifest-verification tests below. const ( manifestTestBlobA = "blob-a" manifestTestBlobB = "blob-b" ) // TestVerifyManifestAgainstDatabase_MissingBlobFails is the regression // guard for issue #157: deep verify must fail when the manifest omits a // blob the database records. The divergence used to be logged as a // warning while verification still returned ok, so an incomplete // manifest — the exact defect that lets prune later delete a needed blob // — passed unnoticed. func TestVerifyManifestAgainstDatabase_MissingBlobFails(t *testing.T) { log.Initialize(log.Config{}) t.Parallel() v := &Vaultik{} dbBlobs := []snapshot.BlobInfo{ {Hash: manifestTestBlobA, CompressedSize: 10}, {Hash: manifestTestBlobB, CompressedSize: 20}, } manifest := &snapshot.Manifest{ Blobs: []snapshot.BlobInfo{ {Hash: manifestTestBlobA, CompressedSize: 10}, }, } err := v.verifyManifestAgainstDatabase(manifest, dbBlobs) require.Error(t, err, "verify must fail when the manifest omits a database blob") assert.Contains(t, err.Error(), manifestTestBlobB) } // TestVerifyManifestAgainstDatabase_MatchingSetsPass keeps the other half // honest: identical blob sets still verify, so the check above cannot be // satisfied by failing everything. func TestVerifyManifestAgainstDatabase_MatchingSetsPass(t *testing.T) { log.Initialize(log.Config{}) t.Parallel() v := &Vaultik{} blobs := []snapshot.BlobInfo{ {Hash: manifestTestBlobA, CompressedSize: 10}, {Hash: manifestTestBlobB, CompressedSize: 20}, } manifest := &snapshot.Manifest{Blobs: blobs} require.NoError(t, v.verifyManifestAgainstDatabase(manifest, blobs)) }