[#283] pkg/container: Add session token and signature to Table

Extended ACL table can be set within a session, and should be signed.

Add `SessionToken` / `SetSessionToken` (`Signature` / `SetSignature`)
methods to carry session token (signature) in `Table` structure.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-05-24 20:35:56 +03:00 committed by Alex Vanin
parent 37b415347d
commit 0719fcef59
2 changed files with 46 additions and 0 deletions

View file

@ -5,6 +5,7 @@ import (
"github.com/nspcc-dev/neofs-api-go/pkg"
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
"github.com/nspcc-dev/neofs-api-go/pkg/session"
v2acl "github.com/nspcc-dev/neofs-api-go/v2/acl"
)
@ -14,6 +15,8 @@ import (
type Table struct {
version pkg.Version
cid *cid.ID
token *session.Token
sig *pkg.Signature
records []*Record
}
@ -49,6 +52,28 @@ func (t *Table) AddRecord(r *Record) {
}
}
// SessionToken returns token of the session
// within which Table was set.
func (t Table) SessionToken() *session.Token {
return t.token
}
// SetSessionToken sets token of the session
// within which Table was set.
func (t *Table) SetSessionToken(tok *session.Token) {
t.token = tok
}
// Signature returns Table signature.
func (t Table) Signature() *pkg.Signature {
return t.sig
}
// SetSignature sets Table signature.
func (t *Table) SetSignature(sig *pkg.Signature) {
t.sig = sig
}
// ToV2 converts Table to v2 acl.EACLTable message.
func (t *Table) ToV2() *v2acl.Table {
v2 := new(v2acl.Table)

View file

@ -7,6 +7,7 @@ import (
"github.com/nspcc-dev/neofs-api-go/pkg"
"github.com/nspcc-dev/neofs-api-go/pkg/acl/eacl"
"github.com/nspcc-dev/neofs-api-go/pkg/container"
sessiontest "github.com/nspcc-dev/neofs-api-go/pkg/session/test"
"github.com/stretchr/testify/require"
)
@ -91,3 +92,23 @@ func TestRecordEncoding(t *testing.T) {
require.Equal(t, tab, r2)
})
}
func TestTable_SessionToken(t *testing.T) {
tok := sessiontest.Generate()
table := eacl.NewTable()
table.SetSessionToken(tok)
require.Equal(t, tok, table.SessionToken())
}
func TestTable_Signature(t *testing.T) {
sig := pkg.NewSignature()
sig.SetKey([]byte{1, 2, 3})
sig.SetSign([]byte{4, 5, 6})
table := eacl.NewTable()
table.SetSignature(sig)
require.Equal(t, sig, table.Signature())
}