fix(17): T-17-15 refuse an unsafe frontend_url on save and import

- Settings.BeforeValidate answers a cabana validation error on
  frontend_url, so the settings save is a 422 and the row is unchanged
- sitemap:import-winter stops on a frontend_url that
  models.AllowedFrontendURL refuses, before the dry-run branch and before
  any database use; the value is printed quoted
- errors.frontend_url phrase in en and pl
- TestSettingsBeforeValidate, TestWinterSettingsFrontendURL and the save
  and import refusals in the Postgres smokes
This commit is contained in:
Jakub Zych
2026-10-13 00:59:24 +02:00
parent b9804ddf17
commit 1bb89ce006
9 changed files with 204 additions and 8 deletions

View File

@@ -213,5 +213,19 @@ func TestImportWinter(t *testing.T) {
if err := e.gdb.Find(&rows).Error; err != nil || models.Text(rows[0].FrontendURL) != "https://other.example.test" {
t.Fatalf("the dry run changed the settings: %+v %v", rows, err)
}
// T-17-15: a frontend_url that is not a plain http(s) URL stops the
// import, also as a dry run, and the row keeps its value.
quoted, _ := json.Marshal(map[string]string{"frontend_url": `https://x"/><y a="`})
unsafe := writeFile(t, dir, "settings4.json", string(quoted))
for _, dryRun := range []bool{false, true} {
report, out, err := run(console.WinterOptions{SettingsFile: unsafe, DryRun: dryRun})
if err == nil || !strings.Contains(err.Error(), "frontend_url") || report.Settings {
t.Fatalf("unsafe frontend_url (dry run %v): %+v %v\n%s", dryRun, report, err, out)
}
if err := e.gdb.Find(&rows).Error; err != nil || len(rows) != 1 || models.Text(rows[0].FrontendURL) != "https://other.example.test" {
t.Fatalf("a refused import (dry run %v) changed the settings: %+v %v", dryRun, rows, err)
}
}
})
}