门禁兼容修复

This commit is contained in:
andy committed 2026-09-05 17:36:23 +08:00
1 parent f60b416949
commit 801c0af692
18 files changed
+257 -87

No files matched your search

+16
View File
@@ -19,6 +19,10 @@ const testChatToken = "abcdef0123456789abcdef0123456789"
func TestNewChatHandlerRejectsUnsafeOptions(t *testing.T) {
tests := []ChatOptions{
{AuthToken: "short", MaxBodyBytes: 1, RunTimeout: time.Second},
{AuthToken: "", AllowLegacyShortToken: true, MaxBodyBytes: 1, RunTimeout: time.Second},
{AuthToken: "delivered\tkey", AllowLegacyShortToken: true, MaxBodyBytes: 1, RunTimeout: time.Second},
{AuthToken: "delivered密钥", AllowLegacyShortToken: true, MaxBodyBytes: 1, RunTimeout: time.Second},
{AuthToken: strings.Repeat("a", 4097), AllowLegacyShortToken: true, MaxBodyBytes: 1, RunTimeout: time.Second},
{AuthToken: testChatToken, MaxBodyBytes: maximumChatBodyBytes + 1, RunTimeout: time.Second},
{AuthToken: testChatToken, MaxBodyBytes: 1, RunTimeout: maximumChatRunTime + time.Second},
{AuthToken: testChatToken, AllowedOrigins: []string{"*"}, MaxBodyBytes: 1, RunTimeout: time.Second},
@@ -31,6 +35,18 @@ func TestNewChatHandlerRejectsUnsafeOptions(t *testing.T) {
}
}
func TestNewChatHandlerAllowsExplicitLegacyShortToken(t *testing.T) {
_, err := NewChatHandler(&fakeChatUseCase{}, ChatOptions{
AuthToken: "delivered-key",
AllowLegacyShortToken: true,
MaxBodyBytes: 1,
RunTimeout: time.Second,
})
if err != nil {
t.Fatalf("NewChatHandler() error = %v", err)
}
}
func TestChatTransportGuardsRunBeforeService(t *testing.T) {
tests := []struct {
name string