Skip to content

Commit

Permalink
added claims_test.go
Browse files Browse the repository at this point in the history
Signed-off-by: Atif Ali <atali@redhat.com>
  • Loading branch information
aali309 committed Nov 17, 2024
1 parent 119fbeb commit 37cca7e
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions cmd/argocd/commands/utils/claims_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package utils

import (
"testing"

"github.com/golang-jwt/jwt/v4"
"github.com/stretchr/testify/assert"
)

func TestGetUserIdentifier(t *testing.T) {
tests := []struct {
name string
claims jwt.MapClaims
want string
}{
{
name: "federated claims present",
claims: jwt.MapClaims{
"sub": "ignored:login",
"federated_claims": map[string]interface{}{
"user_id": "dex-user",
},
},
want: "dex-user",
},
{
name: "empty federated claims falls back to sub",
claims: jwt.MapClaims{
"sub": "test:apiKey",
"federated_claims": map[string]interface{}{
"user_id": "",
},
},
want: "test:apiKey",
},
{
name: "no federated claims uses sub",
claims: jwt.MapClaims{
"sub": "admin:login",
},
want: "admin:login",
},
{
name: "empty claims",
claims: jwt.MapClaims{},
want: "",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := GetUserIdentifier(tt.claims)
assert.Equal(t, tt.want, got)
})
}
}

0 comments on commit 37cca7e

Please sign in to comment.