mirror of
https://github.com/lukaszraczylo/traefikoidc.git
synced 2026-10-14 04:07:46 +00:00
Modernize run
This commit is contained in:
+16
-22
@@ -61,13 +61,10 @@ func (tt *TestTokens) CreateLargeValidJWT(targetSize int) string {
|
||||
|
||||
// Calculate required payload size
|
||||
usedSize := len(header) + len(signature) + 2 // account for dots
|
||||
payloadSize := targetSize - usedSize
|
||||
if payloadSize < 50 {
|
||||
payloadSize = 50
|
||||
}
|
||||
payloadSize := max(targetSize-usedSize, 50)
|
||||
|
||||
// Create a payload with realistic JWT claims
|
||||
claims := map[string]interface{}{
|
||||
claims := map[string]any{
|
||||
"sub": "user123",
|
||||
"iss": "https://example.com",
|
||||
"aud": "client123",
|
||||
@@ -76,10 +73,11 @@ func (tt *TestTokens) CreateLargeValidJWT(targetSize int) string {
|
||||
}
|
||||
|
||||
// FIXED: Calculate data size safely
|
||||
dataSize := payloadSize - 100 // Account for other claims and base64 encoding
|
||||
if dataSize < 10 {
|
||||
dataSize = 10 // Minimum data size
|
||||
}
|
||||
dataSize := max(
|
||||
// Account for other claims and base64 encoding
|
||||
payloadSize-100,
|
||||
// Minimum data size
|
||||
10)
|
||||
|
||||
claims["data"] = tt.generateRandomString(dataSize)
|
||||
|
||||
@@ -101,7 +99,7 @@ func (tt *TestTokens) CreateExpiredJWT() string {
|
||||
header := "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9"
|
||||
|
||||
// Create claims with expired timestamp
|
||||
claims := map[string]interface{}{
|
||||
claims := map[string]any{
|
||||
"sub": "user123",
|
||||
"iss": "https://example.com",
|
||||
"aud": "client123",
|
||||
@@ -120,7 +118,7 @@ func (tt *TestTokens) CreateExpiredJWT() string {
|
||||
func (tt *TestTokens) CreateUniqueValidJWT(id string) string {
|
||||
header := "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9"
|
||||
|
||||
claims := map[string]interface{}{
|
||||
claims := map[string]any{
|
||||
"sub": "user_" + id,
|
||||
"iss": "https://example.com",
|
||||
"aud": "client123",
|
||||
@@ -144,13 +142,10 @@ func (tt *TestTokens) CreateIncompressibleToken(targetSize int) string {
|
||||
|
||||
// Calculate required payload size
|
||||
usedSize := len(header) + len(signature) + 2 // account for dots
|
||||
payloadSize := targetSize - usedSize
|
||||
if payloadSize < 100 {
|
||||
payloadSize = 100
|
||||
}
|
||||
payloadSize := max(targetSize-usedSize, 100)
|
||||
|
||||
// Generate multiple random fields to prevent compression
|
||||
randomFields := make(map[string]interface{})
|
||||
randomFields := make(map[string]any)
|
||||
randomFields["sub"] = "user123"
|
||||
randomFields["iss"] = "https://example.com"
|
||||
randomFields["aud"] = "client123"
|
||||
@@ -159,10 +154,9 @@ func (tt *TestTokens) CreateIncompressibleToken(targetSize int) string {
|
||||
|
||||
// Add many random fields with random data to prevent compression
|
||||
remainingSize := payloadSize - 200 // Account for base64 encoding and other fields
|
||||
fieldCount := remainingSize / 100 // ~100 bytes per field
|
||||
if fieldCount < 1 {
|
||||
fieldCount = 1
|
||||
}
|
||||
fieldCount := max(
|
||||
// ~100 bytes per field
|
||||
remainingSize/100, 1)
|
||||
|
||||
for i := 0; i < fieldCount; i++ {
|
||||
// Generate truly random data for each field
|
||||
@@ -302,7 +296,7 @@ func (ts *TestScenarios) CorruptionTest() CorruptionTestSet {
|
||||
// ConcurrentTest returns unique tokens for concurrent testing
|
||||
func (ts *TestScenarios) ConcurrentTest(count int) []TokenSet {
|
||||
sets := make([]TokenSet, count)
|
||||
for i := 0; i < count; i++ {
|
||||
for i := range count {
|
||||
sets[i] = TokenSet{
|
||||
AccessToken: ts.tokens.CreateUniqueValidJWT(fmt.Sprintf("concurrent_%d", i)),
|
||||
IDToken: ts.tokens.CreateUniqueValidJWT(fmt.Sprintf("id_%d", i)),
|
||||
@@ -393,5 +387,5 @@ func AssertInvalidTokenRejection(t TestingInterface, session *SessionData, token
|
||||
|
||||
// TestingInterface provides the minimal interface needed for testing
|
||||
type TestingInterface interface {
|
||||
Errorf(format string, args ...interface{})
|
||||
Errorf(format string, args ...any)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user