From 72baada0bff35e3aef13a5ebb5bd75c387908adc Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Wed, 24 May 2023 21:08:50 +0300 Subject: [PATCH] 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 --- client/errors.go | 2 ++ client/session.go | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/client/errors.go b/client/errors.go index 367f31f..5880a4d 100644 --- a/client/errors.go +++ b/client/errors.go @@ -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. diff --git a/client/session.go b/client/session.go index b749202..a56f810 100644 --- a/client/session.go +++ b/client/session.go @@ -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) {