oauth_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package openai
  2. import (
  3. "net/url"
  4. "sync"
  5. "testing"
  6. "time"
  7. )
  8. func TestSessionStore_Stop_Idempotent(t *testing.T) {
  9. store := NewSessionStore()
  10. store.Stop()
  11. store.Stop()
  12. select {
  13. case <-store.stopCh:
  14. // ok
  15. case <-time.After(time.Second):
  16. t.Fatal("stopCh 未关闭")
  17. }
  18. }
  19. func TestSessionStore_Stop_Concurrent(t *testing.T) {
  20. store := NewSessionStore()
  21. var wg sync.WaitGroup
  22. for range 50 {
  23. wg.Add(1)
  24. go func() {
  25. defer wg.Done()
  26. store.Stop()
  27. }()
  28. }
  29. wg.Wait()
  30. select {
  31. case <-store.stopCh:
  32. // ok
  33. case <-time.After(time.Second):
  34. t.Fatal("stopCh 未关闭")
  35. }
  36. }
  37. func TestBuildAuthorizationURLForPlatform_OpenAI(t *testing.T) {
  38. authURL := BuildAuthorizationURLForPlatform("state-1", "challenge-1", DefaultRedirectURI, OAuthPlatformOpenAI)
  39. parsed, err := url.Parse(authURL)
  40. if err != nil {
  41. t.Fatalf("Parse URL failed: %v", err)
  42. }
  43. q := parsed.Query()
  44. if got := q.Get("client_id"); got != ClientID {
  45. t.Fatalf("client_id mismatch: got=%q want=%q", got, ClientID)
  46. }
  47. if got := q.Get("codex_cli_simplified_flow"); got != "true" {
  48. t.Fatalf("codex flow mismatch: got=%q want=true", got)
  49. }
  50. if got := q.Get("id_token_add_organizations"); got != "true" {
  51. t.Fatalf("id_token_add_organizations mismatch: got=%q want=true", got)
  52. }
  53. }