fix(oauth): hide completed sessions from legacy getter

This commit is contained in:
Supra4E8C
2026-07-10 16:17:01 +08:00
parent f081b91e57
commit d1ef06cb5e
2 changed files with 18 additions and 1 deletions
@@ -259,7 +259,7 @@ func CompletePluginOAuthSessionsByProvider(provider string) int {
func GetOAuthSession(state string) (provider string, status string, ok bool) {
session, ok := oauthSessions.Get(state)
if !ok {
if !ok || session.Completed {
return "", "", false
}
return session.Provider, session.Status, true
@@ -26,6 +26,23 @@ func TestOAuthSessionStoreCompleteKeepsShortLivedSession(t *testing.T) {
}
}
func TestGetOAuthSessionHidesCompletedSession(t *testing.T) {
store := newOAuthSessionStore(time.Minute)
replaceOAuthSessionStoreForTest(t, store)
store.Register("completed-state", "codex")
store.Complete("completed-state")
provider, status, ok := GetOAuthSession("completed-state")
if ok {
t.Fatalf("GetOAuthSession() = (%q, %q, true), want completed session hidden", provider, status)
}
_, _, _, _, completed, detailsOK := GetOAuthSessionDetails("completed-state")
if !detailsOK || !completed {
t.Fatalf("GetOAuthSessionDetails() completed/ok = %t/%t, want true/true", completed, detailsOK)
}
}
func TestGetAuthStatusRejectsUnknownStateAndAcceptsCompletedState(t *testing.T) {
store := newOAuthSessionStore(time.Minute)
replaceOAuthSessionStoreForTest(t, store)