mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-11-19 15:03:21 +00:00
fix: enrich OpenAI OAuth token refresh
This commit is contained in:
1 parent
1d46be02ae
commit
eba2046320
6 files changed
+164
-26
No files matched your search
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/Wei-Shaw/sub2api/internal/pkg/openai"
|
||||
"github.com/imroc/req/v3"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -32,6 +33,11 @@ func (s *openaiOAuthClientRefreshStub) RefreshTokenWithClientID(ctx context.Cont
|
||||
func TestOpenAIOAuthService_RefreshAccountToken_NoRefreshTokenUsesExistingAccessToken(t *testing.T) {
|
||||
client := &openaiOAuthClientRefreshStub{}
|
||||
svc := NewOpenAIOAuthService(nil, client)
|
||||
var privacyClientCalls int32
|
||||
svc.SetPrivacyClientFactory(func(proxyURL string) (*req.Client, error) {
|
||||
atomic.AddInt32(&privacyClientCalls, 1)
|
||||
return nil, errors.New("stop before request")
|
||||
})
|
||||
|
||||
expiresAt := time.Now().Add(30 * time.Minute).UTC().Format(time.RFC3339)
|
||||
account := &Account{
|
||||
@@ -51,6 +57,7 @@ func TestOpenAIOAuthService_RefreshAccountToken_NoRefreshTokenUsesExistingAccess
|
||||
require.Equal(t, "existing-access-token", info.AccessToken)
|
||||
require.Equal(t, "client-id-1", info.ClientID)
|
||||
require.Zero(t, atomic.LoadInt32(&client.refreshCalls), "existing access token should be reused without calling refresh")
|
||||
require.Positive(t, atomic.LoadInt32(&privacyClientCalls), "existing access token should still run enrichment")
|
||||
}
|
||||
|
||||
func TestOpenAITokenRefresher_NeedsRefresh_SkipsAccountWithoutRefreshToken(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user