mirror of
https://github.com/octoleo/restic.git
synced 2024-11-22 04:45:15 +00:00
repository: Allow skipping verification for tests
Some tests have to explicitly create pack files with blobs that don't match their ID. For those blobs the builtin verification of the repository must be disabled.
This commit is contained in:
parent
30a84e9003
commit
2dbb18128c
@ -336,7 +336,8 @@ func TestRepackWrongBlob(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testRepackWrongBlob(t *testing.T, version uint) {
|
func testRepackWrongBlob(t *testing.T, version uint) {
|
||||||
repo := repository.TestRepositoryWithVersion(t, version)
|
// disable verification to allow adding corrupted blobs to the repository
|
||||||
|
repo := repository.TestRepositoryWithBackend(t, nil, version, repository.Options{NoVerifyPack: true})
|
||||||
|
|
||||||
seed := time.Now().UnixNano()
|
seed := time.Now().UnixNano()
|
||||||
rand.Seed(seed)
|
rand.Seed(seed)
|
||||||
@ -361,7 +362,8 @@ func TestRepackBlobFallback(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testRepackBlobFallback(t *testing.T, version uint) {
|
func testRepackBlobFallback(t *testing.T, version uint) {
|
||||||
repo := repository.TestRepositoryWithVersion(t, version)
|
// disable verification to allow adding corrupted blobs to the repository
|
||||||
|
repo := repository.TestRepositoryWithBackend(t, nil, version, repository.Options{NoVerifyPack: true})
|
||||||
|
|
||||||
seed := time.Now().UnixNano()
|
seed := time.Now().UnixNano()
|
||||||
rand.Seed(seed)
|
rand.Seed(seed)
|
||||||
|
@ -102,7 +102,8 @@ func testRepairBrokenPack(t *testing.T, version uint) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
repo := repository.TestRepositoryWithVersion(t, version)
|
// disable verification to allow adding corrupted blobs to the repository
|
||||||
|
repo := repository.TestRepositoryWithBackend(t, nil, version, repository.Options{NoVerifyPack: true})
|
||||||
|
|
||||||
seed := time.Now().UnixNano()
|
seed := time.Now().UnixNano()
|
||||||
rand.Seed(seed)
|
rand.Seed(seed)
|
||||||
|
@ -61,6 +61,7 @@ type Repository struct {
|
|||||||
type Options struct {
|
type Options struct {
|
||||||
Compression CompressionMode
|
Compression CompressionMode
|
||||||
PackSize uint
|
PackSize uint
|
||||||
|
NoVerifyPack bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// CompressionMode configures if data should be compressed.
|
// CompressionMode configures if data should be compressed.
|
||||||
@ -444,6 +445,10 @@ func (r *Repository) saveAndEncrypt(ctx context.Context, t restic.BlobType, data
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repository) verifyCiphertext(buf []byte, uncompressedLength int, id restic.ID) error {
|
func (r *Repository) verifyCiphertext(buf []byte, uncompressedLength int, id restic.ID) error {
|
||||||
|
if r.opts.NoVerifyPack {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
nonce, ciphertext := buf[:r.key.NonceSize()], buf[r.key.NonceSize():]
|
nonce, ciphertext := buf[:r.key.NonceSize()], buf[r.key.NonceSize():]
|
||||||
plaintext, err := r.key.Open(nil, nonce, ciphertext, nil)
|
plaintext, err := r.key.Open(nil, nonce, ciphertext, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -539,6 +544,10 @@ func (r *Repository) SaveUnpacked(ctx context.Context, t restic.FileType, buf []
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repository) verifyUnpacked(buf []byte, t restic.FileType, expected []byte) error {
|
func (r *Repository) verifyUnpacked(buf []byte, t restic.FileType, expected []byte) error {
|
||||||
|
if r.opts.NoVerifyPack {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
nonce, ciphertext := buf[:r.key.NonceSize()], buf[r.key.NonceSize():]
|
nonce, ciphertext := buf[:r.key.NonceSize()], buf[r.key.NonceSize():]
|
||||||
plaintext, err := r.key.Open(nil, nonce, ciphertext, nil)
|
plaintext, err := r.key.Open(nil, nonce, ciphertext, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user