forked from TrueCloudLab/policy-engine
[#59] router: Inmemory implementation should take empty name for "root"
Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
parent
1d51f2121d
commit
42497ad242
2 changed files with 24 additions and 0 deletions
|
@ -11,6 +11,26 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"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) {
|
func TestInmemory(t *testing.T) {
|
||||||
const (
|
const (
|
||||||
object = "native::object::abc/xyz"
|
object = "native::object::abc/xyz"
|
||||||
|
|
|
@ -52,6 +52,10 @@ func (s *inmemoryLocalStorage) AddOverride(name chain.Name, target engine.Target
|
||||||
s.guard.Lock()
|
s.guard.Lock()
|
||||||
defer s.guard.Unlock()
|
defer s.guard.Unlock()
|
||||||
|
|
||||||
|
if target.Name == "" {
|
||||||
|
target.Name = "root"
|
||||||
|
}
|
||||||
|
|
||||||
// AddOverride assigns generated chain ID if it has not been assigned.
|
// AddOverride assigns generated chain ID if it has not been assigned.
|
||||||
if len(c.ID) == 0 {
|
if len(c.ID) == 0 {
|
||||||
c.ID = s.generateChainID(name, target)
|
c.ID = s.generateChainID(name, target)
|
||||||
|
|
Loading…
Reference in a new issue