forked from TrueCloudLab/frostfs-node
[#525] event/container: Parse binary session token from Put notification
The 4th item of `Put` container notification event is a byte array of serialized session token. Parse session token in `ParsePut` function. Provide `Put.SessionToken` method. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
98cc685a9b
commit
0f91b78df1
2 changed files with 27 additions and 1 deletions
|
@ -13,6 +13,7 @@ type Put struct {
|
|||
rawContainer []byte
|
||||
signature []byte
|
||||
publicKey []byte
|
||||
token []byte
|
||||
}
|
||||
|
||||
const expectedItemNumPut = 4
|
||||
|
@ -29,6 +30,12 @@ func (p Put) Signature() []byte { return p.signature }
|
|||
// PublicKey of container owner.
|
||||
func (p Put) PublicKey() []byte { return p.publicKey }
|
||||
|
||||
// Session token returns binary token of the session
|
||||
// within which the container was created.
|
||||
func (p Put) SessionToken() []byte {
|
||||
return p.token
|
||||
}
|
||||
|
||||
// ParsePut from notification into container event structure.
|
||||
func ParsePut(params []stackitem.Item) (event.Event, error) {
|
||||
var (
|
||||
|
@ -58,5 +65,11 @@ func ParsePut(params []stackitem.Item) (event.Event, error) {
|
|||
return nil, fmt.Errorf("could not get public key: %w", err)
|
||||
}
|
||||
|
||||
// parse session token
|
||||
ev.token, err = client.BytesFromStackItem(params[3])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get sesison token: %w", err)
|
||||
}
|
||||
|
||||
return ev, nil
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ func TestParsePut(t *testing.T) {
|
|||
containerData = []byte("containerData")
|
||||
signature = []byte("signature")
|
||||
publicKey = []byte("pubkey")
|
||||
token = []byte("token")
|
||||
)
|
||||
|
||||
t.Run("wrong number of parameters", func(t *testing.T) {
|
||||
|
@ -52,12 +53,23 @@ func TestParsePut(t *testing.T) {
|
|||
require.Error(t, err)
|
||||
})
|
||||
|
||||
t.Run("wrong session token parameter", func(t *testing.T) {
|
||||
_, err := ParsePut([]stackitem.Item{
|
||||
stackitem.NewByteArray(containerData),
|
||||
stackitem.NewByteArray(signature),
|
||||
stackitem.NewByteArray(publicKey),
|
||||
stackitem.NewMap(),
|
||||
})
|
||||
|
||||
require.Error(t, err)
|
||||
})
|
||||
|
||||
t.Run("correct behavior", func(t *testing.T) {
|
||||
ev, err := ParsePut([]stackitem.Item{
|
||||
stackitem.NewByteArray(containerData),
|
||||
stackitem.NewByteArray(signature),
|
||||
stackitem.NewByteArray(publicKey),
|
||||
stackitem.NewMap(),
|
||||
stackitem.NewByteArray(token),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
|
@ -65,6 +77,7 @@ func TestParsePut(t *testing.T) {
|
|||
rawContainer: containerData,
|
||||
signature: signature,
|
||||
publicKey: publicKey,
|
||||
token: token,
|
||||
}, ev)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue