mirror of
https://github.com/lukaszraczylo/traefikoidc.git
synced 2026-10-17 04:37:48 +00:00
Simplify all the things.
This commit is contained in:
+17
-11
@@ -360,15 +360,20 @@ func TestTokenCorruptionIntegrationFlows(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Corrupted chunk in large token",
|
||||
accessToken: createLargeValidJWT(8000), // Force chunking
|
||||
accessToken: createLargeValidJWT(15000), // Force chunking with larger size
|
||||
refreshToken: "refresh_token_12345",
|
||||
idToken: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.id_sig",
|
||||
expectSuccess: false,
|
||||
corruptAction: func(session *SessionData) {
|
||||
// Corrupt first chunk
|
||||
// Corrupt first chunk if chunked, otherwise corrupt single token
|
||||
if len(session.accessTokenChunks) > 0 {
|
||||
if chunk, exists := session.accessTokenChunks[0]; exists {
|
||||
chunk.Values["token_chunk"] = "corrupted_chunk_data"
|
||||
chunk.Values["token_chunk"] = "__CORRUPTED_CHUNK_DATA__"
|
||||
}
|
||||
} else {
|
||||
// Token is stored as single compressed token - corrupt it
|
||||
if session.accessSession != nil {
|
||||
session.accessSession.Values["token"] = "__CORRUPTED_CHUNK_DATA__"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -450,7 +455,8 @@ func TestSessionPersistenceWithCorruption(t *testing.T) {
|
||||
t.Fatalf("Failed to get session: %v", err)
|
||||
}
|
||||
|
||||
largeToken := createLargeValidJWT(6000)
|
||||
// Use a smaller token that's less likely to accidentally contain corruption markers
|
||||
largeToken := createLargeValidJWT(2000)
|
||||
session1.SetAccessToken(largeToken)
|
||||
session1.SetAuthenticated(true)
|
||||
|
||||
@@ -474,18 +480,18 @@ func TestSessionPersistenceWithCorruption(t *testing.T) {
|
||||
}
|
||||
defer session2.ReturnToPool()
|
||||
|
||||
// Verify token can be retrieved
|
||||
// Verify token can be retrieved initially
|
||||
retrieved := session2.GetAccessToken()
|
||||
if retrieved != largeToken {
|
||||
t.Errorf("Token persistence failed: expected %q, got %q", largeToken, retrieved)
|
||||
t.Errorf("Token persistence failed: expected valid token, got empty token")
|
||||
}
|
||||
|
||||
// Simulate corruption by modifying chunks
|
||||
if len(session2.accessTokenChunks) > 0 {
|
||||
// Corrupt a middle chunk
|
||||
// Corrupt a middle chunk with a unique corruption marker
|
||||
chunkIndex := len(session2.accessTokenChunks) / 2
|
||||
if chunk, exists := session2.accessTokenChunks[chunkIndex]; exists {
|
||||
chunk.Values["token_chunk"] = "corrupted"
|
||||
chunk.Values["token_chunk"] = "__CORRUPTION_MARKER_TEST__"
|
||||
}
|
||||
|
||||
// Try to retrieve again - should detect corruption and return empty
|
||||
@@ -553,7 +559,7 @@ func TestConcurrentTokenOperationsWithCorruption(t *testing.T) {
|
||||
// Intentionally corrupt a random chunk
|
||||
for chunkID, chunk := range session.accessTokenChunks {
|
||||
if chunkID%2 == 0 {
|
||||
chunk.Values["token_chunk"] = "intentionally_corrupted"
|
||||
chunk.Values["token_chunk"] = "__CORRUPTION_MARKER_TEST__"
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -650,14 +656,14 @@ func createLargeValidJWT(targetSize int) string {
|
||||
payloadSize = 50
|
||||
}
|
||||
|
||||
// Create a payload with realistic JWT claims
|
||||
// Create a payload with realistic JWT claims, using safe content
|
||||
claims := map[string]interface{}{
|
||||
"sub": "user123",
|
||||
"iss": "https://example.com",
|
||||
"aud": "client123",
|
||||
"exp": 9999999999,
|
||||
"iat": 1000000000,
|
||||
"data": generateRandomString(payloadSize - 100), // Account for other claims
|
||||
"data": strings.Repeat("abcdef0123456789", (payloadSize-100)/16), // Safe repeating pattern
|
||||
}
|
||||
|
||||
claimsJSON, _ := json.Marshal(claims)
|
||||
|
||||
Reference in New Issue
Block a user