返回 DeepSeek-Reasonix
authentication_auxiliary_test.go
根目录 / internal / control / authentication_auxiliary_test.go
1 package control
2
3 import (
4 "context"
5 "fmt"
6 "testing"
7
8 "reasonix/internal/event"
9 "reasonix/internal/provider"
10 )
11
12 func TestAuditTitleAuthenticationRejectionStopsFurtherRequests(t *testing.T) {
13 for _, explicitModel := range []bool{false, true} {
14 t.Run(fmt.Sprint(explicitModel), func(t *testing.T) {
15 prov := &sessionTitleProviderStub{err: &provider.AuthError{Provider: "test", Status: 401, HasKey: true}}
16 ctrl := sessionTitleTestController(t, prov, event.Discard)
17 for range 2 {
18 var err error
19 if explicitModel {
20 _, err = ctrl.GenerateSessionTitleForModel(context.Background(), "test/title-model", "test title")
21 } else {
22 _, err = ctrl.GenerateSessionTitle(context.Background(), "test title")
23 }
24 if err == nil {
25 t.Fatal("expected provider rejection")
26 }
27 }
28 if len(prov.requests) != 1 {
29 t.Fatalf("authentication rejection allowed %d title requests without explicit retry", len(prov.requests))
30 }
31 })
32 }
33 }
34
35 func TestAuxiliaryAuthenticationFailureIsScopedToConnectionAndModel(t *testing.T) {
36 gate := newAuthenticationGate(AuthenticationState{Status: AuthenticationReady}, "main/chat")
37 gate.recordFailure(&provider.AuthError{Provider: "other", Status: 401}, "other/title")
38 if err := gate.admissionError(); err != nil {
39 t.Fatalf("other connection blocked main chat: %v", err)
40 }
41 if err := gate.admissionErrorForModel("other/title"); err == nil {
42 t.Fatal("failed title connection was not blocked")
43 }
44 gate.recordFailure(&provider.AuthError{Provider: "main", Status: 403}, "main/title")
45 if err := gate.admissionError(); err != nil {
46 t.Fatalf("title-only 403 blocked chat: %v", err)
47 }
48 if err := gate.admissionErrorForModel("main/title"); err == nil {
49 t.Fatal("failed title model was not blocked")
50 }
51 gate.recordFailure(&provider.AuthError{Provider: "main", Status: 401}, "main/title")
52 if err := gate.admissionError(); err == nil {
53 t.Fatal("same-connection 401 did not block chat")
54 }
55 }
56
56 lines GO