Files
CLIProxyAPI/internal/auth/codex/filename_test.go
T
Luis Pater 505c59d8c9 fix(auth): prevent credential overwrites for team-scoped plans with account hashing
- Updated `CredentialFileName` to include trimmed `hashAccountID` for team-scoped plans.
- Added `isTeamScopedPlan` helper to handle plan-specific logic.
- Ensured filenames are unique across emails for multiple teams.

Closes: #4075
2026-07-08 04:50:56 +08:00

65 lines
1.9 KiB
Go

package codex
import "testing"
func TestCredentialFileName(t *testing.T) {
tests := []struct {
name string
email string
planType string
hashAccountID string
includeProviderPrefix bool
want string
}{
{
name: "team includes account hash",
email: "[email protected]",
planType: "team",
hashAccountID: "abc12345",
includeProviderPrefix: true,
want: "[email protected]",
},
{
name: "k12 includes account hash",
email: "[email protected]",
planType: "k12",
hashAccountID: "def67890",
includeProviderPrefix: true,
want: "[email protected]",
},
{
name: "k12 without account hash falls back to email and plan",
email: "[email protected]",
planType: "k12",
hashAccountID: "",
includeProviderPrefix: true,
want: "[email protected]",
},
{
name: "plus ignores account hash",
email: " [email protected] ",
planType: "Plus",
hashAccountID: "abc12345",
includeProviderPrefix: true,
want: "[email protected]",
},
{
name: "plan is normalized",
email: "[email protected]",
planType: " Team Plan ",
hashAccountID: "abc12345",
includeProviderPrefix: true,
want: "[email protected]",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := CredentialFileName(tt.email, tt.planType, tt.hashAccountID, tt.includeProviderPrefix)
if got != tt.want {
t.Fatalf("CredentialFileName() = %q, want %q", got, tt.want)
}
})
}
}