test(ui): avoid a literal em dash in the em dash check

- test(ui): avoid a literal em dash in the em dash check
- fix(cli): accept any positive int64 audit count and share the last active admin rule
- fix(api): limit audit before_id to 2^53-1
- fix(api): audit unmatched api requests, bound every request body and record audit write failures
- fix(ui): recheck the account in the login transaction and require existing zones on zone pages
- fix(api): recheck the acting admin and the stored password hash in change transactions
- fix(db): keep committed outcomes on lock release failure, narrow the records contract and trace sql statements
- fix(db): make the initial migration restartable and verify the application schema
- fix(auth): never move last_seen_at backwards on concurrent session touches
- test(api): cover lock release failure after commit and handler tracing without secrets
- fix(test): redact credentials from mysql setup errors
- fix(audit): retain addressed objects on admin refusals
- test(db): cover migration restarts and records contract ranges in mysql
- test(api): verify account races and audit rollback in mysql
- fix(auth): reject password changes after account deletion
- docs: document unknown api audit entries
- fix(audit): bound failure retries and redact sensitive sql parameters
- fix(test): isolate docker resources and cover image cli commands
- test(auth): expect unauthorized after an account deletion race
- fix(db): verify application column widths and foreign keys
This commit is contained in:
bryanpedini committed 2026-11-19 15:46:12 +01:00
1 parent 5f17aab6ca
commit 53444bec7a
40 files changed
+2332 -254

No files matched your search

+70
View File
@@ -98,6 +98,18 @@ type migrationDB struct {
failErr error
executedDDL []string
versionWrite []any
schemaChange func(rows [][]driver.Value) [][]driver.Value
}
func appSchemaRows(prefix string, change func(rows [][]driver.Value) [][]driver.Value) [][]driver.Value {
var rows [][]driver.Value
for _, c := range appSchema {
rows = append(rows, []driver.Value{prefix + c.table, c.column, strings.ToUpper(c.columnType)})
}
if change != nil {
rows = change(rows)
}
return rows
}
func (m *migrationDB) handler(q string, args []any) fdbResponse {
@@ -125,6 +137,10 @@ func (m *migrationDB) handler(q string, args []any) fdbResponse {
case strings.HasPrefix(q, "CREATE TABLE"):
m.executedDDL = append(m.executedDDL, q)
return fdbResponse{}
case strings.Contains(q, "information_schema.COLUMNS"):
return fdbResponse{rows: appSchemaRows("coredns_", m.schemaChange)}
case strings.Contains(q, "information_schema.KEY_COLUMN_USAGE"):
return fdbResponse{rows: fdbRow(int64(5))}
}
return fdbResponse{err: errors.New("unexpected query " + q)}
}
@@ -248,3 +264,57 @@ func TestMigrateDatabase(t *testing.T) {
t.Fatal("invalid prefix accepted")
}
}
func TestVerifyAppSchema(t *testing.T) {
ctx := context.Background()
m := &migrationDB{tableCount: 0}
db, st := newFakeDB(t, m.handler)
if err := migrateDatabase(ctx, db, fdbTables(t), discardLogger()); err != nil {
t.Fatal(err)
}
var verify fdbCall
for _, c := range st.Calls() {
if strings.Contains(c.query, "information_schema.COLUMNS") {
verify = c
}
}
if len(verify.args) != 5 || verify.args[0] != "coredns_webui_schema" || verify.args[4] != "coredns_webui_audit" {
t.Fatalf("%+v", verify)
}
all, err := loadMigrations(migrationFiles, "coredns_")
if err != nil {
t.Fatal(err)
}
for _, migration := range all {
for _, stmt := range migration.statements {
if !strings.HasPrefix(stmt, "CREATE TABLE IF NOT EXISTS ") {
t.Fatalf("%s: not idempotent: %.60s", migration.name, stmt)
}
}
}
cases := map[string]func(rows [][]driver.Value) [][]driver.Value{
"table coredns_webui_audit has no column after_value": func(rows [][]driver.Value) [][]driver.Value { return rows[:len(rows)-1] },
"column id of table coredns_webui_users has type bigint, expected int": func(rows [][]driver.Value) [][]driver.Value {
for _, r := range rows {
if r[0] == "coredns_webui_users" && r[1] == "id" {
r[2] = "bigint"
}
}
return rows
},
"table coredns_webui_schema has no column id": func([][]driver.Value) [][]driver.Value { return nil },
}
for want, change := range cases {
m := &migrationDB{tableCount: 1, version: int64(1), schemaChange: change}
db, _ := newFakeDB(t, m.handler)
if err := migrateDatabase(ctx, db, fdbTables(t), discardLogger()); err == nil || !strings.Contains(err.Error(), want) {
t.Fatalf("%s: %v", want, err)
}
}
for _, fail := range []fdbResponse{{err: errors.New("boom")}, {rows: [][]driver.Value{{"t", nil, "int"}}}} {
db, _ := newFakeDB(t, fdbRules(fdbRule{"information_schema.COLUMNS", fail}))
if err := verifyAppSchema(ctx, db, fdbTables(t), discardLogger()); err == nil || !strings.Contains(err.Error(), "read application schema") {
t.Fatal(err)
}
}
}