package console import ( "bytes" "context" "encoding/json" "os" "path/filepath" "strings" "testing" "git.golem15.com/golem15/sm-sitemap-plugin/models" "git.golem15.com/golem15/summercms/modules/bonfire" ) // TestWinterSettingsFrontendURL pins the import check of T-17-15: a settings // export whose frontend_url models.AllowedFrontendURL refuses stops // sitemap:import-winter with an error naming the setting, with and without // --dry-run and before the database is used (the test passes none). An // accepted, empty, null or missing frontend_url is read as before. func TestWinterSettingsFrontendURL(t *testing.T) { dir := t.TempDir() n := 0 settingsFile := func(fields map[string]any) string { t.Helper() // json.Marshal encodes the quotes of the attack value. raw, err := json.Marshal(fields) if err != nil { t.Fatal(err) } n++ path := filepath.Join(dir, "settings-"+string(rune('a'+n))+".json") if err := os.WriteFile(path, raw, 0o644); err != nil { t.Fatal(err) } return path } for _, value := range []string{ "javascript:alert(document.domain)//", `https://x"/>