[#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,7 @@
package objecttest
import (
crand "crypto/rand"
"math/rand"
"time"
@ -59,7 +60,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 +95,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 +157,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 +637,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