[#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,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