Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03f126edc1 |
@@ -7,10 +7,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"filippo.io/age"
|
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"sneak.berlin/go/vaultik/internal/blobgen"
|
|
||||||
"sneak.berlin/go/vaultik/internal/database"
|
"sneak.berlin/go/vaultik/internal/database"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -58,37 +56,6 @@ func TestMaterializeSnapshotDBPrivateDir(t *testing.T) {
|
|||||||
require.Error(t, err, "materialized snapshot database must be read-only")
|
require.Error(t, err, "materialized snapshot database must be read-only")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestMaterializeSnapshotDBRejectsCompleteEmptyStream proves the written == 0
|
|
||||||
// guard rejects a genuinely empty but complete metadata object: a real age
|
|
||||||
// header, nonce, and final tag encrypting zero plaintext bytes. The truncation
|
|
||||||
// case is stopped earlier by the reader (io.ErrUnexpectedEOF) and never reaches
|
|
||||||
// this branch, so it needs its own input. This complete stream decrypts to zero
|
|
||||||
// bytes with a clean EOF, passes the reader, and must be refused as empty rather
|
|
||||||
// than accepted as a valid zero-table database. Reverting the guard lets the
|
|
||||||
// empty file open as a fresh schema and the test fails.
|
|
||||||
func TestMaterializeSnapshotDBRejectsCompleteEmptyStream(t *testing.T) {
|
|
||||||
identity, err := age.GenerateX25519Identity()
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
var stream bytes.Buffer
|
|
||||||
|
|
||||||
w, err := age.Encrypt(&stream, identity.Recipient())
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.NoError(t, w.Close())
|
|
||||||
|
|
||||||
blobReader, err := blobgen.NewReader(bytes.NewReader(stream.Bytes()), identity)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
t.Cleanup(func() { _ = blobReader.Close() })
|
|
||||||
|
|
||||||
t.Setenv("TMPDIR", t.TempDir())
|
|
||||||
|
|
||||||
v := &Vaultik{ctx: context.Background(), Fs: afero.NewOsFs()}
|
|
||||||
|
|
||||||
_, _, err = v.materializeSnapshotDB(blobReader)
|
|
||||||
require.ErrorIs(t, err, errEmptySnapshotDB)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestMaterializeSnapshotDBRemovesDirOnOpenFailure proves a failed open
|
// TestMaterializeSnapshotDBRemovesDirOnOpenFailure proves a failed open
|
||||||
// leaves no temp directory behind.
|
// leaves no temp directory behind.
|
||||||
func TestMaterializeSnapshotDBRemovesDirOnOpenFailure(t *testing.T) {
|
func TestMaterializeSnapshotDBRemovesDirOnOpenFailure(t *testing.T) {
|
||||||
|
|||||||
@@ -20,11 +20,7 @@ import (
|
|||||||
// the snapshot's db.zst.age with a stream cut right after the age header and
|
// the snapshot's db.zst.age with a stream cut right after the age header and
|
||||||
// its 16-byte nonce. age.Decrypt still accepts such an object and the zstd
|
// its 16-byte nonce. age.Decrypt still accepts such an object and the zstd
|
||||||
// decoder turns the truncated read into a clean EOF, so before the fix restore
|
// decoder turns the truncated read into a clean EOF, so before the fix restore
|
||||||
// built a fresh empty schema and reported success. Restore must now fail with
|
// built a fresh empty schema and reported success. Restore must now fail.
|
||||||
// io.ErrUnexpectedEOF, the error the reader raises for a truncated object.
|
|
||||||
// Asserting that specific error pins the reader fix: without it the truncation
|
|
||||||
// yields an empty database, which the identity check rejects for an unrelated
|
|
||||||
// reason, and this test would pass anyway.
|
|
||||||
func TestRestoreRejectsTruncatedMetadataDB(t *testing.T) {
|
func TestRestoreRejectsTruncatedMetadataDB(t *testing.T) {
|
||||||
log.Initialize(log.Config{})
|
log.Initialize(log.Config{})
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
@@ -81,5 +77,5 @@ func TestRestoreRejectsTruncatedMetadataDB(t *testing.T) {
|
|||||||
TargetDir: restoreDir,
|
TargetDir: restoreDir,
|
||||||
Verify: true,
|
Verify: true,
|
||||||
})
|
})
|
||||||
require.ErrorIs(t, err, io.ErrUnexpectedEOF)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user