Skip to content

Commit 9ecb789

Browse files
Add test file for test publish settings
1 parent 20bd79d commit 9ecb789

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package core
2+
3+
import (
4+
"encoding/json"
5+
"strings"
6+
"testing"
7+
"time"
8+
)
9+
10+
func TestSettingValueMask(t *testing.T) {
11+
tests := []struct { input string; expected string }{
12+
{"", "****"},
13+
{"a", "a****a"},
14+
{"abcdefghi", "abcd****fghi"},
15+
{"sk_test_abc12345xyz", "sk_t****45xyz"},
16+
}
17+
for _, tt := range tests {
18+
got := SettingValueMask(tt.input)
19+
if got != tt.expected {
20+
t.Errorf("SettingValueMask(%q) = %q, want %q", tt.input, got, tt.expected)
21+
}
22+
}
23+
}
24+
25+
func TestCheckForEnvCollision(t *testing.T) {
26+
for _, name := range []string{"GITHUB_TOKEN","ADMIN_EMAIL","ADMIN_PASSWORD","PAYPAL_CLIENT_ID","GEMINI_API_KEYS"} {
27+
if err := checkForEnvCollision(name); err == nil {
28+
t.Errorf("expected collision for %q", name)
29+
}
30+
}
31+
if err := checkForEnvCollision("MERGEOS_FOO"); err == nil {
32+
t.Error("expected collision for MERGEOS_* prefix")
33+
}
34+
if err := checkForEnvCollision("my-custom-key"); err != nil {
35+
t.Errorf("unexpected error: %v", err)
36+
}
37+
}
38+
39+
func TestTestSettingsStore(t *testing.T) {
40+
store := newTestStore(t)
41+
defer store.Close()
42+
43+
enabled := true
44+
_, err := store.UpdateTestSettingsConfig(UpdateTestSettingsRequest{
45+
TestModeEnabled: &enabled,
46+
TestPassword: "test123",
47+
})
48+
if err != nil { t.Fatal(err) }
49+
if !store.GetTestSettingsConfig().TestModeEnabled { t.Error("expected enabled") }
50+
if !store.VerifyTestPassword("test123") { t.Error("password should match") }
51+
if store.VerifyTestPassword("wrong") { t.Error("wrong pw should fail") }
52+
53+
entry, err := store.AddTestSettingsEntry(AddTestEntryRequest{
54+
IntegrationType: "llm", SettingKey: "OPENAI_KEY", SettingValue: "sk-proj-abc",
55+
})
56+
if err != nil { t.Fatal(err) }
57+
if entry.SettingValueHint != SettingValueMask("sk-proj-abc") {
58+
t.Errorf("bad mask: %q", entry.SettingValueHint)
59+
}
60+
61+
_, err = store.AddTestSettingsEntry(AddTestEntryRequest{
62+
IntegrationType: "env", SettingKey: "GITHUB_TOKEN", SettingValue: "xxx",
63+
})
64+
if err == nil { t.Error("expected env collision error") }
65+
}

0 commit comments

Comments
 (0)