Use low-security scrypt KDF parameters for testing

This commit is contained in:
Alexander Neumann 2016-08-21 13:42:04 +02:00
parent 8e24c51233
commit a3492d69dd
3 changed files with 21 additions and 1 deletions

View file

@ -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))

View file

@ -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))

View file

@ -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)