From 0545ca131cec0f3bee0611d1e42e8bca4c5fea97 Mon Sep 17 00:00:00 2001 From: Alano Terblanche <18033717+Benehiko@users.noreply.github.com> Date: Mon, 2 Nov 2026 14:43:06 +0100 Subject: [PATCH] chore(store): drop x/testhelper from store tests Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com> --- store/go.mod | 4 +- store/go.sum | 5 + store/keychain/keychain_darwin_test.go | 46 +++--- store/posixage/store_test.go | 209 ++++++++++++------------- 4 files changed, 134 insertions(+), 130 deletions(-) diff --git a/store/go.mod b/store/go.mod index 4de09c2d..626cc8ae 100644 --- a/store/go.mod +++ b/store/go.mod @@ -13,7 +13,6 @@ require ( filippo.io/age v1.3.1 github.com/danieljoos/wincred v1.2.3 github.com/docker/secrets-engine/secrets v1.0.0 - github.com/docker/secrets-engine/x v0.8.5 github.com/godbus/dbus/v5 v5.1.0 github.com/stretchr/testify v1.11.1 golang.org/x/crypto v0.52.0 @@ -24,7 +23,8 @@ require ( filippo.io/edwards25519 v1.1.0 // indirect filippo.io/hpke v0.4.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/kr/text v0.2.0 // indirect + github.com/kr/pretty v0.3.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/store/go.sum b/store/go.sum index 3fd65a3f..2ed3f83b 100644 --- a/store/go.sum +++ b/store/go.sum @@ -13,12 +13,17 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= diff --git a/store/keychain/keychain_darwin_test.go b/store/keychain/keychain_darwin_test.go index 70240120..183c7e97 100644 --- a/store/keychain/keychain_darwin_test.go +++ b/store/keychain/keychain_darwin_test.go @@ -19,6 +19,7 @@ package keychain import ( "bytes" "context" + "crypto/rand" "testing" "github.com/stretchr/testify/assert" @@ -27,12 +28,11 @@ import ( "github.com/docker/secrets-engine/secrets" kc "github.com/docker/secrets-engine/store/keychain/internal/go-keychain" "github.com/docker/secrets-engine/store/mocks" - "github.com/docker/secrets-engine/x/testhelper" ) func TestMacosKeychain(t *testing.T) { var ( - serviceName = testhelper.RandomString() + serviceName = rand.Text() serviceGroup = "com.test.testing" ) keychainStore := keychainStore[*mocks.MockCredential]{ @@ -44,9 +44,9 @@ func TestMacosKeychain(t *testing.T) { } ids := []string{ - serviceGroup + "/" + serviceName + "/" + testhelper.RandomString(), - serviceGroup + "/" + serviceName + "/" + testhelper.RandomString(), - serviceGroup + "/" + serviceName + "/" + testhelper.RandomString(), + serviceGroup + "/" + serviceName + "/" + rand.Text(), + serviceGroup + "/" + serviceName + "/" + rand.Text(), + serviceGroup + "/" + serviceName + "/" + rand.Text(), } t.Cleanup(func() { for _, id := range ids { @@ -55,8 +55,8 @@ func TestMacosKeychain(t *testing.T) { }) for _, id := range ids { assert.NoError(t, keychainStore.Save(t.Context(), secrets.MustParseID(id), &mocks.MockCredential{ - Username: testhelper.RandomString(), - Password: testhelper.RandomString(), + Username: rand.Text(), + Password: rand.Text(), Attributes: map[string]string{ "color": "purple", "game": "unknown", @@ -65,10 +65,10 @@ func TestMacosKeychain(t *testing.T) { } t.Run("can store secret that has no attribute", func(t *testing.T) { - id := secrets.MustParseID(serviceGroup + "/" + serviceName + "/" + testhelper.RandomString()) + id := secrets.MustParseID(serviceGroup + "/" + serviceName + "/" + rand.Text()) secret := &mocks.MockCredential{ - Username: testhelper.RandomString(), + Username: rand.Text(), Password: "bob2", } t.Cleanup(func() { @@ -81,14 +81,14 @@ func TestMacosKeychain(t *testing.T) { }) t.Run("can store large attributes", func(t *testing.T) { - id := secrets.MustParseID(serviceGroup + "/" + serviceName + "/" + testhelper.RandomString()) + id := secrets.MustParseID(serviceGroup + "/" + serviceName + "/" + rand.Text()) t.Cleanup(func() { assert.NoError(t, keychainStore.Delete(t.Context(), id)) }) large := bytes.Repeat([]byte{'a'}, 1024*1024) secret := &mocks.MockCredential{ - Username: testhelper.RandomString(), + Username: rand.Text(), Password: "bob2", Attributes: map[string]string{ "large": string(large), @@ -103,13 +103,13 @@ func TestMacosKeychain(t *testing.T) { }) t.Run("filter populates both metadata and secret", func(t *testing.T) { - id := secrets.MustParseID(serviceGroup + "/" + serviceName + "/" + testhelper.RandomString()) + id := secrets.MustParseID(serviceGroup + "/" + serviceName + "/" + rand.Text()) t.Cleanup(func() { assert.NoError(t, keychainStore.Delete(t.Context(), id)) }) secret := &mocks.MockCredential{ - Username: testhelper.RandomString(), + Username: rand.Text(), Password: "bob2", Attributes: map[string]string{ "game": "elden ring", @@ -129,13 +129,13 @@ func TestMacosKeychain(t *testing.T) { }) t.Run("can use pattern only matching service name", func(t *testing.T) { - id := secrets.MustParseID(serviceGroup + "/" + serviceName + "/" + testhelper.RandomString()) + id := secrets.MustParseID(serviceGroup + "/" + serviceName + "/" + rand.Text()) t.Cleanup(func() { assert.NoError(t, keychainStore.Delete(t.Context(), id)) }) secret := &mocks.MockCredential{ - Username: testhelper.RandomString(), + Username: rand.Text(), Password: "bob2", Attributes: map[string]string{ "color": "blue", @@ -153,7 +153,7 @@ func TestMacosKeychain(t *testing.T) { func TestUpsert(t *testing.T) { var ( - serviceName = testhelper.RandomString() + serviceName = rand.Text() serviceGroup = "com.test.testing" ) ks := keychainStore[*mocks.MockCredential]{ @@ -165,7 +165,7 @@ func TestUpsert(t *testing.T) { } t.Run("inserts when credential does not exist", func(t *testing.T) { - id := secrets.MustParseID(serviceGroup + "/" + serviceName + "/" + testhelper.RandomString()) + id := secrets.MustParseID(serviceGroup + "/" + serviceName + "/" + rand.Text()) t.Cleanup(func() { assert.NoError(t, ks.Delete(t.Context(), id)) }) @@ -185,7 +185,7 @@ func TestUpsert(t *testing.T) { }) t.Run("overwrites an existing credential", func(t *testing.T) { - id := secrets.MustParseID(serviceGroup + "/" + serviceName + "/" + testhelper.RandomString()) + id := secrets.MustParseID(serviceGroup + "/" + serviceName + "/" + rand.Text()) t.Cleanup(func() { assert.NoError(t, ks.Delete(t.Context(), id)) }) @@ -211,7 +211,7 @@ func TestUpsert(t *testing.T) { }) t.Run("updates an existing credential in place", func(t *testing.T) { - id := secrets.MustParseID(serviceGroup + "/" + serviceName + "/" + testhelper.RandomString()) + id := secrets.MustParseID(serviceGroup + "/" + serviceName + "/" + rand.Text()) t.Cleanup(func() { assert.NoError(t, ks.Delete(t.Context(), id)) }) @@ -261,7 +261,7 @@ func TestUpsert(t *testing.T) { return &bufferSecret{} }, } - id := secrets.MustParseID(serviceGroup + "/" + serviceName + "/" + testhelper.RandomString()) + id := secrets.MustParseID(serviceGroup + "/" + serviceName + "/" + rand.Text()) t.Cleanup(func() { assert.NoError(t, bs.Delete(t.Context(), id)) }) @@ -281,7 +281,7 @@ func TestUpsert(t *testing.T) { return &bufferSecret{} }, } - id := secrets.MustParseID(serviceGroup + "/" + serviceName + "/" + testhelper.RandomString()) + id := secrets.MustParseID(serviceGroup + "/" + serviceName + "/" + rand.Text()) t.Cleanup(func() { assert.NoError(t, bs.Delete(t.Context(), id)) }) @@ -303,7 +303,7 @@ func TestUpsert(t *testing.T) { return &bufferSecret{} }, } - id := secrets.MustParseID(serviceGroup + "/" + serviceName + "/" + testhelper.RandomString()) + id := secrets.MustParseID(serviceGroup + "/" + serviceName + "/" + rand.Text()) t.Cleanup(func() { assert.NoError(t, bs.Delete(t.Context(), id)) }) @@ -316,7 +316,7 @@ func TestUpsert(t *testing.T) { }) t.Run("save returns duplicate item error when credential already exists", func(t *testing.T) { - id := secrets.MustParseID(serviceGroup + "/" + serviceName + "/" + testhelper.RandomString()) + id := secrets.MustParseID(serviceGroup + "/" + serviceName + "/" + rand.Text()) t.Cleanup(func() { assert.NoError(t, ks.Delete(t.Context(), id)) }) diff --git a/store/posixage/store_test.go b/store/posixage/store_test.go index 6c21f431..a0394a60 100644 --- a/store/posixage/store_test.go +++ b/store/posixage/store_test.go @@ -38,7 +38,6 @@ import ( "github.com/docker/secrets-engine/store/mocks" "github.com/docker/secrets-engine/store/posixage/internal/secretfile" - "github.com/docker/secrets-engine/x/testhelper" ) type testLogger struct { @@ -83,7 +82,7 @@ func TestPOSIXAge(t *testing.T) { assert.NoError(t, root.Close()) }) - masterKey := testhelper.RandomString() + masterKey := rand.Text() s, err := New(root, func(_ context.Context, _ secrets.ID) *mocks.MockCredential { return &mocks.MockCredential{} @@ -98,14 +97,14 @@ func TestPOSIXAge(t *testing.T) { ) require.NoError(t, err) secret := &mocks.MockCredential{ - Username: testhelper.RandomString(), - Password: testhelper.RandomString(), + Username: rand.Text(), + Password: rand.Text(), Attributes: map[string]string{ - "val1": testhelper.RandomString(), - "val2": testhelper.RandomString(), + "val1": rand.Text(), + "val2": rand.Text(), }, } - id := secrets.MustParseID("test/something/" + testhelper.RandomString()) + id := secrets.MustParseID("test/something/" + rand.Text()) require.NoError(t, s.Save(t.Context(), id, secret)) fsFiles, err := onlyDirs(root.FS()) @@ -156,7 +155,7 @@ func TestPOSIXAge(t *testing.T) { assert.NoError(t, root.Close()) }) - masterKey := testhelper.RandomString() + masterKey := rand.Text() s, err := New(root, func(_ context.Context, _ secrets.ID) *mocks.MockCredential { return &mocks.MockCredential{} @@ -171,14 +170,14 @@ func TestPOSIXAge(t *testing.T) { ) require.NoError(t, err) secret := &mocks.MockCredential{ - Username: testhelper.RandomString(), - Password: testhelper.RandomString(), + Username: rand.Text(), + Password: rand.Text(), Attributes: map[string]string{ - "val1": testhelper.RandomString(), - "val2": testhelper.RandomString(), + "val1": rand.Text(), + "val2": rand.Text(), }, } - id := secrets.MustParseID("test/something/" + testhelper.RandomString()) + id := secrets.MustParseID("test/something/" + rand.Text()) require.NoError(t, s.Save(t.Context(), id, secret)) storeSecret, err := s.Get(t.Context(), id) @@ -195,7 +194,7 @@ func TestPOSIXAge(t *testing.T) { assert.NoError(t, root.Close()) }) - masterKey := testhelper.RandomString() + masterKey := rand.Text() s, err := New(root, func(_ context.Context, _ secrets.ID) *mocks.MockCredential { return &mocks.MockCredential{} @@ -210,20 +209,20 @@ func TestPOSIXAge(t *testing.T) { ) require.NoError(t, err) results := map[secrets.ID]*mocks.MockCredential{ - secrets.MustParseID("something/secret1/" + testhelper.RandomString()): { - Username: testhelper.RandomString(), - Password: testhelper.RandomString(), + secrets.MustParseID("something/secret1/" + rand.Text()): { + Username: rand.Text(), + Password: rand.Text(), Attributes: map[string]string{ - "val1": testhelper.RandomString(), - "val2": testhelper.RandomString(), + "val1": rand.Text(), + "val2": rand.Text(), }, }, - secrets.MustParseID("something/secret2/" + testhelper.RandomString()): { - Username: testhelper.RandomString(), - Password: testhelper.RandomString(), + secrets.MustParseID("something/secret2/" + rand.Text()): { + Username: rand.Text(), + Password: rand.Text(), Attributes: map[string]string{ - "val3": testhelper.RandomString(), - "val4": testhelper.RandomString(), + "val3": rand.Text(), + "val4": rand.Text(), }, }, } @@ -253,7 +252,7 @@ func TestPOSIXAge(t *testing.T) { assert.NoError(t, root.Close()) }) - masterKey := testhelper.RandomString() + masterKey := rand.Text() s, err := New(root, func(_ context.Context, _ secrets.ID) *mocks.MockCredential { return &mocks.MockCredential{} @@ -268,24 +267,24 @@ func TestPOSIXAge(t *testing.T) { ) require.NoError(t, err) - secretOne := secrets.MustParseID("something/secret1/" + testhelper.RandomString()) - secretTwo := secrets.MustParseID("something2/secret2/" + testhelper.RandomString()) + secretOne := secrets.MustParseID("something/secret1/" + rand.Text()) + secretTwo := secrets.MustParseID("something2/secret2/" + rand.Text()) results := map[secrets.ID]*mocks.MockCredential{ secretOne: { - Username: testhelper.RandomString(), - Password: testhelper.RandomString(), + Username: rand.Text(), + Password: rand.Text(), Attributes: map[string]string{ - "val1": testhelper.RandomString(), - "val2": testhelper.RandomString(), + "val1": rand.Text(), + "val2": rand.Text(), }, }, secretTwo: { - Username: testhelper.RandomString(), - Password: testhelper.RandomString(), + Username: rand.Text(), + Password: rand.Text(), Attributes: map[string]string{ - "val3": testhelper.RandomString(), - "val4": testhelper.RandomString(), + "val3": rand.Text(), + "val4": rand.Text(), }, }, } @@ -305,7 +304,7 @@ func TestPOSIXAge(t *testing.T) { }) t.Run("filter on an empty store returns an empty map", func(t *testing.T) { - s := newPasswordStore(t, newTempRoot(t), testhelper.RandomString()) + s := newPasswordStore(t, newTempRoot(t), rand.Text()) storeSecrets, err := s.Filter(t.Context(), secrets.MustParsePattern("**")) require.NoError(t, err) @@ -314,10 +313,10 @@ func TestPOSIXAge(t *testing.T) { }) t.Run("filter with no matching secret returns an empty map", func(t *testing.T) { - s := newPasswordStore(t, newTempRoot(t), testhelper.RandomString()) + s := newPasswordStore(t, newTempRoot(t), rand.Text()) require.NoError(t, s.Save(t.Context(), secrets.MustParseID("something/secret1/bob"), &mocks.MockCredential{ - Username: testhelper.RandomString(), - Password: testhelper.RandomString(), + Username: rand.Text(), + Password: rand.Text(), })) storeSecrets, err := s.Filter(t.Context(), secrets.MustParsePattern("something/secret1/alice")) @@ -327,7 +326,7 @@ func TestPOSIXAge(t *testing.T) { }) t.Run("get all metadata on an empty store returns an empty map", func(t *testing.T) { - s := newPasswordStore(t, newTempRoot(t), testhelper.RandomString()) + s := newPasswordStore(t, newTempRoot(t), rand.Text()) storeSecrets, err := s.GetAllMetadata(t.Context()) require.NoError(t, err) @@ -342,7 +341,7 @@ func TestPOSIXAge(t *testing.T) { assert.NoError(t, root.Close()) }) - masterKey := testhelper.RandomString() + masterKey := rand.Text() identity, err := age.GenerateX25519Identity() require.NoError(t, err) @@ -366,14 +365,14 @@ func TestPOSIXAge(t *testing.T) { ) require.NoError(t, err) secret := &mocks.MockCredential{ - Username: testhelper.RandomString(), - Password: testhelper.RandomString(), + Username: rand.Text(), + Password: rand.Text(), Attributes: map[string]string{ - "val1": testhelper.RandomString(), - "val2": testhelper.RandomString(), + "val1": rand.Text(), + "val2": rand.Text(), }, } - id := secrets.MustParseID("test/something/" + testhelper.RandomString()) + id := secrets.MustParseID("test/something/" + rand.Text()) require.NoError(t, s.Save(t.Context(), id, secret)) fsFiles, err := onlyDirs(root.FS()) @@ -425,7 +424,7 @@ func TestPOSIXAge(t *testing.T) { assert.NoError(t, root.Close()) }) - masterKey := testhelper.RandomString() + masterKey := rand.Text() identity, err := age.GenerateX25519Identity() require.NoError(t, err) @@ -449,14 +448,14 @@ func TestPOSIXAge(t *testing.T) { ) require.NoError(t, err) secret := &mocks.MockCredential{ - Username: testhelper.RandomString(), - Password: testhelper.RandomString(), + Username: rand.Text(), + Password: rand.Text(), Attributes: map[string]string{ - "val1": testhelper.RandomString(), - "val2": testhelper.RandomString(), + "val1": rand.Text(), + "val2": rand.Text(), }, } - id := secrets.MustParseID("test/something/" + testhelper.RandomString()) + id := secrets.MustParseID("test/something/" + rand.Text()) require.NoError(t, s.Save(t.Context(), id, secret)) fsFiles, err := onlyDirs(root.FS()) @@ -494,7 +493,7 @@ func TestPOSIXAge(t *testing.T) { assert.NoError(t, root.Close()) }) - masterKey := testhelper.RandomString() + masterKey := rand.Text() identity, err := age.GenerateX25519Identity() require.NoError(t, err) @@ -528,14 +527,14 @@ func TestPOSIXAge(t *testing.T) { ) require.NoError(t, err) secret := &mocks.MockCredential{ - Username: testhelper.RandomString(), - Password: testhelper.RandomString(), + Username: rand.Text(), + Password: rand.Text(), Attributes: map[string]string{ - "val1": testhelper.RandomString(), - "val2": testhelper.RandomString(), + "val1": rand.Text(), + "val2": rand.Text(), }, } - id := secrets.MustParseID("test/something/" + testhelper.RandomString()) + id := secrets.MustParseID("test/something/" + rand.Text()) require.NoError(t, s.Save(t.Context(), id, secret)) x := s.(*fileStore[*mocks.MockCredential]) @@ -565,7 +564,7 @@ func TestPOSIXAge(t *testing.T) { assert.NoError(t, root.Close()) }) - masterKey := testhelper.RandomString() + masterKey := rand.Text() identity, err := age.GenerateX25519Identity() require.NoError(t, err) @@ -611,14 +610,14 @@ func TestPOSIXAge(t *testing.T) { ) require.NoError(t, err) secret := &mocks.MockCredential{ - Username: testhelper.RandomString(), - Password: testhelper.RandomString(), + Username: rand.Text(), + Password: rand.Text(), Attributes: map[string]string{ - "val1": testhelper.RandomString(), - "val2": testhelper.RandomString(), + "val1": rand.Text(), + "val2": rand.Text(), }, } - id := secrets.MustParseID("test/something/" + testhelper.RandomString()) + id := secrets.MustParseID("test/something/" + rand.Text()) require.NoError(t, s.Save(t.Context(), id, secret)) storeSecret, err := s.Get(t.Context(), id) @@ -633,7 +632,7 @@ func TestPOSIXAge(t *testing.T) { assert.NoError(t, root.Close()) }) - masterKey := testhelper.RandomString() + masterKey := rand.Text() identity, err := age.GenerateX25519Identity() require.NoError(t, err) @@ -673,14 +672,14 @@ func TestPOSIXAge(t *testing.T) { ) require.NoError(t, err) secret := &mocks.MockCredential{ - Username: testhelper.RandomString(), - Password: testhelper.RandomString(), + Username: rand.Text(), + Password: rand.Text(), Attributes: map[string]string{ - "val1": testhelper.RandomString(), - "val2": testhelper.RandomString(), + "val1": rand.Text(), + "val2": rand.Text(), }, } - id := secrets.MustParseID("test/something/" + testhelper.RandomString()) + id := secrets.MustParseID("test/something/" + rand.Text()) require.NoError(t, s.Save(t.Context(), id, secret)) storeSecret, err := s.Get(t.Context(), id) @@ -695,7 +694,7 @@ func TestPOSIXAge(t *testing.T) { assert.NoError(t, root.Close()) }) - masterKey := testhelper.RandomString() + masterKey := rand.Text() s, err := New(root, func(_ context.Context, _ secrets.ID) *mocks.MockCredential { return &mocks.MockCredential{} @@ -711,10 +710,10 @@ func TestPOSIXAge(t *testing.T) { require.NoError(t, err) secret := &mocks.MockCredential{ - Username: testhelper.RandomString(), - Password: testhelper.RandomString(), + Username: rand.Text(), + Password: rand.Text(), } - id := secrets.MustParseID("test/something/" + testhelper.RandomString()) + id := secrets.MustParseID("test/something/" + rand.Text()) require.NoError(t, s.Upsert(t.Context(), id, secret)) storeSecret, err := s.Get(t.Context(), id) @@ -729,7 +728,7 @@ func TestPOSIXAge(t *testing.T) { assert.NoError(t, root.Close()) }) - masterKey := testhelper.RandomString() + masterKey := rand.Text() s, err := New(root, func(_ context.Context, _ secrets.ID) *mocks.MockCredential { return &mocks.MockCredential{} @@ -745,15 +744,15 @@ func TestPOSIXAge(t *testing.T) { require.NoError(t, err) original := &mocks.MockCredential{ - Username: testhelper.RandomString(), - Password: testhelper.RandomString(), + Username: rand.Text(), + Password: rand.Text(), } - id := secrets.MustParseID("test/something/" + testhelper.RandomString()) + id := secrets.MustParseID("test/something/" + rand.Text()) require.NoError(t, s.Save(t.Context(), id, original)) updated := &mocks.MockCredential{ - Username: testhelper.RandomString(), - Password: testhelper.RandomString(), + Username: rand.Text(), + Password: rand.Text(), } require.NoError(t, s.Upsert(t.Context(), id, updated)) @@ -784,14 +783,14 @@ func TestPOSIXAge(t *testing.T) { ) require.NoError(t, err) secret := &mocks.MockCredential{ - Username: testhelper.RandomString(), - Password: testhelper.RandomString(), + Username: rand.Text(), + Password: rand.Text(), Attributes: map[string]string{ - "val1": testhelper.RandomString(), - "val2": testhelper.RandomString(), + "val1": rand.Text(), + "val2": rand.Text(), }, } - id := secrets.MustParseID("test/something/" + testhelper.RandomString()) + id := secrets.MustParseID("test/something/" + rand.Text()) assert.ErrorIs(t, s.Save(t.Context(), id, secret), encryptError) }) @@ -817,14 +816,14 @@ func TestPOSIXAge(t *testing.T) { ) require.NoError(t, err) secret := &mocks.MockCredential{ - Username: testhelper.RandomString(), - Password: testhelper.RandomString(), + Username: rand.Text(), + Password: rand.Text(), Attributes: map[string]string{ - "val1": testhelper.RandomString(), - "val2": testhelper.RandomString(), + "val1": rand.Text(), + "val2": rand.Text(), }, } - id := secrets.MustParseID("test/something/" + testhelper.RandomString()) + id := secrets.MustParseID("test/something/" + rand.Text()) require.NoError(t, s.Save(t.Context(), id, secret)) _, err = s.Get(t.Context(), id) @@ -905,12 +904,12 @@ func TestScryptWorkFactor(t *testing.T) { const workFactor = 10 t.Run("records the configured work factor in the header", func(t *testing.T) { - password := testhelper.RandomString() + password := rand.Text() root := newTempRoot(t) s := newPasswordStore(t, root, password, WithScryptWorkFactor(workFactor)) - secret := &mocks.MockCredential{Username: testhelper.RandomString(), Password: testhelper.RandomString()} - id := secrets.MustParseID("test/something/" + testhelper.RandomString()) + secret := &mocks.MockCredential{Username: rand.Text(), Password: rand.Text()} + id := secrets.MustParseID("test/something/" + rand.Text()) require.NoError(t, s.Save(t.Context(), id, secret)) encryptedFile := readPassSecret(t, root, id) @@ -923,12 +922,12 @@ func TestScryptWorkFactor(t *testing.T) { }) t.Run("defaults to the age work factor when unset", func(t *testing.T) { - password := testhelper.RandomString() + password := rand.Text() root := newTempRoot(t) s := newPasswordStore(t, root, password) - secret := &mocks.MockCredential{Username: testhelper.RandomString(), Password: testhelper.RandomString()} - id := secrets.MustParseID("test/something/" + testhelper.RandomString()) + secret := &mocks.MockCredential{Username: rand.Text(), Password: rand.Text()} + id := secrets.MustParseID("test/something/" + rand.Text()) require.NoError(t, s.Save(t.Context(), id, secret)) encryptedFile := readPassSecret(t, root, id) @@ -940,12 +939,12 @@ func TestScryptWorkFactor(t *testing.T) { // A file written with a custom work factor must decrypt on a store that // has no work-factor option configured: the factor is read from the // header, not from store configuration. - password := testhelper.RandomString() + password := rand.Text() root := newTempRoot(t) writer := newPasswordStore(t, root, password, WithScryptWorkFactor(workFactor)) - secret := &mocks.MockCredential{Username: testhelper.RandomString(), Password: testhelper.RandomString()} - id := secrets.MustParseID("test/something/" + testhelper.RandomString()) + secret := &mocks.MockCredential{Username: rand.Text(), Password: rand.Text()} + id := secrets.MustParseID("test/something/" + rand.Text()) require.NoError(t, writer.Save(t.Context(), id, secret)) // A separate store with no work-factor option configured. @@ -983,17 +982,17 @@ func TestScryptWorkFactor(t *testing.T) { // configured for a different work factor migrates the stored file to that // factor while preserving the plaintext. The factor moves in both directions. func TestScryptWorkFactorMigration(t *testing.T) { - password := testhelper.RandomString() + password := rand.Text() root := newTempRoot(t) secret := &mocks.MockCredential{ - Username: testhelper.RandomString(), - Password: testhelper.RandomString(), + Username: rand.Text(), + Password: rand.Text(), Attributes: map[string]string{ - "val1": testhelper.RandomString(), + "val1": rand.Text(), }, } - id := secrets.MustParseID("test/something/" + testhelper.RandomString()) + id := secrets.MustParseID("test/something/" + rand.Text()) // Seed the secret with the age default (logN=18), simulating data written // by a build that never configured a work factor. @@ -1064,7 +1063,7 @@ func TestSaveRejectsEmptySecret(t *testing.T) { }), ) require.NoError(t, err) - id := secrets.MustParseID("test/something/" + testhelper.RandomString()) + id := secrets.MustParseID("test/something/" + rand.Text()) for _, secret := range []secrets.Secret{&emptySecret{}, &emptySecret{value: []byte{}}} { require.ErrorIs(t, s.Save(t.Context(), id, secret), secrets.ErrEmptySecret)