From 0719fcef59f9f7d1050e5c81ad7055d30789bbe4 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 24 May 2021 20:35:56 +0300 Subject: [PATCH] [#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 --- pkg/acl/eacl/table.go | 25 +++++++++++++++++++++++++ pkg/acl/eacl/table_test.go | 21 +++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/pkg/acl/eacl/table.go b/pkg/acl/eacl/table.go index a3175293..99b6aada 100644 --- a/pkg/acl/eacl/table.go +++ b/pkg/acl/eacl/table.go @@ -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) diff --git a/pkg/acl/eacl/table_test.go b/pkg/acl/eacl/table_test.go index 7092aeab..ec28efee 100644 --- a/pkg/acl/eacl/table_test.go +++ b/pkg/acl/eacl/table_test.go @@ -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()) +}