From a3492d69dd629953c5751895da682c98512a450e Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 21 Aug 2016 13:42:04 +0200 Subject: [PATCH] Use low-security scrypt KDF parameters for testing --- src/cmds/restic/integration_test.go | 2 ++ src/restic/checker/checker_test.go | 2 ++ src/restic/repository/testing.go | 18 +++++++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/cmds/restic/integration_test.go b/src/cmds/restic/integration_test.go index 94992104f..4b99d8a32 100644 --- a/src/cmds/restic/integration_test.go +++ b/src/cmds/restic/integration_test.go @@ -40,6 +40,8 @@ func parseIDsFromReader(t testing.TB, rd io.Reader) backend.IDs { } func cmdInit(t testing.TB, global GlobalOptions) { + repository.TestUseLowSecurityKDFParameters(t) + cmd := &CmdInit{global: &global} OK(t, cmd.Execute(nil)) diff --git a/src/restic/checker/checker_test.go b/src/restic/checker/checker_test.go index 3448dafbc..d06b2139b 100644 --- a/src/restic/checker/checker_test.go +++ b/src/restic/checker/checker_test.go @@ -239,6 +239,8 @@ func induceError(data []byte) { func TestCheckerModifiedData(t *testing.T) { be := mem.New() + repository.TestUseLowSecurityKDFParameters(t) + repo := repository.New(be) OK(t, repo.Init(TestPassword)) diff --git a/src/restic/repository/testing.go b/src/restic/repository/testing.go index f0a9913f1..904ee397c 100644 --- a/src/restic/repository/testing.go +++ b/src/restic/repository/testing.go @@ -5,11 +5,25 @@ import ( "restic/backend" "restic/backend/local" "restic/backend/mem" + "restic/crypto" "testing" "github.com/restic/chunker" ) +// testKDFParams are the parameters for the KDF to be used during testing. +var testKDFParams = crypto.KDFParams{ + N: 128, + R: 1, + P: 1, +} + +// TestUseLowSecurityKDFParameters configures low-security KDF parameters for testing. +func TestUseLowSecurityKDFParameters(t testing.TB) { + t.Logf("using low-security KDF parameters for test") + KDFParams = &testKDFParams +} + // TestBackend returns a fully configured in-memory backend. func TestBackend(t testing.TB) (be backend.Backend, cleanup func()) { return mem.New(), func() {} @@ -22,8 +36,10 @@ const testChunkerPol = chunker.Pol(0x3DA3358B4DC173) // TestRepositoryWithBackend returns a repository initialized with a test // password. If be is nil, an in-memory backend is used. A constant polynomial -// is used for the chunker. +// is used for the chunker and low-security test parameters. func TestRepositoryWithBackend(t testing.TB, be backend.Backend) (r *Repository, cleanup func()) { + TestUseLowSecurityKDFParameters(t) + var beCleanup func() if be == nil { be, beCleanup = TestBackend(t)