[#525] event/container: Parse session token from SetEACL notification
The 4th item of `SetEACL` container notification event is a byte array of serialized session token. Parse session token in `ParseSetEACL` function. Provide `SetEACL.SessionToken` method. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
b09f212990
commit
db7312274c
2 changed files with 28 additions and 1 deletions
|
@ -16,6 +16,8 @@ type SetEACL struct {
|
|||
signature []byte
|
||||
|
||||
publicKey []byte
|
||||
|
||||
token []byte
|
||||
}
|
||||
|
||||
// MorphEvent implements Neo:Morph Event interface.
|
||||
|
@ -37,6 +39,12 @@ func (x SetEACL) PublicKey() []byte {
|
|||
return x.publicKey
|
||||
}
|
||||
|
||||
// Session token returns binary token of the session
|
||||
// within which the eACL was set.
|
||||
func (x SetEACL) SessionToken() []byte {
|
||||
return x.token
|
||||
}
|
||||
|
||||
// ParseSetEACL parses SetEACL notification event from list of stack items.
|
||||
//
|
||||
// Expects 4 stack items.
|
||||
|
@ -70,5 +78,11 @@ func ParseSetEACL(items []stackitem.Item) (event.Event, error) {
|
|||
return nil, fmt.Errorf("could not parse binary public key: %w", err)
|
||||
}
|
||||
|
||||
// parse session token
|
||||
ev.token, err = client.BytesFromStackItem(items[3])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get sesison token: %w", err)
|
||||
}
|
||||
|
||||
return ev, nil
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ func TestParseEACL(t *testing.T) {
|
|||
binaryTable = []byte("table")
|
||||
signature = []byte("signature")
|
||||
publicKey = []byte("pubkey")
|
||||
token = []byte("token")
|
||||
)
|
||||
|
||||
t.Run("wrong number of parameters", func(t *testing.T) {
|
||||
|
@ -55,12 +56,23 @@ func TestParseEACL(t *testing.T) {
|
|||
require.Error(t, err)
|
||||
})
|
||||
|
||||
t.Run("wrong session token parameter", func(t *testing.T) {
|
||||
_, err := container.ParseSetEACL([]stackitem.Item{
|
||||
stackitem.NewByteArray(binaryTable),
|
||||
stackitem.NewByteArray(signature),
|
||||
stackitem.NewByteArray(publicKey),
|
||||
stackitem.NewMap(),
|
||||
})
|
||||
|
||||
require.Error(t, err)
|
||||
})
|
||||
|
||||
t.Run("correct behavior", func(t *testing.T) {
|
||||
ev, err := container.ParseSetEACL([]stackitem.Item{
|
||||
stackitem.NewByteArray(binaryTable),
|
||||
stackitem.NewByteArray(signature),
|
||||
stackitem.NewByteArray(publicKey),
|
||||
stackitem.NewMap(),
|
||||
stackitem.NewByteArray(token),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
|
@ -69,5 +81,6 @@ func TestParseEACL(t *testing.T) {
|
|||
require.Equal(t, binaryTable, e.Table())
|
||||
require.Equal(t, signature, e.Signature())
|
||||
require.Equal(t, publicKey, e.PublicKey())
|
||||
require.Equal(t, token, e.SessionToken())
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue