From 42497ad2424c76a625038ff2bfcc008733a5d59b Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Tue, 2 Apr 2024 11:09:42 +0300 Subject: [PATCH] [#59] router: Inmemory implementation should take empty name for "root" Signed-off-by: Denis Kirillov --- pkg/engine/inmemory/inmemory_test.go | 20 ++++++++++++++++++++ pkg/engine/inmemory/local_storage.go | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/pkg/engine/inmemory/inmemory_test.go b/pkg/engine/inmemory/inmemory_test.go index 628a81c..498586d 100644 --- a/pkg/engine/inmemory/inmemory_test.go +++ b/pkg/engine/inmemory/inmemory_test.go @@ -11,6 +11,26 @@ import ( "github.com/stretchr/testify/require" ) +func TestAddRootOverrides(t *testing.T) { + s := NewInMemoryLocalOverrides() + + target := engine.NamespaceTarget("") + + id, err := s.LocalStorage().AddOverride(chain.S3, target, &chain.Chain{ + Rules: []chain.Rule{{ + Status: chain.Allow, + Actions: chain.Actions{Names: []string{"s3:PutObject"}}, + Resources: chain.Resources{Names: []string{"*"}}, + }}, + }) + require.NoError(t, err) + + res, err := s.LocalStorage().ListOverrides(chain.S3, target) + require.NoError(t, err) + require.Len(t, res, 1) + require.Equal(t, string(id), string(res[0].ID)) +} + func TestInmemory(t *testing.T) { const ( object = "native::object::abc/xyz" diff --git a/pkg/engine/inmemory/local_storage.go b/pkg/engine/inmemory/local_storage.go index 276b495..b585816 100644 --- a/pkg/engine/inmemory/local_storage.go +++ b/pkg/engine/inmemory/local_storage.go @@ -52,6 +52,10 @@ func (s *inmemoryLocalStorage) AddOverride(name chain.Name, target engine.Target s.guard.Lock() defer s.guard.Unlock() + if target.Name == "" { + target.Name = "root" + } + // AddOverride assigns generated chain ID if it has not been assigned. if len(c.ID) == 0 { c.ID = s.generateChainID(name, target)