[#106] test: Generate correct data for tests

Some tests are using invalid data that do not meet the requirements of the
FrostFS protocol, e.g.
- Container/Object IDs aren't 32 bytes long
- Signature key and sign have invalid length
- Split IDs aren't valid UUIDv4
and etc.

Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
This commit is contained in:
Aleksey Savchuk 2024-08-26 14:13:20 +03:00
parent 5e1c6a908f
commit 9c5e32a183
No known key found for this signature in database
5 changed files with 66 additions and 17 deletions

View file

@ -1,6 +1,8 @@
package containertest package containertest
import ( import (
"crypto/rand"
acltest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/test" acltest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/test"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container"
netmaptest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/test" 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) m := new(container.Container)
if !empty { if !empty {
nonce := make([]byte, 16)
_, _ = rand.Read(nonce)
m.SetBasicACL(12) m.SetBasicACL(12)
m.SetNonce([]byte{1, 2, 3}) m.SetNonce(nonce)
m.SetOwnerID(refstest.GenerateOwnerID(false)) m.SetOwnerID(refstest.GenerateOwnerID(false))
m.SetAttributes(GenerateAttributes(false)) m.SetAttributes(GenerateAttributes(false))
m.SetPlacementPolicy(netmaptest.GeneratePlacementPolicy(false)) m.SetPlacementPolicy(netmaptest.GeneratePlacementPolicy(false))

View file

@ -1,6 +1,7 @@
package objecttest package objecttest
import ( import (
crand "crypto/rand"
"math/rand" "math/rand"
"time" "time"
@ -59,7 +60,10 @@ func generateSplitHeader(empty, withPar bool) *object.SplitHeader {
m := new(object.SplitHeader) m := new(object.SplitHeader)
if !empty { if !empty {
m.SetSplitID([]byte{1, 3, 5}) id := make([]byte, 16)
_, _ = crand.Read(id)
m.SetSplitID(id)
m.SetParent(refstest.GenerateObjectID(false)) m.SetParent(refstest.GenerateObjectID(false))
m.SetPrevious(refstest.GenerateObjectID(false)) m.SetPrevious(refstest.GenerateObjectID(false))
m.SetChildren(refstest.GenerateObjectIDs(false)) m.SetChildren(refstest.GenerateObjectIDs(false))
@ -91,7 +95,10 @@ func GenerateECHeader(empty bool) *object.ECHeader {
if !empty { if !empty {
ech.Parent = refstest.GenerateObjectID(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.ParentSplitParentID = refstest.GenerateObjectID(empty)
ech.ParentAttributes = GenerateAttributes(empty) ech.ParentAttributes = GenerateAttributes(empty)
ech.Index = 0 ech.Index = 0
@ -150,7 +157,10 @@ func GenerateSplitInfo(empty bool) *object.SplitInfo {
m := new(object.SplitInfo) m := new(object.SplitInfo)
if !empty { if !empty {
m.SetSplitID([]byte("splitID")) id := make([]byte, 16)
_, _ = crand.Read(id)
m.SetSplitID(id)
m.SetLastPart(refstest.GenerateObjectID(false)) m.SetLastPart(refstest.GenerateObjectID(false))
m.SetLink(refstest.GenerateObjectID(false)) m.SetLink(refstest.GenerateObjectID(false))
} }
@ -627,7 +637,10 @@ func GenerateGetRangeHashResponseBody(empty bool) *object.GetRangeHashResponseBo
if !empty { if !empty {
m.SetType(678) m.SetType(678)
m.SetHashList([][]byte{{1}, {2}}) m.SetHashList([][]byte{
refstest.GenerateChecksum(false).GetSum(),
refstest.GenerateChecksum(false).GetSum(),
})
} }
return m return m

View file

@ -1,7 +1,8 @@
package refstest package refstest
import ( import (
"math/rand" crand "crypto/rand"
"crypto/sha256"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
) )
@ -21,7 +22,10 @@ func GenerateOwnerID(empty bool) *refs.OwnerID {
m := new(refs.OwnerID) m := new(refs.OwnerID)
if !empty { if !empty {
m.SetValue([]byte{1, 2, 3}) id := make([]byte, 25)
_, _ = crand.Read(id)
m.SetValue(id)
} }
return m return m
@ -42,7 +46,10 @@ func GenerateObjectID(empty bool) *refs.ObjectID {
m := new(refs.ObjectID) m := new(refs.ObjectID)
if !empty { if !empty {
m.SetValue([]byte{1, 2, 3}) id := make([]byte, sha256.Size)
_, _ = crand.Read(id)
m.SetValue(id)
} }
return m return m
@ -65,7 +72,10 @@ func GenerateContainerID(empty bool) *refs.ContainerID {
m := new(refs.ContainerID) m := new(refs.ContainerID)
if !empty { if !empty {
m.SetValue([]byte{1, 2, 3}) id := make([]byte, sha256.Size)
_, _ = crand.Read(id)
m.SetValue(id)
} }
return m return m
@ -88,9 +98,15 @@ func GenerateSignature(empty bool) *refs.Signature {
m := new(refs.Signature) m := new(refs.Signature)
if !empty { if !empty {
m.SetKey([]byte{1}) key := make([]byte, 33)
m.SetSign([]byte{2}) _, _ = crand.Read(key)
m.SetScheme(refs.SignatureScheme(rand.Int31() % 3))
sign := make([]byte, 65)
_, _ = crand.Read(sign)
m.SetScheme(refs.ECDSA_SHA512)
m.SetKey(key)
m.SetSign(sign)
} }
return m return m
@ -100,8 +116,11 @@ func GenerateChecksum(empty bool) *refs.Checksum {
m := new(refs.Checksum) m := new(refs.Checksum)
if !empty { if !empty {
m.SetType(1) cs := make([]byte, sha256.Size)
m.SetSum([]byte{1, 2, 3}) _, _ = crand.Read(cs)
m.SetType(refs.SHA256)
m.SetSum(cs)
} }
return m return m

View file

@ -1,6 +1,7 @@
package sessiontest package sessiontest
import ( import (
crand "crypto/rand"
"math/rand" "math/rand"
"time" "time"
@ -38,7 +39,10 @@ func GenerateCreateResponseBody(empty bool) *session.CreateResponseBody {
m := new(session.CreateResponseBody) m := new(session.CreateResponseBody)
if !empty { if !empty {
m.SetID([]byte{1, 2, 3}) id := make([]byte, 16)
_, _ = crand.Read(id)
m.SetID(id)
m.SetSessionKey([]byte{4, 5, 6}) m.SetSessionKey([]byte{4, 5, 6})
} }
@ -164,7 +168,10 @@ func GenerateSessionTokenBody(empty bool) *session.TokenBody {
m := new(session.TokenBody) m := new(session.TokenBody)
if !empty { if !empty {
m.SetID([]byte{1}) id := make([]byte, 16)
_, _ = crand.Read(id)
m.SetID(id)
m.SetSessionKey([]byte{2}) m.SetSessionKey([]byte{2})
m.SetOwnerID(refstest.GenerateOwnerID(false)) m.SetOwnerID(refstest.GenerateOwnerID(false))
m.SetLifetime(GenerateTokenLifetime(false)) m.SetLifetime(GenerateTokenLifetime(false))

View file

@ -1,6 +1,8 @@
package tombstonetest package tombstonetest
import ( import (
"crypto/rand"
refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test" refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/tombstone" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/tombstone"
) )
@ -9,8 +11,11 @@ func GenerateTombstone(empty bool) *tombstone.Tombstone {
m := new(tombstone.Tombstone) m := new(tombstone.Tombstone)
if !empty { if !empty {
id := make([]byte, 16)
_, _ = rand.Read(id)
m.SetExpirationEpoch(89) m.SetExpirationEpoch(89)
m.SetSplitID([]byte{3, 2, 1}) m.SetSplitID(id)
m.SetMembers(refstest.GenerateObjectIDs(false)) m.SetMembers(refstest.GenerateObjectIDs(false))
} }