diff --git a/container/test/generate.go b/container/test/generate.go index b94347b..23ad3a1 100644 --- a/container/test/generate.go +++ b/container/test/generate.go @@ -1,6 +1,8 @@ package containertest import ( + "crypto/rand" + acltest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/test" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container" netmaptest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/test" @@ -36,8 +38,11 @@ func GenerateContainer(empty bool) *container.Container { m := new(container.Container) if !empty { + nonce := make([]byte, 16) + _, _ = rand.Read(nonce) + m.SetBasicACL(12) - m.SetNonce([]byte{1, 2, 3}) + m.SetNonce(nonce) m.SetOwnerID(refstest.GenerateOwnerID(false)) m.SetAttributes(GenerateAttributes(false)) m.SetPlacementPolicy(netmaptest.GeneratePlacementPolicy(false)) diff --git a/object/test/generate.go b/object/test/generate.go index 87ad64e..7b649f9 100644 --- a/object/test/generate.go +++ b/object/test/generate.go @@ -4,6 +4,8 @@ import ( "math/rand" "time" + crand "crypto/rand" + "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test" @@ -59,7 +61,10 @@ func generateSplitHeader(empty, withPar bool) *object.SplitHeader { m := new(object.SplitHeader) if !empty { - m.SetSplitID([]byte{1, 3, 5}) + id := make([]byte, 16) + _, _ = crand.Read(id) + + m.SetSplitID(id) m.SetParent(refstest.GenerateObjectID(false)) m.SetPrevious(refstest.GenerateObjectID(false)) m.SetChildren(refstest.GenerateObjectIDs(false)) @@ -91,7 +96,10 @@ func GenerateECHeader(empty bool) *object.ECHeader { if !empty { ech.Parent = refstest.GenerateObjectID(empty) - ech.ParentSplitID = []byte{1, 2, 3} + + ech.ParentSplitID = make([]byte, 16) + _, _ = crand.Read(ech.ParentSplitID) + ech.ParentSplitParentID = refstest.GenerateObjectID(empty) ech.ParentAttributes = GenerateAttributes(empty) ech.Index = 0 @@ -150,7 +158,10 @@ func GenerateSplitInfo(empty bool) *object.SplitInfo { m := new(object.SplitInfo) if !empty { - m.SetSplitID([]byte("splitID")) + id := make([]byte, 16) + _, _ = crand.Read(id) + + m.SetSplitID(id) m.SetLastPart(refstest.GenerateObjectID(false)) m.SetLink(refstest.GenerateObjectID(false)) } @@ -627,7 +638,10 @@ func GenerateGetRangeHashResponseBody(empty bool) *object.GetRangeHashResponseBo if !empty { m.SetType(678) - m.SetHashList([][]byte{{1}, {2}}) + m.SetHashList([][]byte{ + refstest.GenerateChecksum(false).GetSum(), + refstest.GenerateChecksum(false).GetSum(), + }) } return m diff --git a/refs/test/generate.go b/refs/test/generate.go index 6217a96..49619ef 100644 --- a/refs/test/generate.go +++ b/refs/test/generate.go @@ -1,7 +1,8 @@ package refstest import ( - "math/rand" + crand "crypto/rand" + "crypto/sha256" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" ) @@ -21,7 +22,10 @@ func GenerateOwnerID(empty bool) *refs.OwnerID { m := new(refs.OwnerID) if !empty { - m.SetValue([]byte{1, 2, 3}) + id := make([]byte, 25) + _, _ = crand.Read(id) + + m.SetValue(id) } return m @@ -42,7 +46,10 @@ func GenerateObjectID(empty bool) *refs.ObjectID { m := new(refs.ObjectID) if !empty { - m.SetValue([]byte{1, 2, 3}) + id := make([]byte, sha256.Size) + _, _ = crand.Read(id) + + m.SetValue(id) } return m @@ -65,7 +72,10 @@ func GenerateContainerID(empty bool) *refs.ContainerID { m := new(refs.ContainerID) if !empty { - m.SetValue([]byte{1, 2, 3}) + id := make([]byte, sha256.Size) + _, _ = crand.Read(id) + + m.SetValue(id) } return m @@ -88,9 +98,15 @@ func GenerateSignature(empty bool) *refs.Signature { m := new(refs.Signature) if !empty { - m.SetKey([]byte{1}) - m.SetSign([]byte{2}) - m.SetScheme(refs.SignatureScheme(rand.Int31() % 3)) + key := make([]byte, 33) + _, _ = crand.Read(key) + + sign := make([]byte, 65) + _, _ = crand.Read(sign) + + m.SetScheme(refs.ECDSA_SHA512) + m.SetKey(key) + m.SetSign(sign) } return m @@ -100,8 +116,11 @@ func GenerateChecksum(empty bool) *refs.Checksum { m := new(refs.Checksum) if !empty { - m.SetType(1) - m.SetSum([]byte{1, 2, 3}) + cs := make([]byte, sha256.Size) + _, _ = crand.Read(cs) + + m.SetType(refs.SHA256) + m.SetSum(cs) } return m diff --git a/session/test/generate.go b/session/test/generate.go index 561ec01..237eca5 100644 --- a/session/test/generate.go +++ b/session/test/generate.go @@ -4,6 +4,8 @@ import ( "math/rand" "time" + crand "crypto/rand" + acltest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/test" refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session" @@ -38,7 +40,10 @@ func GenerateCreateResponseBody(empty bool) *session.CreateResponseBody { m := new(session.CreateResponseBody) if !empty { - m.SetID([]byte{1, 2, 3}) + id := make([]byte, 16) + _, _ = crand.Read(id) + + m.SetID(id) m.SetSessionKey([]byte{4, 5, 6}) } @@ -164,7 +169,10 @@ func GenerateSessionTokenBody(empty bool) *session.TokenBody { m := new(session.TokenBody) if !empty { - m.SetID([]byte{1}) + id := make([]byte, 16) + _, _ = crand.Read(id) + + m.SetID(id) m.SetSessionKey([]byte{2}) m.SetOwnerID(refstest.GenerateOwnerID(false)) m.SetLifetime(GenerateTokenLifetime(false)) diff --git a/tombstone/test/generate.go b/tombstone/test/generate.go index 3caf528..1fab9eb 100644 --- a/tombstone/test/generate.go +++ b/tombstone/test/generate.go @@ -1,6 +1,8 @@ package tombstonetest import ( + "crypto/rand" + refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/tombstone" ) @@ -9,8 +11,11 @@ func GenerateTombstone(empty bool) *tombstone.Tombstone { m := new(tombstone.Tombstone) if !empty { + id := make([]byte, 16) + _, _ = rand.Read(id) + m.SetExpirationEpoch(89) - m.SetSplitID([]byte{3, 2, 1}) + m.SetSplitID(id) m.SetMembers(refstest.GenerateObjectIDs(false)) }