Sub2API v1.0 - AI API 网关(二开初始版本,基于上游 Wei-Shaw/sub2api)
Release / update-version (push) Has been cancelled
Release / build-frontend (push) Has been cancelled
Release / release (push) Has been cancelled
Release / sync-version-file (push) Has been cancelled
CI / shell (push) Canceled after 0s
CI / test (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
Security Scan / backend-security (push) Canceled after 0s
Security Scan / frontend-security (push) Canceled after 0s
Release / update-version (push) Has been cancelled
Release / build-frontend (push) Has been cancelled
Release / release (push) Has been cancelled
Release / sync-version-file (push) Has been cancelled
CI / shell (push) Canceled after 0s
CI / test (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
Security Scan / backend-security (push) Canceled after 0s
Security Scan / frontend-security (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestAuthorizeURLMatchesClaudeCodeCLI(t *testing.T) {
|
||||
const want = "https://claude.com/cai/oauth/authorize"
|
||||
if AuthorizeURL != want {
|
||||
t.Fatalf("AuthorizeURL = %q, want %q", AuthorizeURL, want)
|
||||
}
|
||||
|
||||
authURL := BuildAuthorizationURL("state-value", "challenge-value", ScopeOAuth)
|
||||
if !strings.HasPrefix(authURL, want+"?") {
|
||||
t.Fatalf("BuildAuthorizationURL() = %q, want prefix %q", authURL, want+"?")
|
||||
}
|
||||
for _, part := range []string{
|
||||
"code=true",
|
||||
"client_id=" + ClientID,
|
||||
"response_type=code",
|
||||
"code_challenge=challenge-value",
|
||||
"code_challenge_method=S256",
|
||||
"state=state-value",
|
||||
} {
|
||||
if !strings.Contains(authURL, part) {
|
||||
t.Fatalf("BuildAuthorizationURL() missing %q\nURL: %s", part, authURL)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSessionStore_Stop_Idempotent(t *testing.T) {
|
||||
store := NewSessionStore()
|
||||
|
||||
store.Stop()
|
||||
store.Stop()
|
||||
|
||||
select {
|
||||
case <-store.stopCh:
|
||||
// ok
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("stopCh 未关闭")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSessionStore_Stop_Concurrent(t *testing.T) {
|
||||
store := NewSessionStore()
|
||||
|
||||
var wg sync.WaitGroup
|
||||
for range 50 {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
store.Stop()
|
||||
}()
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
select {
|
||||
case <-store.stopCh:
|
||||
// ok
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("stopCh 未关闭")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user