GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — meter/accounts_test.go at main · andybons/meter Expand file tree/ Copy pathaccounts_test.goMore file actions 150 lines (137 loc) · 4.48 KB / Copy pathaccounts_test.goFile metadata and controls150 lines (137 loc) · 4.48 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 package main import ( "os" "path/filepath" "strings" "testing" "time" ) // testAccounts is a fixed set used by tests that need accounts. func testAccounts() []*Account { return []*Account{ } } func TestKeychainService(t *testing.T) { // Claude Code suffixes the service with sha256(dir)[:8] for custom dirs. for _, c := range []struct{ dir, want string }{ {"", "Claude Code-credentials"}, {"/home/u/[email protected]", "Claude Code-credentials-aa24287f"}, } { a := &Account{Provider: Claude, Dir: c.dir} if got := a.keychainService(); got != c.want { t.Errorf("dir %q: got %q, want %q", c.dir, got, c.want) } } } func TestEnvStripsKeysAndSetsDir(t *testing.T) { t.Setenv("CLAUDE_CONFIG_DIR", "/bogus") t.Setenv("ANTHROPIC_API_KEY", "x") t.Setenv("OPENAI_API_KEY", "x") for _, a := range testAccounts() { var got string for _, kv := range a.Env() { for _, bad := range []string{"ANTHROPIC_API_KEY=", "OPENAI_API_KEY=", "CLAUDE_CONFIG_DIR=/bogus"} { if strings.HasPrefix(kv, bad) { t.Errorf("%s %s: env leaks %s", a.Provider, a.Email, bad) } } if strings.HasPrefix(kv, a.envVar()+"=") { got = strings.TrimPrefix(kv, a.envVar()+"=") } } if got != a.Dir { t.Errorf("%s %s: %s=%q, want %q", a.Provider, a.Email, a.envVar(), got, a.Dir) } } } func TestLoadConfig(t *testing.T) { path := filepath.Join(t.TempDir(), "config.toml") os.WriteFile(path, []byte(` refresh = "1m" [[claude]] email = "[email protected]" [[claude]] email = "[email protected]" dir = "~/[email protected]/" [[codex]] email = "[email protected]" `), 0o644) accs, refresh, err := loadConfig(path) if err != nil { t.Fatal(err) } if refresh != time.Minute { t.Errorf("refresh = %v", refresh) } if len(accs) != 3 { t.Fatalf("got %d accounts", len(accs)) } if accs[0].Dir != "" || accs[2].Provider != Codex { t.Errorf("unexpected accounts: %+v", accs) } // ~ expanded and trailing slash cleaned, so the Keychain hash matches. t.Errorf("dir = %q, want %q", accs[1].Dir, want) } } func TestLoadConfigErrors(t *testing.T) { for name, body := range map[string]string{ "missing email": "[[claude]]\ndir = \"~/.claude-x\"\n", "relative dir": "[[claude]]\nemail = \"[email protected]\"\ndir = \"rel\"\n", "duplicate dir": "[[codex]]\nemail = \"[email protected]\"\n[[codex]]\nemail = \"[email protected]\"\n", "bad refresh": "refresh = \"soon\"\n", } { path := filepath.Join(t.TempDir(), "config.toml") os.WriteFile(path, []byte(body), 0o644) if _, _, err := loadConfig(path); err == nil { t.Errorf("%s: expected error", name) } } } func TestWindowLabel(t *testing.T) { for secs, want := range map[int64]string{604800: "Weekly", 18000: "Session", 172800: "2d window"} { if got := windowLabel(secs); got != want { t.Errorf("windowLabel(%d) = %q, want %q", secs, got, want) } } } func TestJWTClaims(t *testing.T) { // header.{"exp":1700000000,"email":"[email protected]"}.sig tok := "e30.eyJleHAiOjE3MDAwMDAwMDAsImVtYWlsIjoiYUBleGFtcGxlLmNvbSJ9.x" if got := jwtExpiry(tok); !got.Equal(time.Unix(1700000000, 0)) { t.Errorf("jwtExpiry = %v", got) } t.Errorf("email = %q", got) } } func TestFmtInterval(t *testing.T) { for _, c := range []struct { d time.Duration want string }{{30 * time.Second, "30s"}, {time.Minute, "1m"}, {10 * time.Minute, "10m"}} { if got := fmtInterval(c.d); got != c.want { t.Errorf("fmtInterval(%v) = %q, want %q", c.d, got, c.want) } } } func TestClaudePlan(t *testing.T) { for _, c := range []struct{ sub, tier, want string }{ {"max", "default_claude_max_20x", "ultra"}, {"max", "default_claude_max_5x", "max 5x"}, {"team", "default_claude_team_5x", "team 5x"}, {"pro", "default_claude_pro", "pro"}, } { o := map[string]any{"subscriptionType": c.sub, "rateLimitTier": c.tier} if got := claudePlan(o); got != c.want { t.Errorf("claudePlan(%q, %q) = %q, want %q", c.sub, c.tier, got, c.want) } } } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |