2020-08-11 14:46:31 +03:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
2022-08-11 17:24:26 +04:00
|
|
|
"crypto/sha256"
|
2020-08-11 14:46:31 +03:00
|
|
|
"testing"
|
|
|
|
|
2023-03-07 16:38:26 +03:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event"
|
|
|
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
2020-10-26 17:46:15 +03:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
2020-08-11 14:46:31 +03:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestParsePut(t *testing.T) {
|
|
|
|
var (
|
|
|
|
containerData = []byte("containerData")
|
|
|
|
signature = []byte("signature")
|
2021-05-19 17:16:48 +03:00
|
|
|
publicKey = []byte("pubkey")
|
2021-05-25 18:52:55 +03:00
|
|
|
token = []byte("token")
|
2020-08-11 14:46:31 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
t.Run("wrong number of parameters", func(t *testing.T) {
|
2020-10-26 17:46:15 +03:00
|
|
|
prms := []stackitem.Item{
|
|
|
|
stackitem.NewMap(),
|
|
|
|
stackitem.NewMap(),
|
2020-08-11 14:46:31 +03:00
|
|
|
}
|
|
|
|
|
2021-10-22 13:06:08 +03:00
|
|
|
_, err := ParsePut(createNotifyEventFromItems(prms))
|
2021-05-25 12:15:24 +03:00
|
|
|
require.EqualError(t, err, event.WrongNumberOfParameters(expectedItemNumPut, len(prms)).Error())
|
2020-08-11 14:46:31 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("wrong container parameter", func(t *testing.T) {
|
2021-10-22 13:06:08 +03:00
|
|
|
_, err := ParsePut(createNotifyEventFromItems([]stackitem.Item{
|
2020-10-26 17:46:15 +03:00
|
|
|
stackitem.NewMap(),
|
2021-10-22 13:06:08 +03:00
|
|
|
}))
|
2020-08-11 14:46:31 +03:00
|
|
|
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("wrong signature parameter", func(t *testing.T) {
|
2021-10-22 13:06:08 +03:00
|
|
|
_, err := ParsePut(createNotifyEventFromItems([]stackitem.Item{
|
2020-10-26 17:46:15 +03:00
|
|
|
stackitem.NewByteArray(containerData),
|
|
|
|
stackitem.NewMap(),
|
2021-10-22 13:06:08 +03:00
|
|
|
}))
|
2020-08-11 14:46:31 +03:00
|
|
|
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("wrong key parameter", func(t *testing.T) {
|
2021-10-22 13:06:08 +03:00
|
|
|
_, err := ParsePut(createNotifyEventFromItems([]stackitem.Item{
|
2020-10-26 17:46:15 +03:00
|
|
|
stackitem.NewByteArray(containerData),
|
|
|
|
stackitem.NewByteArray(signature),
|
|
|
|
stackitem.NewMap(),
|
2021-10-22 13:06:08 +03:00
|
|
|
}))
|
2020-08-11 14:46:31 +03:00
|
|
|
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
2021-05-25 18:52:55 +03:00
|
|
|
t.Run("wrong session token parameter", func(t *testing.T) {
|
2021-10-22 13:06:08 +03:00
|
|
|
_, err := ParsePut(createNotifyEventFromItems([]stackitem.Item{
|
2021-05-25 18:52:55 +03:00
|
|
|
stackitem.NewByteArray(containerData),
|
|
|
|
stackitem.NewByteArray(signature),
|
|
|
|
stackitem.NewByteArray(publicKey),
|
|
|
|
stackitem.NewMap(),
|
2021-10-22 13:06:08 +03:00
|
|
|
}))
|
2021-05-25 18:52:55 +03:00
|
|
|
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
2020-08-11 14:46:31 +03:00
|
|
|
t.Run("correct behavior", func(t *testing.T) {
|
2021-10-22 13:06:08 +03:00
|
|
|
ev, err := ParsePut(createNotifyEventFromItems([]stackitem.Item{
|
2020-10-26 17:46:15 +03:00
|
|
|
stackitem.NewByteArray(containerData),
|
|
|
|
stackitem.NewByteArray(signature),
|
2021-05-19 17:16:48 +03:00
|
|
|
stackitem.NewByteArray(publicKey),
|
2021-05-25 18:52:55 +03:00
|
|
|
stackitem.NewByteArray(token),
|
2021-10-22 13:06:08 +03:00
|
|
|
}))
|
2020-08-11 14:46:31 +03:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Equal(t, Put{
|
|
|
|
rawContainer: containerData,
|
|
|
|
signature: signature,
|
2021-05-19 17:16:48 +03:00
|
|
|
publicKey: publicKey,
|
2021-05-25 18:52:55 +03:00
|
|
|
token: token,
|
2020-08-11 14:46:31 +03:00
|
|
|
}, ev)
|
|
|
|
})
|
|
|
|
}
|
2022-08-11 17:24:26 +04:00
|
|
|
|
|
|
|
func TestParsePutSuccess(t *testing.T) {
|
|
|
|
t.Run("wrong number of parameters", func(t *testing.T) {
|
|
|
|
prms := []stackitem.Item{
|
|
|
|
stackitem.NewMap(),
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := ParsePutSuccess(createNotifyEventFromItems(prms))
|
|
|
|
require.EqualError(t, err, event.WrongNumberOfParameters(2, len(prms)).Error())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("wrong container ID parameter", func(t *testing.T) {
|
|
|
|
_, err := ParsePutSuccess(createNotifyEventFromItems([]stackitem.Item{
|
|
|
|
stackitem.NewMap(),
|
|
|
|
stackitem.NewMap(),
|
|
|
|
}))
|
|
|
|
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
id := cidtest.ID()
|
|
|
|
|
|
|
|
binID := make([]byte, sha256.Size)
|
|
|
|
id.Encode(binID)
|
|
|
|
|
|
|
|
t.Run("wrong public key parameter", func(t *testing.T) {
|
|
|
|
_, err := ParsePutSuccess(createNotifyEventFromItems([]stackitem.Item{
|
|
|
|
stackitem.NewByteArray(binID),
|
|
|
|
stackitem.NewMap(),
|
|
|
|
}))
|
|
|
|
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("correct behavior", func(t *testing.T) {
|
|
|
|
ev, err := ParsePutSuccess(createNotifyEventFromItems([]stackitem.Item{
|
|
|
|
stackitem.NewByteArray(binID),
|
|
|
|
stackitem.NewByteArray([]byte("key")),
|
|
|
|
}))
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Equal(t, PutSuccess{
|
|
|
|
ID: id,
|
|
|
|
}, ev)
|
|
|
|
})
|
|
|
|
}
|