mirror of
https://github.com/moby/buildkit.git
synced 2026-08-09 17:18:11 +00:00
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>
52 lines
1014 B
Go
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)
|
|
}
|
|
})
|
|
}
|
|
}
|