forked from moby/buildkit
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Jacob MacElroy
committed
Oct 27, 2021
1 parent
33fb83e
commit 5279e68
Showing
2 changed files
with
72 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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) | ||
} | ||
}) | ||
} | ||
} |