mirror of
https://github.com/lukaszraczylo/traefikoidc.git
synced 2026-10-12 04:04:26 +00:00
Under yaegi, the authenticated cookie path allocated about 3.8 MB per request. A yaegi harness measures bytes per request with a browser-like cookie jar. With it, these changes cut bytes by 83%, allocations by 69% and time by about 93%. - Replace range loops over tokens with index loops. Under yaegi, ranging over a string allocates O(n^2) bytes. - Pool gzip readers for combined session cookies. - Memoize the validated ID token within one request. - Cache content-only token validation across requests. The key is the token type and SHA-256, and the cache holds at most 4096 entries. The entry keeps the parsed exp and iat claims. The expiry and freshness checks still run on every request. New tests pin the validator results, the memo and the cache behavior.
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package traefikoidc
|
|
|
|
import (
|
|
"sync"
|
|
"testing"
|
|
)
|
|
|
|
func TestDecompressCombinedPayloadReusesReaders(t *testing.T) {
|
|
var readers sync.Pool
|
|
first, err := compressCombinedPayload(&combinedSessionPayload{Ui: "[email protected]"})
|
|
if err != nil {
|
|
t.Fatalf("compress first: %v", err)
|
|
}
|
|
second, err := compressCombinedPayload(&combinedSessionPayload{Ui: "[email protected]"})
|
|
if err != nil {
|
|
t.Fatalf("compress second: %v", err)
|
|
}
|
|
|
|
cases := []struct {
|
|
name string
|
|
input string
|
|
wantUser string
|
|
wantErr bool
|
|
}{
|
|
{"first payload", first, "[email protected]", false},
|
|
{"corrupt payload rejected", "bm90LWd6aXA=", "", true},
|
|
{"second payload after corrupt one", second, "[email protected]", false},
|
|
{"first payload again", first, "[email protected]", false},
|
|
}
|
|
for _, tc := range cases {
|
|
got, err := decompressCombinedPayload(tc.input, &readers)
|
|
if tc.wantErr {
|
|
if err == nil {
|
|
t.Fatalf("%s: expected error", tc.name)
|
|
}
|
|
continue
|
|
}
|
|
if err != nil {
|
|
t.Fatalf("%s: %v", tc.name, err)
|
|
}
|
|
if got.Ui != tc.wantUser {
|
|
t.Fatalf("%s: user = %q, want %q", tc.name, got.Ui, tc.wantUser)
|
|
}
|
|
}
|
|
}
|