-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <[email protected]>
- Loading branch information
Showing
3 changed files
with
155 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package executor | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func Test_isAuthorized(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
want bool | ||
permissions []string | ||
namespace string | ||
function string | ||
}{ | ||
{ | ||
name: "allow cluster wildcard", | ||
want: true, | ||
permissions: []string{"*"}, | ||
namespace: "staging", | ||
function: "figlet", | ||
}, | ||
{ | ||
name: "allow namespace wildcard", | ||
want: true, | ||
permissions: []string{"dev:*"}, | ||
namespace: "dev", | ||
function: "figlet", | ||
}, | ||
{ | ||
name: "allow function", | ||
want: true, | ||
permissions: []string{"openfaas-fn:env"}, | ||
namespace: "openfaas-fn", | ||
function: "env", | ||
}, | ||
{ | ||
name: "deny function", | ||
want: false, | ||
permissions: []string{"openfaas-fn:env"}, | ||
namespace: "openfaas-fn", | ||
function: "figlet", | ||
}, | ||
{ | ||
name: "deny namespace", | ||
want: false, | ||
permissions: []string{"openfaas-fn:*"}, | ||
namespace: "staging", | ||
function: "env", | ||
}, | ||
{ | ||
name: "multiple permissions allow function", | ||
want: true, | ||
permissions: []string{"openfaas-fn:*", "staging:env"}, | ||
namespace: "staging", | ||
function: "env", | ||
}, | ||
{ | ||
name: "deny empty permission list", | ||
want: false, | ||
permissions: []string{}, | ||
namespace: "staging", | ||
function: "env", | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
want := test.want | ||
got := isAuthorized(test.permissions, test.namespace, test.function) | ||
|
||
if want != got { | ||
t.Errorf("want: %t, got: %t", want, got) | ||
} | ||
}) | ||
} | ||
} |