Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
giftkugel committed Aug 30, 2024
1 parent eef9ef6 commit 5d443b1
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
28 changes: 28 additions & 0 deletions internal/oidc/claims_test.go
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)
}
})
}
}
27 changes: 27 additions & 0 deletions internal/oidc/parameters_test.go
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)
}
})
}
}
53 changes: 53 additions & 0 deletions internal/oidc/scopes_test.go
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)
}
})
}
}

0 comments on commit 5d443b1

Please sign in to comment.