mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-12-06 11:03:52 +00:00
test(auth): pin the oidc override reload on cached tokens
A users file reload that renames an override or changes its limits already reaches a cached token on the next request. The cached principal stores the override object, and a reload builds a new object. The new test uses the same token across two reloads. It checks the new name, the new limits, the accounting name, and that no extra key fetch happens.
This commit is contained in:
@@ -242,3 +242,38 @@ func TestOIDC_XAPIKeyNotTreatedAsToken(t *testing.T) {
|
||||
t.Fatalf("discovery hits = %d, want 0", d)
|
||||
}
|
||||
}
|
||||
|
||||
// A reload that renames an override or changes its limits must reach a token
|
||||
// that is already cached, on the very next request.
|
||||
func TestOIDC_ReloadReachesCachedTokenNameAndLimits(t *testing.T) {
|
||||
fx := newOIDCGateway(t, nil)
|
||||
tok := fx.token(t, nil)
|
||||
reload := func(name string, rpm int64) {
|
||||
t.Helper()
|
||||
err := fx.gw.auth.replaceFileUsers([]*UserConfig{{Name: name, OIDCIdentity: "[email protected]", Limits: &LimitsConfig{RequestsPerMinute: rpm}}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
reload("alice-a", 5)
|
||||
if rec := fx.chat(t, tok); rec.Code != http.StatusOK {
|
||||
t.Fatalf("status %d", rec.Code)
|
||||
}
|
||||
if fx.userRequests("alice-a") != 1 {
|
||||
t.Fatal("first request must be accounted to alice-a")
|
||||
}
|
||||
reload("alice-b", 7)
|
||||
u, _, st := fx.gw.auth.authenticate(adminRequest(http.MethodPost, "/v1/chat/completions", tok))
|
||||
if st != authOK || u.name != "alice-b" || u.limits.RequestsPerMinute != 7 {
|
||||
t.Fatalf("status %v user %+v, want the renamed override with its new limits", st, u)
|
||||
}
|
||||
if rec := fx.chat(t, tok); rec.Code != http.StatusOK {
|
||||
t.Fatalf("status %d", rec.Code)
|
||||
}
|
||||
if fx.userRequests("alice-b") != 1 {
|
||||
t.Fatal("request after the rename must be accounted to alice-b")
|
||||
}
|
||||
if hits := fx.idp.jwksHits.Load(); hits != 1 {
|
||||
t.Fatalf("jwks hits = %d: the token must stay cached across the reload", hits)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user