Skip to content

Commit

Permalink
test: add test for supporting scope list in token
Browse files Browse the repository at this point in the history
Co-authored-by: Xiaofei Du <[email protected]>
  • Loading branch information
pirm-in and xiaofei-du committed Nov 6, 2023
1 parent e05b84e commit 889cb9c
Showing 1 changed file with 130 additions and 0 deletions.
130 changes: 130 additions & 0 deletions jose_test.go
Original file line number Diff line number Diff line change
@@ -150,6 +150,71 @@ func TestScopesAllMatcher(t *testing.T) {
requiredScopes []string
expected bool
}{
{
name: "all_simple_success_for_scope_slice",
scopesKey: "scope",
claims: map[string]interface{}{"scope": []interface{}{"a", "b"}},
requiredScopes: []string{"a", "b"},
expected: true,
},
{
name: "all_simple_fail_for_scope_slice",
scopesKey: "scope",
claims: map[string]interface{}{"scope": []interface{}{"a", "b"}},
requiredScopes: []string{"c"},
expected: false,
},
{
name: "all_missingone_fail_for_scope_slice",
scopesKey: "scope",
claims: map[string]interface{}{"scope": []interface{}{"a", "b"}},
requiredScopes: []string{"a", "b", "c"},
expected: false,
},
{
name: "all_one_simple_success_for_scope_slice",
scopesKey: "scope",
claims: map[string]interface{}{"scope": []interface{}{"a", "b"}},
requiredScopes: []string{"b"},
expected: true,
},
{
name: "all_no_req_scopes_success_for_scope_slice",
scopesKey: "scope",
claims: map[string]interface{}{"scope": []interface{}{"a", "b"}},
requiredScopes: []string{},
expected: true,
},
{
name: "all_struct_success_for_scope_slice",
scopesKey: "data.scope",
claims: map[string]interface{}{"data": map[string]interface{}{"scope": []interface{}{"a", "b"}}},
requiredScopes: []string{"a", "b"},
expected: true,
},
{
name: "all_deep_struct_success_for_scope_slice",
scopesKey: "data.data.data.data.data.data.data.scope",
claims: map[string]interface{}{
"data": map[string]interface{}{
"data": map[string]interface{}{
"data": map[string]interface{}{
"data": map[string]interface{}{
"data": map[string]interface{}{
"data": map[string]interface{}{
"data": map[string]interface{}{
"scope": []interface{}{"a", "b"},
},
},
},
},
},
},
},
},
requiredScopes: []string{"a", "b"},
expected: true,
},
{
name: "all_simple_success",
scopesKey: "scope",
@@ -232,6 +297,71 @@ func TestScopesAnyMatcher(t *testing.T) {
requiredScopes []string
expected bool
}{
{
name: "any_simple_success_for_scope_slice",
scopesKey: "scope",
claims: map[string]interface{}{"scope": []interface{}{"a", "b"}},
requiredScopes: []string{"a", "b"},
expected: true,
},
{
name: "any_simple_fail_for_scope_slice",
scopesKey: "scope",
claims: map[string]interface{}{"scope": []interface{}{"a", "b"}},
requiredScopes: []string{"c"},
expected: false,
},
{
name: "any_missingone_success_for_scope_slice",
scopesKey: "scope",
claims: map[string]interface{}{"scope": []interface{}{"a"}},
requiredScopes: []string{"a", "b"},
expected: true,
},
{
name: "any_one_simple_success_for_scope_slice",
scopesKey: "scope",
claims: map[string]interface{}{"scope": []interface{}{"a", "b"}},
requiredScopes: []string{"b"},
expected: true,
},
{
name: "any_no_req_scopes_success_for_scope_slice",
scopesKey: "scope",
claims: map[string]interface{}{"scope": []interface{}{"a", "b"}},
requiredScopes: []string{},
expected: true,
},
{
name: "any_struct_success_for_scope_slice",
scopesKey: "data.scope",
claims: map[string]interface{}{"data": map[string]interface{}{"scope": []interface{}{"a"}}},
requiredScopes: []string{"a", "b"},
expected: true,
},
{
name: "any_deep_struct_success_for_scope_slice",
scopesKey: "data.data.data.data.data.data.data.scope",
claims: map[string]interface{}{
"data": map[string]interface{}{
"data": map[string]interface{}{
"data": map[string]interface{}{
"data": map[string]interface{}{
"data": map[string]interface{}{
"data": map[string]interface{}{
"data": map[string]interface{}{
"scope": []interface{}{"a"},
},
},
},
},
},
},
},
},
requiredScopes: []string{"a", "b"},
expected: true,
},
{
name: "any_simple_success",
scopesKey: "scope",

0 comments on commit 889cb9c

Please sign in to comment.