diff --git a/pkg/morph/event/container/delete.go b/pkg/morph/event/container/delete.go index 56fc7be039..931de22166 100644 --- a/pkg/morph/event/container/delete.go +++ b/pkg/morph/event/container/delete.go @@ -12,6 +12,7 @@ import ( type Delete struct { containerID []byte signature []byte + token []byte } // MorphEvent implements Neo:Morph Event interface. @@ -23,15 +24,25 @@ func (d Delete) ContainerID() []byte { return d.containerID } // Signature of marshalled container by container owner. func (d Delete) Signature() []byte { return d.signature } +// SessionToken returns binary token of the session +// within which the eACL was set. +func (d Delete) SessionToken() []byte { + return d.token +} + // ParseDelete from notification into container event structure. +// +// Expects 3 stack items. func ParseDelete(params []stackitem.Item) (event.Event, error) { var ( ev Delete err error ) - if ln := len(params); ln != 2 { - return nil, event.WrongNumberOfParameters(2, ln) + const expectedItemNumEACL = 3 + + if ln := len(params); ln != expectedItemNumEACL { + return nil, event.WrongNumberOfParameters(expectedItemNumEACL, ln) } // parse container @@ -46,5 +57,11 @@ func ParseDelete(params []stackitem.Item) (event.Event, error) { return nil, fmt.Errorf("could not get signature: %w", err) } + // parse session token + ev.token, err = client.BytesFromStackItem(params[2]) + if err != nil { + return nil, fmt.Errorf("could not get session token: %w", err) + } + return ev, nil } diff --git a/pkg/morph/event/container/delete_test.go b/pkg/morph/event/container/delete_test.go index 1ac309f34a..37f5edef6b 100644 --- a/pkg/morph/event/container/delete_test.go +++ b/pkg/morph/event/container/delete_test.go @@ -12,6 +12,7 @@ func TestParseDelete(t *testing.T) { var ( containerID = []byte("containreID") signature = []byte("signature") + token = []byte("token") ) t.Run("wrong number of parameters", func(t *testing.T) { @@ -20,7 +21,7 @@ func TestParseDelete(t *testing.T) { } _, err := ParseDelete(prms) - require.EqualError(t, err, event.WrongNumberOfParameters(2, len(prms)).Error()) + require.EqualError(t, err, event.WrongNumberOfParameters(3, len(prms)).Error()) }) t.Run("wrong container parameter", func(t *testing.T) { @@ -40,10 +41,21 @@ func TestParseDelete(t *testing.T) { require.Error(t, err) }) + t.Run("wrong session token parameter", func(t *testing.T) { + _, err := ParseDelete([]stackitem.Item{ + stackitem.NewByteArray(containerID), + stackitem.NewByteArray(signature), + stackitem.NewMap(), + }) + + require.Error(t, err) + }) + t.Run("correct behavior", func(t *testing.T) { ev, err := ParseDelete([]stackitem.Item{ stackitem.NewByteArray(containerID), stackitem.NewByteArray(signature), + stackitem.NewByteArray(token), }) require.NoError(t, err) @@ -51,6 +63,7 @@ func TestParseDelete(t *testing.T) { require.Equal(t, Delete{ containerID: containerID, signature: signature, + token: token, }, ev) }) }