mirror of
https://github.com/lukaszraczylo/traefikoidc.git
synced 2026-10-14 04:07:46 +00:00
Well.. that escalated quickly.
Completely forgot that Traefik uses outdated Yaegi and requires compatibility with 1.20 ( pre-generic Go code ).
This commit is contained in:
@@ -2,7 +2,6 @@ package traefikoidc
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"maps"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
@@ -21,7 +20,7 @@ func TestTemplatedHeadersIntegration(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
sessionSetup func(*SessionData)
|
||||
claims map[string]any
|
||||
claims map[string]interface{}
|
||||
expectedHeaders map[string]string
|
||||
interceptedHeaders map[string]string
|
||||
name string
|
||||
@@ -32,7 +31,7 @@ func TestTemplatedHeadersIntegration(t *testing.T) {
|
||||
headers: []TemplatedHeader{
|
||||
{Name: "X-User-Email", Value: "{{.Claims.email}}"},
|
||||
},
|
||||
claims: map[string]any{
|
||||
claims: map[string]interface{}{
|
||||
"email": "[email protected]",
|
||||
},
|
||||
expectedHeaders: map[string]string{
|
||||
@@ -46,7 +45,7 @@ func TestTemplatedHeadersIntegration(t *testing.T) {
|
||||
{Name: "X-User-ID", Value: "{{.Claims.sub}}"},
|
||||
{Name: "X-User-Name", Value: "{{.Claims.given_name}} {{.Claims.family_name}}"},
|
||||
},
|
||||
claims: map[string]any{
|
||||
claims: map[string]interface{}{
|
||||
"email": "[email protected]",
|
||||
"sub": "user123",
|
||||
"given_name": "John",
|
||||
@@ -95,7 +94,7 @@ func TestTemplatedHeadersIntegration(t *testing.T) {
|
||||
headers: []TemplatedHeader{
|
||||
{Name: "X-User-Role", Value: "{{.Claims.role}}"},
|
||||
},
|
||||
claims: map[string]any{
|
||||
claims: map[string]interface{}{
|
||||
"email": "[email protected]",
|
||||
// role claim is missing
|
||||
},
|
||||
@@ -108,7 +107,7 @@ func TestTemplatedHeadersIntegration(t *testing.T) {
|
||||
headers: []TemplatedHeader{
|
||||
{Name: "X-User-Admin", Value: "{{if .Claims.is_admin}}true{{else}}false{{end}}"},
|
||||
},
|
||||
claims: map[string]any{
|
||||
claims: map[string]interface{}{
|
||||
"email": "[email protected]",
|
||||
"is_admin": true,
|
||||
},
|
||||
@@ -121,7 +120,7 @@ func TestTemplatedHeadersIntegration(t *testing.T) {
|
||||
headers: []TemplatedHeader{
|
||||
{Name: "X-Auth-Info", Value: "User={{.Claims.email}}, Token={{.AccessToken}}"},
|
||||
},
|
||||
claims: map[string]any{
|
||||
claims: map[string]interface{}{
|
||||
"email": "[email protected]",
|
||||
},
|
||||
expectedHeaders: map[string]string{
|
||||
@@ -134,7 +133,7 @@ func TestTemplatedHeadersIntegration(t *testing.T) {
|
||||
headers: []TemplatedHeader{
|
||||
{Name: "X-User-AccessToken", Value: "{{.AccessToken}}"},
|
||||
},
|
||||
claims: map[string]any{ // For ID Token
|
||||
claims: map[string]interface{}{ // For ID Token
|
||||
"email": "[email protected]",
|
||||
"sub": "opaque_sub_for_id_token",
|
||||
},
|
||||
@@ -150,7 +149,7 @@ func TestTemplatedHeadersIntegration(t *testing.T) {
|
||||
token := ts.token
|
||||
if len(tc.claims) > 0 {
|
||||
var err error
|
||||
baseClaims := map[string]any{
|
||||
baseClaims := map[string]interface{}{
|
||||
"iss": "https://test-issuer.com",
|
||||
"aud": "test-client-id",
|
||||
"exp": float64(3000000000), // Far future timestamp
|
||||
@@ -162,7 +161,9 @@ func TestTemplatedHeadersIntegration(t *testing.T) {
|
||||
}
|
||||
|
||||
// Add the test-specific claims
|
||||
maps.Copy(baseClaims, tc.claims)
|
||||
for k, v := range tc.claims {
|
||||
baseClaims[k] = v
|
||||
}
|
||||
|
||||
token, err = createTestJWT(ts.rsaPrivateKey, "RS256", "test-key-id", baseClaims)
|
||||
if err != nil {
|
||||
@@ -266,7 +267,7 @@ func TestTemplatedHeadersIntegration(t *testing.T) {
|
||||
session.SetRefreshToken("test-refresh-token")
|
||||
|
||||
if tc.name == "ID Token Header" || tc.name == "Both Token Types" {
|
||||
idTokenClaims := map[string]any{
|
||||
idTokenClaims := map[string]interface{}{
|
||||
"iss": "https://test-issuer.com", "aud": "test-client-id", "exp": float64(3000000000),
|
||||
"iat": float64(1000000000), "nbf": float64(1000000000), "sub": "test-subject",
|
||||
"nonce": "test-nonce", "jti": generateRandomString(16), "type": "id_token",
|
||||
@@ -284,7 +285,7 @@ func TestTemplatedHeadersIntegration(t *testing.T) {
|
||||
t.Fatalf("Failed to create test ID JWT: %v", idErr)
|
||||
}
|
||||
|
||||
accessTokenClaims := map[string]any{
|
||||
accessTokenClaims := map[string]interface{}{
|
||||
"iss": "https://test-issuer.com", "aud": "test-client-id", "exp": float64(3000000000),
|
||||
"iat": float64(1000000000), "nbf": float64(1000000000), "sub": "test-subject",
|
||||
"jti": generateRandomString(16), "type": "access_token", "scope": "openid email profile",
|
||||
@@ -315,13 +316,15 @@ func TestTemplatedHeadersIntegration(t *testing.T) {
|
||||
tc.expectedHeaders["X-Access-Token"] = accessTokenForSession
|
||||
}
|
||||
} else if tc.name == "Opaque Access Token with AccessTokenField" {
|
||||
idTokenClaims := map[string]any{
|
||||
idTokenClaims := map[string]interface{}{
|
||||
"iss": "https://test-issuer.com", "aud": "test-client-id", "exp": float64(3000000000),
|
||||
"iat": float64(1000000000), "nbf": float64(1000000000), "sub": "test-subject", // Default sub
|
||||
"nonce": "test-nonce", "jti": generateRandomString(16), "type": "id_token",
|
||||
}
|
||||
// Populate ID token claims from tc.claims
|
||||
maps.Copy(idTokenClaims, tc.claims)
|
||||
for k, v := range tc.claims {
|
||||
idTokenClaims[k] = v
|
||||
}
|
||||
// Ensure email from tc.claims is used for the ID token
|
||||
session.SetEmail(tc.claims["email"].(string)) // Also set it directly for initial session state
|
||||
|
||||
@@ -423,7 +426,7 @@ func TestEdgeCaseTemplatedHeaders(t *testing.T) {
|
||||
ts.Setup()
|
||||
|
||||
tests := []struct {
|
||||
claims map[string]any
|
||||
claims map[string]interface{}
|
||||
name string
|
||||
headers []TemplatedHeader
|
||||
shouldExecuteCheck bool
|
||||
@@ -444,8 +447,8 @@ func TestEdgeCaseTemplatedHeaders(t *testing.T) {
|
||||
headers: []TemplatedHeader{
|
||||
{Name: "X-Roles", Value: "{{range $i, $e := .Claims.roles}}{{if $i}},{{end}}{{$e}}{{end}}"},
|
||||
},
|
||||
claims: map[string]any{
|
||||
"roles": []any{"admin", "user", "manager"},
|
||||
claims: map[string]interface{}{
|
||||
"roles": []interface{}{"admin", "user", "manager"},
|
||||
},
|
||||
shouldExecuteCheck: true,
|
||||
},
|
||||
@@ -454,7 +457,7 @@ func TestEdgeCaseTemplatedHeaders(t *testing.T) {
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
// Create token with the test claims
|
||||
claims := map[string]any{
|
||||
claims := map[string]interface{}{
|
||||
"iss": "https://test-issuer.com",
|
||||
"aud": "test-client-id",
|
||||
"exp": float64(3000000000), // Far future timestamp
|
||||
@@ -466,7 +469,9 @@ func TestEdgeCaseTemplatedHeaders(t *testing.T) {
|
||||
}
|
||||
|
||||
// Add the test-specific claims
|
||||
maps.Copy(claims, tc.claims)
|
||||
for k, v := range tc.claims {
|
||||
claims[k] = v
|
||||
}
|
||||
|
||||
token, err := createTestJWT(ts.rsaPrivateKey, "RS256", "test-key-id", claims)
|
||||
if err != nil {
|
||||
@@ -571,7 +576,8 @@ func TestEdgeCaseTemplatedHeaders(t *testing.T) {
|
||||
// createLargeTemplate creates a template with many variable references
|
||||
func createLargeTemplate(size int) string {
|
||||
template := "{{with .Claims}}"
|
||||
for i := range size {
|
||||
for i := 0; i < size; i++ {
|
||||
|
||||
if i > 0 {
|
||||
template += ","
|
||||
}
|
||||
@@ -582,9 +588,9 @@ func createLargeTemplate(size int) string {
|
||||
}
|
||||
|
||||
// createLargeClaims creates a map with many claims for testing large templates
|
||||
func createLargeClaims(size int) map[string]any {
|
||||
claims := make(map[string]any)
|
||||
for i := range size {
|
||||
func createLargeClaims(size int) map[string]interface{} {
|
||||
claims := make(map[string]interface{})
|
||||
for i := 0; i < size; i++ {
|
||||
claims["email"] = "[email protected]" // Add email claim
|
||||
key := "field" + string(rune('a'+i%26)) + string(rune('0'+i%10))
|
||||
claims[key] = "value" + string(rune('a'+i%26)) + string(rune('0'+i%10))
|
||||
|
||||
Reference in New Issue
Block a user