-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
108 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package oidc | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func Test_Claims(t *testing.T) { | ||
type claimParameter struct { | ||
value string | ||
expected string | ||
} | ||
|
||
var claimParameters = []claimParameter{ | ||
{ClaimNonce, "nonce"}, | ||
{ClaimAuthorizedParty, "azp"}, | ||
{ClaimAtHash, "at_hash"}, | ||
} | ||
|
||
for _, test := range claimParameters { | ||
testMessage := fmt.Sprintf("OIDC claim %s", test.value) | ||
t.Run(testMessage, func(t *testing.T) { | ||
if test.value != test.expected { | ||
t.Errorf("assertion error, %v != %v", test.value, test.expected) | ||
} | ||
}) | ||
} | ||
} |
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,27 @@ | ||
package oidc | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func Test_Parameters(t *testing.T) { | ||
type paramParameter struct { | ||
value string | ||
expected string | ||
} | ||
|
||
var paramParameters = []paramParameter{ | ||
{ParameterNonce, "nonce"}, | ||
{ParameterIdToken, "id_token"}, | ||
} | ||
|
||
for _, test := range paramParameters { | ||
testMessage := fmt.Sprintf("OIDC parameter %s", test.value) | ||
t.Run(testMessage, func(t *testing.T) { | ||
if test.value != test.expected { | ||
t.Errorf("assertion error, %v != %v", test.value, test.expected) | ||
} | ||
}) | ||
} | ||
} |
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,53 @@ | ||
package oidc | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func Test_Scopes(t *testing.T) { | ||
type scopeParameter struct { | ||
value string | ||
expected string | ||
} | ||
|
||
var scopeParameters = []scopeParameter{ | ||
{ScopeOpenId, "openid"}, | ||
{ScopeOfflineAccess, "offline_access"}, | ||
} | ||
|
||
for _, test := range scopeParameters { | ||
testMessage := fmt.Sprintf("OIDC scope %s", test.value) | ||
t.Run(testMessage, func(t *testing.T) { | ||
if test.value != test.expected { | ||
t.Errorf("assertion error, %v != %v", test.value, test.expected) | ||
} | ||
}) | ||
} | ||
|
||
type hasScopeParameter struct { | ||
values []string | ||
expected bool | ||
} | ||
|
||
var hasScopeParameters = []hasScopeParameter{ | ||
{[]string{ScopeOpenId}, true}, | ||
{[]string{ScopeOpenId, ScopeOfflineAccess}, true}, | ||
{[]string{ScopeOpenId, "foo", "bar"}, true}, | ||
{[]string{ScopeOfflineAccess}, false}, | ||
{[]string{ScopeOfflineAccess, "foo"}, false}, | ||
{[]string{ScopeOfflineAccess, "foo", "bar"}, false}, | ||
{[]string{"foo", "bar"}, false}, | ||
{[]string{"foo"}, false}, | ||
} | ||
|
||
for _, test := range hasScopeParameters { | ||
testMessage := fmt.Sprintf("Has OIDC scope %s", test.values) | ||
t.Run(testMessage, func(t *testing.T) { | ||
result := HasOidcScope(test.values) | ||
if result != test.expected { | ||
t.Errorf("should have OIDC scopes %v", test.values) | ||
} | ||
}) | ||
} | ||
} |