2021-12-16 15:26:13 +00:00
|
|
|
package container_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/container"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
|
|
|
containerCore "github.com/nspcc-dev/neofs-node/pkg/core/container"
|
|
|
|
containerSvc "github.com/nspcc-dev/neofs-node/pkg/services/container"
|
|
|
|
containerSvcMorph "github.com/nspcc-dev/neofs-node/pkg/services/container/morph"
|
|
|
|
containerSDK "github.com/nspcc-dev/neofs-sdk-go/container"
|
|
|
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/eacl"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
type mock struct{}
|
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
func (m mock) Put(_ *containerSDK.Container) (*cid.ID, error) {
|
2021-12-16 15:26:13 +00:00
|
|
|
return new(cid.ID), nil
|
|
|
|
}
|
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
func (m mock) Delete(_ containerCore.RemovalWitness) error {
|
2021-12-16 15:26:13 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
func (m mock) PutEACL(_ *eacl.Table) error {
|
2021-12-16 15:26:13 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
func (m mock) Get(_ *cid.ID) (*containerSDK.Container, error) {
|
2021-12-16 15:26:13 +00:00
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
func (m mock) GetEACL(_ *cid.ID) (*eacl.Table, error) {
|
2021-12-16 15:26:13 +00:00
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
func (m mock) List(_ *owner.ID) ([]*cid.ID, error) {
|
2021-12-16 15:26:13 +00:00
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInvalidToken(t *testing.T) {
|
|
|
|
m := mock{}
|
|
|
|
e := containerSvcMorph.NewExecutor(m, m)
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
op func(e containerSvc.ServiceExecutor, ctx containerSvc.ContextWithToken) error
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "put",
|
|
|
|
op: func(e containerSvc.ServiceExecutor, ctx containerSvc.ContextWithToken) (err error) {
|
|
|
|
_, err = e.Put(ctx, new(container.PutRequestBody))
|
|
|
|
return
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "delete",
|
|
|
|
op: func(e containerSvc.ServiceExecutor, ctx containerSvc.ContextWithToken) (err error) {
|
|
|
|
_, err = e.Delete(ctx, new(container.DeleteRequestBody))
|
|
|
|
return
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "setEACL",
|
|
|
|
op: func(e containerSvc.ServiceExecutor, ctx containerSvc.ContextWithToken) (err error) {
|
|
|
|
_, err = e.SetExtendedACL(ctx, new(container.SetExtendedACLRequestBody))
|
|
|
|
return
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
ctx := containerSvc.ContextWithToken{
|
|
|
|
Context: context.Background(),
|
|
|
|
SessionToken: generateToken(new(session.ObjectSessionContext)),
|
|
|
|
}
|
|
|
|
require.Error(t, test.op(e, ctx), containerSvcMorph.ErrInvalidContext)
|
|
|
|
|
|
|
|
ctx.SessionToken = generateToken(new(session.ContainerSessionContext))
|
|
|
|
require.NoError(t, test.op(e, ctx))
|
|
|
|
|
|
|
|
ctx.SessionToken = nil
|
|
|
|
require.NoError(t, test.op(e, ctx))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
func generateToken(ctx session.TokenContext) *session.Token {
|
|
|
|
body := new(session.TokenBody)
|
2021-12-16 15:26:13 +00:00
|
|
|
body.SetContext(ctx)
|
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
tok := new(session.Token)
|
2021-12-16 15:26:13 +00:00
|
|
|
tok.SetBody(body)
|
|
|
|
|
|
|
|
return tok
|
|
|
|
}
|