client: Fix panic in SessionCreate

Do not panic if a signer was provided as a default. Also, return
`ErrMissingSigner` if no signer was provided at all.

Signed-off-by: Pavel Karpy <carpawell@morphbits.io>
This commit is contained in:
Pavel Karpy 2023-05-24 21:08:50 +03:00
parent 5f07bcfec2
commit 72baada0bf
2 changed files with 16 additions and 6 deletions

View file

@ -17,6 +17,8 @@ var (
ErrMissingObject = errors.New("missing object")
// ErrMissingAccount is returned when account/owner is not provided.
ErrMissingAccount = errors.New("missing account")
// ErrMissingSigner is returned when signer is not provided.
ErrMissingSigner = errors.New("missing signer")
// ErrMissingEACL is returned when eACL table is not provided.
ErrMissingEACL = errors.New("missing eACL table")
// ErrMissingEACLContainer is returned when container info is not provided in eACL table.

View file

@ -66,9 +66,21 @@ func (x ResSessionCreate) PublicKey() []byte {
// see [apistatus] package for NeoFS-specific error types.
//
// Context is required and must not be nil. It is used for network communication.
//
// Return errors:
// - [ErrMissingSigner]
func (c *Client) SessionCreate(ctx context.Context, prm PrmSessionCreate) (*ResSessionCreate, error) {
signer := prm.signer
if signer == nil {
signer = c.prm.signer
}
if signer == nil {
return nil, ErrMissingSigner
}
var ownerID user.ID
if err := user.IDFromSigner(&ownerID, prm.signer); err != nil {
if err := user.IDFromSigner(&ownerID, signer); err != nil {
return nil, fmt.Errorf("IDFromSigner: %w", err)
}
@ -93,11 +105,7 @@ func (c *Client) SessionCreate(ctx context.Context, prm PrmSessionCreate) (*ResS
)
c.initCallContext(&cc)
cc.signer = prm.signer
if cc.signer == nil {
cc.signer = c.prm.signer
}
cc.signer = signer
cc.meta = prm.prmCommonMeta
cc.req = &req
cc.call = func() (responseV2, error) {