| 1 | package workbench |
| 2 | |
| 3 | import ( |
| 4 | "github.com/sylvinus/agent-vm/internal/cage" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestAutomaticRegionSettingsPreserveManualOverrides(t *testing.T) { |
| 9 | cfg := cage.DefaultConfig() |
| 10 | loc := Location{CountryCode: "JP", Timezone: "Asia/Tokyo"} |
| 11 | manual := autoRegionSettings(cfg, Preferences{}, loc) |
| 12 | if manual != cfg { |
| 13 | t.Fatal("location changed manually selected settings") |
| 14 | } |
| 15 | tzOnly := autoRegionSettings(cfg, Preferences{AutoTimezone: true}, loc) |
| 16 | if tzOnly.Timezone != "Asia/Tokyo" || tzOnly.Locale != cfg.Locale { |
| 17 | t.Fatal("timezone option changed language") |
| 18 | } |
| 19 | languageOnly := autoRegionSettings(cfg, Preferences{AutoLanguage: true}, loc) |
| 20 | if languageOnly.Locale != "ja_JP.UTF-8" || languageOnly.BrowserLanguage != "ja-JP" || languageOnly.Timezone != cfg.Timezone { |
| 21 | t.Fatal("language option did not preserve independent timezone") |
| 22 | } |
| 23 | unknown := autoRegionSettings(cfg, Preferences{AutoLanguage: true}, Location{CountryCode: "ZZ"}) |
| 24 | if unknown != cfg { |
| 25 | t.Fatal("unknown region invented a language setting") |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | func TestMissingExitPolicyDoesNotRelaxSavedStaticRule(t *testing.T) { |
| 30 | s := testServer(t) |
| 31 | old := cage.DefaultConfig() |
| 32 | old.ExitPolicy = cage.ExitPolicy{Mode: "static", Scope: "country", IP: "8.8.8.8"} |
| 33 | input := settingsView(old, Preferences{Keyboard: "mac"}) |
| 34 | input.ExitPolicy = cage.ExitPolicy{} |
| 35 | got, _, err := proposedSettings(input, old, s.profile) |
| 36 | if err != nil { |
| 37 | t.Fatal(err) |
| 38 | } |
| 39 | if got.ExitPolicy != old.ExitPolicy { |
| 40 | t.Fatal("legacy form silently relaxed static IP") |
| 41 | } |
| 42 | } |