Files
buildkit/util/resolver/authorizer_test.go
Jacob MacElroy 5279e683a5 Handling parsing of multiple scopes combined in a single string.
It is possible for challenge headers to contain multiple scopes in a single string. This change ensures that this case is handled when parsing the scopes by splitting out scopes combined in a single string.

Signed-off-by: Jacob MacElroy <jacob@okteto.com>
2021-10-27 16:32:36 -06:00

52 lines
1014 B
Go

package resolver
import (
"reflect"
"testing"
)
func TestParseScopes(t *testing.T) {
for _, tc := range []struct {
name string
input []string
expected scopes
}{
{
name: "SeparateStrings",
input: []string{
"repository:foo/bar:pull",
"repository:foo/baz:pull,push",
},
expected: map[string]map[string]struct{}{
"repository:foo/bar": {
"pull": struct{}{},
},
"repository:foo/baz": {
"pull": struct{}{},
"push": struct{}{},
},
},
},
{
name: "CombinedStrings",
input: []string{"repository:foo/bar:pull repository:foo/baz:pull,push"},
expected: map[string]map[string]struct{}{
"repository:foo/bar": {
"pull": struct{}{},
},
"repository:foo/baz": {
"pull": struct{}{},
"push": struct{}{},
},
},
},
} {
t.Run(tc.name, func(t *testing.T) {
parsed := parseScopes(tc.input)
if !reflect.DeepEqual(parsed, tc.expected) {
t.Fatalf("expected %v, got %v", tc.expected, parsed)
}
})
}
}