From c67a8452f790b684efb146bbcd47e12674237969 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 11 Mar 2018 20:59:40 +0100 Subject: [PATCH] Disable polynomial check for chunker for tests --- cmd/restic/integration_helpers_test.go | 2 ++ cmd/restic/integration_test.go | 1 + internal/restic/config.go | 15 +++++++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/cmd/restic/integration_helpers_test.go b/cmd/restic/integration_helpers_test.go index 2fb026512..d0450817d 100644 --- a/cmd/restic/integration_helpers_test.go +++ b/cmd/restic/integration_helpers_test.go @@ -11,6 +11,7 @@ import ( "github.com/restic/restic/internal/options" "github.com/restic/restic/internal/repository" + "github.com/restic/restic/internal/restic" rtest "github.com/restic/restic/internal/test" ) @@ -189,6 +190,7 @@ func withTestEnvironment(t testing.TB) (env *testEnvironment, cleanup func()) { } repository.TestUseLowSecurityKDFParameters(t) + restic.TestDisableCheckPolynomial(t) tempdir, err := ioutil.TempDir(rtest.TestTempDir, "restic-test-") rtest.OK(t, err) diff --git a/cmd/restic/integration_test.go b/cmd/restic/integration_test.go index dbc48703e..3392ab0d0 100644 --- a/cmd/restic/integration_test.go +++ b/cmd/restic/integration_test.go @@ -44,6 +44,7 @@ func parseIDsFromReader(t testing.TB, rd io.Reader) restic.IDs { func testRunInit(t testing.TB, opts GlobalOptions) { repository.TestUseLowSecurityKDFParameters(t) + restic.TestDisableCheckPolynomial(t) restic.TestSetLockTimeout(t, 0) rtest.OK(t, runInit(opts, nil)) diff --git a/internal/restic/config.go b/internal/restic/config.go index a11bf5409..4f3c6c4bc 100644 --- a/internal/restic/config.go +++ b/internal/restic/config.go @@ -57,6 +57,15 @@ func TestCreateConfig(t testing.TB, pol chunker.Pol) (cfg Config) { return cfg } +var checkPolynomial = true + +// TestDisableCheckPolynomial disables the check that the polynomial used for +// the chunker. +func TestDisableCheckPolynomial(t testing.TB) { + t.Logf("disabling check of the chunker polynomial") + checkPolynomial = false +} + // LoadConfig returns loads, checks and returns the config for a repository. func LoadConfig(ctx context.Context, r JSONUnpackedLoader) (Config, error) { var ( @@ -72,8 +81,10 @@ func LoadConfig(ctx context.Context, r JSONUnpackedLoader) (Config, error) { return Config{}, errors.New("unsupported repository version") } - if !cfg.ChunkerPolynomial.Irreducible() { - return Config{}, errors.New("invalid chunker polynomial") + if checkPolynomial { + if !cfg.ChunkerPolynomial.Irreducible() { + return Config{}, errors.New("invalid chunker polynomial") + } } return cfg, nil