feat: add proxy labels and default profiles
This commit is contained in:
@@ -112,6 +112,28 @@ func TestDefaultPathForExecutableUsesExecutableDirectory(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefaultInstanceUserDataDirectoryUsesExecutableDirectoryAndStableID(t *testing.T) {
|
||||
executable := filepath.Join(t.TempDir(), "published", "chub.exe")
|
||||
root, err := defaultInstanceUserDataRootForExecutable(executable)
|
||||
if err != nil || root != filepath.Join(filepath.Dir(executable), "user_data_dirs") {
|
||||
t.Fatalf("defaultInstanceUserDataRootForExecutable() = %q, %v", root, err)
|
||||
}
|
||||
first, err := defaultInstanceUserDataDir(root, "instance-one")
|
||||
if err != nil || first != filepath.Join(root, "instance-one") {
|
||||
t.Fatalf("defaultInstanceUserDataDir() = %q, %v", first, err)
|
||||
}
|
||||
second, err := defaultInstanceUserDataDir(root, "instance-two")
|
||||
if err != nil || second == first {
|
||||
t.Fatalf("distinct instance directory = %q, %v", second, err)
|
||||
}
|
||||
if _, err := defaultInstanceUserDataRootForExecutable("chub.exe"); !errors.Is(err, ErrDefaultConfigUnavailable) {
|
||||
t.Fatalf("relative executable root error = %v", err)
|
||||
}
|
||||
if _, err := defaultInstanceUserDataDir(root, `..\other`); !errors.Is(err, ErrDefaultConfigUnavailable) {
|
||||
t.Fatalf("unsafe instance id error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpenDefaultAtMigratesValidLegacyWithoutRemovingIt(t *testing.T) {
|
||||
directory := t.TempDir()
|
||||
target := filepath.Join(directory, "portable", "config.json")
|
||||
@@ -249,6 +271,23 @@ func TestStoreRoundTripsReferencedProxyWithoutCredentials(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStoreRejectsBlankOrDuplicateProxyNamesAndServers(t *testing.T) {
|
||||
store, err := New(filepath.Join(t.TempDir(), "config.json"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, proxies := range [][]ProxyProfile{
|
||||
{{ID: "blank", Name: " ", Server: "http://127.0.0.1:8080"}},
|
||||
{{ID: "one", Name: "新加坡", Server: "http://127.0.0.1:8080"}, {ID: "two", Name: "新加坡", Server: "http://127.0.0.1:8081"}},
|
||||
{{ID: "one", Name: "Singapore", Server: "http://127.0.0.1:8080"}, {ID: "two", Name: "sINGAPORE", Server: "http://127.0.0.1:8081"}},
|
||||
{{ID: "one", Name: "新加坡", Server: "http://127.0.0.1:8080"}, {ID: "two", Name: "东京", Server: "HTTP://127.0.0.1:8080"}},
|
||||
} {
|
||||
if err := store.Save(File{Proxies: proxies}); err == nil {
|
||||
t.Fatalf("unsafe proxy profiles persisted: %#v", proxies)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestStoreMigratesLegacyProxyAndRejectsUnsafeConfig(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "config.json")
|
||||
if err := os.WriteFile(path, []byte(`{"version":1,"settings":{},"instances":[{"id":"a","name":"运营","launch":{"Kind":"chrome","UserDataDir":"C:\\profiles\\a","ProxyServer":"http://127.0.0.1:8080"}}]}`), 0o600); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user