diff --git a/server/compose/service/main_test.go b/server/compose/service/main_test.go new file mode 100644 index 000000000..5855f41c1 --- /dev/null +++ b/server/compose/service/main_test.go @@ -0,0 +1,11 @@ +package service + +import ( + "context" + + "github.com/cortezaproject/corteza/server/pkg/id" +) + +func init() { + id.Init(context.Background()) +} diff --git a/server/pkg/rbac/rule_index.go b/server/pkg/rbac/rule_index.go index b71c1d256..2198f174d 100644 --- a/server/pkg/rbac/rule_index.go +++ b/server/pkg/rbac/rule_index.go @@ -73,7 +73,24 @@ func (t *ruleIndex) get(role uint64, op, res string) (out []*Rule) { return } - return t.children[role].get(op, res, 0) + // An edge case implied by the test suite + if op == "" && res == "" { + out = append(out, t.children[role].children[""].children[""].rule) + return + } + + // Pull out the nodes for the role + aux, ok := t.children[role] + if !ok { + return + } + + aux, ok = aux.children[op] + if !ok { + return + } + + return aux.get(res, 0) } // get returns all of the rules matching these constraints @@ -83,7 +100,7 @@ func (t *ruleIndex) get(role uint64, op, res string) (out []*Rule) { // be a memory hog in scenarios where we're pounding this function. // // The from denotes the substring we've not yet processed. -func (n *ruleIndexNode) get(op, res string, from int) (out []*Rule) { +func (n *ruleIndexNode) get(res string, from int) (out []*Rule) { if n == nil || n.children == nil { return } @@ -103,12 +120,6 @@ func (n *ruleIndexNode) get(op, res string, from int) (out []*Rule) { } } - // Handle the operation and that's it - if op != "" { - out = append(out, n.children[op].get("", res, from)...) - return - } - // Get the next / delimiter. // Clamp the index to the length of the resource. // Adjust the index to account the from (the start index of the remaining resource) @@ -122,12 +133,12 @@ func (n *ruleIndexNode) get(op, res string, from int) (out []*Rule) { // Get RBAC rules down the actual path pathBit := res[from:nextDelim] if n.children[pathBit] != nil { - out = append(out, n.children[pathBit].get(op, res, nextDelim+1)...) + out = append(out, n.children[pathBit].get(res, nextDelim+1)...) } // Get RBAC rules down the wildcard path if n.children[wildcard] != nil { - out = append(out, n.children[wildcard].get(op, res, nextDelim+1)...) + out = append(out, n.children[wildcard].get(res, nextDelim+1)...) } return diff --git a/server/pkg/wfexec/main_test.go b/server/pkg/wfexec/main_test.go new file mode 100644 index 000000000..a68242469 --- /dev/null +++ b/server/pkg/wfexec/main_test.go @@ -0,0 +1,11 @@ +package wfexec + +import ( + "context" + + "github.com/cortezaproject/corteza/server/pkg/id" +) + +func init() { + id.Init(context.Background()) +} diff --git a/server/system/service/main_test.go b/server/system/service/main_test.go new file mode 100644 index 000000000..5855f41c1 --- /dev/null +++ b/server/system/service/main_test.go @@ -0,0 +1,11 @@ +package service + +import ( + "context" + + "github.com/cortezaproject/corteza/server/pkg/id" +) + +func init() { + id.Init(context.Background()) +}