383edb1be4
Move all memory allocation and field settings in `Generate...(empty bool)` functions behind `if !empty` check. Do not create empty slices if `empty == true`. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
228 lines
4.9 KiB
Go
228 lines
4.9 KiB
Go
package sessiontest
|
|
|
|
import (
|
|
acltest "github.com/nspcc-dev/neofs-api-go/v2/acl/test"
|
|
refstest "github.com/nspcc-dev/neofs-api-go/v2/refs/test"
|
|
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
|
)
|
|
|
|
func GenerateCreateRequestBody(empty bool) *session.CreateRequestBody {
|
|
m := new(session.CreateRequestBody)
|
|
|
|
if !empty {
|
|
m.SetExpiration(555)
|
|
m.SetOwnerID(refstest.GenerateOwnerID(false))
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
func GenerateCreateRequest(empty bool) *session.CreateRequest {
|
|
m := new(session.CreateRequest)
|
|
|
|
if !empty {
|
|
m.SetBody(GenerateCreateRequestBody(false))
|
|
}
|
|
|
|
m.SetMetaHeader(GenerateRequestMetaHeader(empty))
|
|
m.SetVerificationHeader(GenerateRequestVerificationHeader(empty))
|
|
|
|
return m
|
|
}
|
|
|
|
func GenerateCreateResponseBody(empty bool) *session.CreateResponseBody {
|
|
m := new(session.CreateResponseBody)
|
|
|
|
if !empty {
|
|
m.SetID([]byte{1, 2, 3})
|
|
m.SetSessionKey([]byte{4, 5, 6})
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
func GenerateCreateResponse(empty bool) *session.CreateResponse {
|
|
m := new(session.CreateResponse)
|
|
|
|
if !empty {
|
|
m.SetBody(GenerateCreateResponseBody(false))
|
|
}
|
|
|
|
m.SetMetaHeader(GenerateResponseMetaHeader(empty))
|
|
m.SetVerificationHeader(GenerateResponseVerificationHeader(empty))
|
|
|
|
return m
|
|
}
|
|
|
|
func GenerateResponseVerificationHeader(empty bool) *session.ResponseVerificationHeader {
|
|
return generateResponseVerificationHeader(empty, true)
|
|
}
|
|
|
|
func generateResponseVerificationHeader(empty, withOrigin bool) *session.ResponseVerificationHeader {
|
|
m := new(session.ResponseVerificationHeader)
|
|
|
|
if !empty {
|
|
m.SetBodySignature(refstest.GenerateSignature(false))
|
|
}
|
|
|
|
m.SetMetaSignature(refstest.GenerateSignature(empty))
|
|
m.SetOriginSignature(refstest.GenerateSignature(empty))
|
|
|
|
if withOrigin {
|
|
m.SetOrigin(generateResponseVerificationHeader(empty, false))
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
func GenerateResponseMetaHeader(empty bool) *session.ResponseMetaHeader {
|
|
return generateResponseMetaHeader(empty, true)
|
|
}
|
|
|
|
func generateResponseMetaHeader(empty, withOrigin bool) *session.ResponseMetaHeader {
|
|
m := new(session.ResponseMetaHeader)
|
|
|
|
if !empty {
|
|
m.SetEpoch(13)
|
|
m.SetTTL(100)
|
|
}
|
|
|
|
m.SetXHeaders(GenerateXHeaders(empty))
|
|
m.SetVersion(refstest.GenerateVersion(empty))
|
|
|
|
if withOrigin {
|
|
m.SetOrigin(generateResponseMetaHeader(empty, false))
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
func GenerateRequestVerificationHeader(empty bool) *session.RequestVerificationHeader {
|
|
return generateRequestVerificationHeader(empty, true)
|
|
}
|
|
|
|
func generateRequestVerificationHeader(empty, withOrigin bool) *session.RequestVerificationHeader {
|
|
m := new(session.RequestVerificationHeader)
|
|
|
|
if !empty {
|
|
m.SetBodySignature(refstest.GenerateSignature(false))
|
|
}
|
|
|
|
m.SetMetaSignature(refstest.GenerateSignature(empty))
|
|
m.SetOriginSignature(refstest.GenerateSignature(empty))
|
|
|
|
if withOrigin {
|
|
m.SetOrigin(generateRequestVerificationHeader(empty, false))
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
func GenerateRequestMetaHeader(empty bool) *session.RequestMetaHeader {
|
|
return generateRequestMetaHeader(empty, true)
|
|
}
|
|
|
|
func generateRequestMetaHeader(empty, withOrigin bool) *session.RequestMetaHeader {
|
|
m := new(session.RequestMetaHeader)
|
|
|
|
if !empty {
|
|
m.SetEpoch(13)
|
|
m.SetTTL(100)
|
|
}
|
|
|
|
m.SetXHeaders(GenerateXHeaders(empty))
|
|
m.SetVersion(refstest.GenerateVersion(empty))
|
|
m.SetSessionToken(GenerateSessionToken(empty))
|
|
m.SetBearerToken(acltest.GenerateBearerToken(empty))
|
|
|
|
if withOrigin {
|
|
m.SetOrigin(generateRequestMetaHeader(empty, false))
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
func GenerateSessionToken(empty bool) *session.SessionToken {
|
|
m := new(session.SessionToken)
|
|
|
|
if !empty {
|
|
m.SetBody(GenerateSessionTokenBody(false))
|
|
}
|
|
|
|
m.SetSignature(refstest.GenerateSignature(empty))
|
|
|
|
return m
|
|
}
|
|
|
|
func GenerateSessionTokenBody(empty bool) *session.SessionTokenBody {
|
|
m := new(session.SessionTokenBody)
|
|
|
|
if !empty {
|
|
m.SetID([]byte{1})
|
|
m.SetSessionKey([]byte{2})
|
|
m.SetOwnerID(refstest.GenerateOwnerID(false))
|
|
m.SetLifetime(GenerateTokenLifetime(false))
|
|
m.SetContext(GenerateObjectSessionContext(false))
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
func GenerateTokenLifetime(empty bool) *session.TokenLifetime {
|
|
m := new(session.TokenLifetime)
|
|
|
|
if !empty {
|
|
m.SetExp(1)
|
|
m.SetIat(2)
|
|
m.SetExp(3)
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
func GenerateObjectSessionContext(empty bool) *session.ObjectSessionContext {
|
|
m := new(session.ObjectSessionContext)
|
|
|
|
if !empty {
|
|
m.SetVerb(session.ObjectVerbHead)
|
|
m.SetAddress(refstest.GenerateAddress(false))
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
func GenerateContainerSessionContext(empty bool) *session.ContainerSessionContext {
|
|
m := new(session.ContainerSessionContext)
|
|
|
|
if !empty {
|
|
m.SetVerb(session.ContainerVerbDelete)
|
|
m.SetWildcard(true)
|
|
m.SetContainerID(refstest.GenerateContainerID(false))
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
func GenerateXHeader(empty bool) *session.XHeader {
|
|
m := new(session.XHeader)
|
|
|
|
if !empty {
|
|
m.SetKey("key")
|
|
m.SetValue("val")
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
func GenerateXHeaders(empty bool) []*session.XHeader {
|
|
var xs []*session.XHeader
|
|
|
|
if !empty {
|
|
xs = append(xs,
|
|
GenerateXHeader(false),
|
|
GenerateXHeader(false),
|
|
)
|
|
}
|
|
|
|
return xs
|
|
}
|