(t *testing.T)
| 31 | t.Fatalf("oauth fields should be cleared: %+v", account) |
| 32 | } |
| 33 | wantMachine := MachineIdFromAPIKey("ksk_test_key") |
| 34 | if account.MachineId != wantMachine { |
| 35 | t.Fatalf("machineId = %q, want %q", account.MachineId, wantMachine) |
| 36 | } |
| 37 | if !IsAPIKeyAccount(&account) { |
| 38 | t.Fatal("expected IsAPIKeyAccount true") |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | func TestAddAccountRejectsDuplicateAPIKey(t *testing.T) { |
| 43 | if err := Init(filepath.Join(t.TempDir(), "config.json")); err != nil { |
| 44 | t.Fatalf("init config: %v", err) |
| 45 | } |
| 46 | first := Account{ID: "api-1", KiroApiKey: "ksk_dup", AuthMethod: "api_key", Enabled: true} |
| 47 | if err := AddAccount(first); err != nil { |
| 48 | t.Fatalf("add first: %v", err) |
| 49 | } |
| 50 | second := Account{ID: "api-2", KiroApiKey: "ksk_dup", AuthMethod: "api_key", Enabled: true} |
| 51 | if err := AddAccount(second); err != ErrDuplicateAPIKey { |
| 52 | t.Fatalf("expected ErrDuplicateAPIKey, got %v", err) |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | func TestSplitKiroAPIKeyAndRegionValidation(t *testing.T) { |
| 57 | key, region, err := SplitKiroAPIKeyAndRegion("ksk_abc|us-east-1") |
| 58 | if err != nil || key != "ksk_abc" || region != "us-east-1" { |
| 59 | t.Fatalf("got key=%q region=%q err=%v", key, region, err) |
nothing calls this directly
no test coverage detected