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

+71 -2
View File
@@ -9,6 +9,7 @@ import (
"context"
"database/sql"
"errors"
"fmt"
"strconv"
"strings"
"sync"
@@ -28,6 +29,11 @@ func TestIntegrationContractCheck(t *testing.T) {
{"missing column", itOptions{prefix: "coredns_", recordDDL: strings.Replace(itRecordsDDL, " `ttl` INT DEFAULT NULL,\n", "", 1)}, "has no column ttl"},
{"incompatible type", itOptions{prefix: "coredns_", recordDDL: strings.Replace(itRecordsDDL, "`ttl` INT DEFAULT NULL", "`ttl` VARCHAR(10) DEFAULT NULL", 1)}, "column ttl of table coredns_records has incompatible type varchar"},
{"incompatible content", itOptions{prefix: "coredns_", recordDDL: strings.Replace(itRecordsDDL, "`content` TEXT", "`content` BLOB", 1)}, "column content of table coredns_records has incompatible type blob"},
{"wide id", itOptions{prefix: "coredns_", recordDDL: strings.Replace(itRecordsDDL, "`id` INT", "`id` BIGINT", 1)}, "column id of table coredns_records has incompatible type bigint"},
{"narrow ttl", itOptions{prefix: "coredns_", recordDDL: strings.Replace(itRecordsDDL, "`ttl` INT", "`ttl` MEDIUMINT", 1)}, "column ttl of table coredns_records has incompatible type mediumint"},
{"short zone", itOptions{prefix: "coredns_", recordDDL: strings.Replace(itRecordsDDL, "`zone` VARCHAR(255)", "`zone` VARCHAR(254)", 1)}, "column zone of table coredns_records has incompatible type varchar(254)"},
{"short name", itOptions{prefix: "coredns_", recordDDL: strings.Replace(itRecordsDDL, "`name` VARCHAR(255)", "`name` VARCHAR(254)", 1)}, "column name of table coredns_records has incompatible type varchar(254)"},
{"short type", itOptions{prefix: "coredns_", recordDDL: strings.Replace(itRecordsDDL, "`record_type` VARCHAR(255)", "`record_type` VARCHAR(8)", 1)}, "column record_type of table coredns_records has incompatible type varchar(8)"},
}
for _, c := range cases {
d := newITDatabase(t, c.opts)
@@ -58,13 +64,76 @@ func TestIntegrationContractCheck(t *testing.T) {
t.Fatalf("prefix %q: %v", prefix, err)
}
}
bigint := strings.NewReplacer("`id` INT", "`id` BIGINT", "`zone` VARCHAR(255)", "`zone` TEXT", "`content` TEXT", "`content` JSON").Replace(itRecordsDDL)
d := newITDatabase(t, itOptions{prefix: "coredns_", recordDDL: bigint})
compatible := strings.NewReplacer("`id` INT", "`id` INT UNSIGNED", "`ttl` INT", "`ttl` BIGINT", "`zone` VARCHAR(255)", "`zone` TEXT",
"`name` VARCHAR(255)", "`name` MEDIUMTEXT", "`content` TEXT", "`content` JSON", "`record_type` VARCHAR(255)", "`record_type` VARCHAR(9)").Replace(itRecordsDDL)
d := newITDatabase(t, itOptions{prefix: "coredns_", recordDDL: compatible})
if err := verifyRecordsContract(ctx, d.openApp(t), d.tables(t), discardLogger()); err != nil {
t.Fatalf("compatible types refused: %v", err)
}
}
func TestIntegrationMigrationRestartsAfterEveryDDL(t *testing.T) {
const prefix = "resume_"
migrations, err := loadMigrations(migrationFiles, prefix)
if err != nil {
t.Fatal(err)
}
statements := migrations[0].statements
for boundary := 1; boundary <= len(statements); boundary++ {
t.Run(fmt.Sprintf("after_ddl_%d", boundary), func(t *testing.T) {
d := newITDatabase(t, itOptions{prefix: prefix})
tn := d.tables(t)
db := d.openApp(t)
ctx := t.Context()
for _, stmt := range statements[:boundary] {
if _, err := db.ExecContext(ctx, stmt); err != nil {
t.Fatal(err)
}
}
if v, err := schemaVersion(ctx, db, tn); err != nil || v != 0 {
t.Fatalf("interrupted schema version = %d, %v", v, err)
}
if err := db.Close(); err != nil {
t.Fatal(err)
}
db, tn = d.migrated(t)
if v, err := schemaVersion(ctx, db, tn); err != nil || v != 1 {
t.Fatalf("restarted schema version = %d, %v", v, err)
}
if n := d.count(t, "SELECT COUNT(*) FROM information_schema.REFERENTIAL_CONSTRAINTS WHERE CONSTRAINT_SCHEMA = DATABASE()"); n != 5 {
t.Fatalf("restarted schema has %d foreign keys", n)
}
})
}
t.Run("invalid_existing_table", func(t *testing.T) {
d := newITDatabase(t, itOptions{prefix: prefix})
db, tn := d.migrated(t)
d.rootExec(t, tn.sql("ALTER TABLE {sessions} DROP COLUMN user_agent"))
err := migrateDatabase(t.Context(), db, tn, discardLogger())
if err == nil || !strings.Contains(err.Error(), "has no column user_agent") {
t.Fatalf("accepted incomplete application schema: %v", err)
}
})
t.Run("invalid_column_width", func(t *testing.T) {
d := newITDatabase(t, itOptions{prefix: prefix})
db, tn := d.migrated(t)
d.rootExec(t, tn.sql("ALTER TABLE {users} MODIFY password_hash VARCHAR(15) NOT NULL"))
err := migrateDatabase(t.Context(), db, tn, discardLogger())
if err == nil || !strings.Contains(err.Error(), "has type varchar(15), expected varchar(255)") {
t.Fatalf("accepted invalid column width: %v", err)
}
})
t.Run("missing_foreign_key", func(t *testing.T) {
d := newITDatabase(t, itOptions{prefix: prefix})
db, tn := d.migrated(t)
d.rootExec(t, tn.sql("ALTER TABLE {audit} DROP FOREIGN KEY resume_webui_audit_ibfk_2"))
err := migrateDatabase(t.Context(), db, tn, discardLogger())
if err == nil || !strings.Contains(err.Error(), "expected 5 foreign keys") {
t.Fatalf("accepted missing audit foreign key: %v", err)
}
})
}
func TestIntegrationMigrations(t *testing.T) {
t.Parallel()
ctx := context.Background()