Support a separate database for Web UI tables
This commit is contained in:
1 parent
a2f8e59d9b
commit
f464dc0af9
38 files changed
+880
-302
No files matched your search
+14
-14
@@ -41,7 +41,7 @@ func TestIntegrationUserCLI(t *testing.T) {
|
||||
t.Fatalf("%d %q", code, cli.stderr.String())
|
||||
}
|
||||
var hash string
|
||||
if err := d.root.QueryRow("SELECT `password_hash` FROM `coredns_webui_users` WHERE `username` = 'alice'").Scan(&hash); err != nil || hash != "$test$first password here" {
|
||||
if err := d.root.QueryRow(d.sql("SELECT `password_hash` FROM {users} WHERE `username` = 'alice'")).Scan(&hash); err != nil || hash != "$test$first password here" {
|
||||
t.Fatal(hash, err)
|
||||
}
|
||||
if code := cli.run("user", "list"); code != 0 {
|
||||
@@ -59,14 +59,14 @@ func TestIntegrationUserCLI(t *testing.T) {
|
||||
if code := cli.run("user", "delete", "alice"); code != 1 || !strings.Contains(cli.stderr.String(), "last active admin") {
|
||||
t.Fatalf("%d %q", code, cli.stderr.String())
|
||||
}
|
||||
bobID := int64(d.count(t, "SELECT `id` FROM `coredns_webui_users` WHERE `username` = 'bob'"))
|
||||
d.rootExec(t, "INSERT INTO `coredns_webui_sessions` VALUES (UNHEX(SHA2('a', 256)), ?, NOW(6), NOW(6), NOW(6), 'x', 'y')", bobID)
|
||||
d.rootExec(t, "INSERT INTO `coredns_webui_sessions` VALUES (UNHEX(SHA2('b', 256)), ?, NOW(6), NOW(6), NOW(6), 'x', 'y')", bobID)
|
||||
bobID := int64(d.count(t, "SELECT `id` FROM {users} WHERE `username` = 'bob'"))
|
||||
d.rootExec(t, "INSERT INTO {sessions} VALUES (UNHEX(SHA2('a', 256)), ?, NOW(6), NOW(6), NOW(6), 'x', 'y')", bobID)
|
||||
d.rootExec(t, "INSERT INTO {sessions} VALUES (UNHEX(SHA2('b', 256)), ?, NOW(6), NOW(6), NOW(6), 'x', 'y')", bobID)
|
||||
cli = d.cli(t, "new bob password\n", now.Add(time.Minute))
|
||||
if code := cli.run("user", "passwd", "bob"); code != 0 {
|
||||
t.Fatalf("%d %q", code, cli.stderr.String())
|
||||
}
|
||||
if d.count(t, "SELECT COUNT(*) FROM `coredns_webui_sessions`") != 0 {
|
||||
if d.count(t, "SELECT COUNT(*) FROM {sessions}") != 0 {
|
||||
t.Fatal("sessions survived passwd")
|
||||
}
|
||||
if code := cli.run("user", "role", "bob", "admin"); code != 0 {
|
||||
@@ -75,14 +75,14 @@ func TestIntegrationUserCLI(t *testing.T) {
|
||||
if code := cli.run("user", "role", "alice", "user"); code != 0 {
|
||||
t.Fatalf("%d %q", code, cli.stderr.String())
|
||||
}
|
||||
d.rootExec(t, "INSERT INTO `coredns_webui_sessions` VALUES (UNHEX(SHA2('c', 256)), (SELECT `id` FROM `coredns_webui_users` WHERE `username` = 'alice'), NOW(6), NOW(6), NOW(6), 'x', 'y')")
|
||||
d.rootExec(t, "INSERT INTO {sessions} VALUES (UNHEX(SHA2('c', 256)), (SELECT `id` FROM {users} WHERE `username` = 'alice'), NOW(6), NOW(6), NOW(6), 'x', 'y')")
|
||||
if code := cli.run("user", "delete", "alice"); code != 0 {
|
||||
t.Fatalf("%d %q", code, cli.stderr.String())
|
||||
}
|
||||
if d.count(t, "SELECT COUNT(*) FROM `coredns_webui_sessions`") != 0 {
|
||||
if d.count(t, "SELECT COUNT(*) FROM {sessions}") != 0 {
|
||||
t.Fatal("sessions survived delete")
|
||||
}
|
||||
if d.count(t, "SELECT COUNT(*) FROM `coredns_webui_users` WHERE `username` = 'alice' AND `deleted_at` IS NOT NULL") != 1 {
|
||||
if d.count(t, "SELECT COUNT(*) FROM {users} WHERE `username` = 'alice' AND `deleted_at` IS NOT NULL") != 1 {
|
||||
t.Fatal("deleted user row missing")
|
||||
}
|
||||
for _, args := range [][]string{{"user", "passwd", "alice"}, {"user", "role", "alice", "admin"}, {"user", "delete", "alice"}, {"user", "passwd", "nobody"}} {
|
||||
@@ -99,7 +99,7 @@ func TestIntegrationUserCLI(t *testing.T) {
|
||||
t.Fatalf("%d\n%s", code, cli.stdout.String())
|
||||
}
|
||||
|
||||
rows, err := d.root.Query("SELECT `user_id`, `actor`, `origin`, `operation`, `status`, `error`, `zone`, `record_id`, `target_user_id`, `before_value`, `after_value` FROM `coredns_webui_audit` ORDER BY `id`")
|
||||
rows, err := d.root.Query(d.sql("SELECT `user_id`, `actor`, `origin`, `operation`, `status`, `error`, `zone`, `record_id`, `target_user_id`, `before_value`, `after_value` FROM {audit} ORDER BY `id`"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -163,10 +163,10 @@ func TestIntegrationLastAdminRace(t *testing.T) {
|
||||
if codes[0]+codes[1] != 1 {
|
||||
t.Fatalf("round %d: exit codes %v", round, codes)
|
||||
}
|
||||
if n := d.count(t, "SELECT COUNT(*) FROM `coredns_webui_users` WHERE `role` = 'admin' AND `deleted_at` IS NULL"); n != 1 {
|
||||
if n := d.count(t, "SELECT COUNT(*) FROM {users} WHERE `role` = 'admin' AND `deleted_at` IS NULL"); n != 1 {
|
||||
t.Fatalf("round %d: %d active admins", round, n)
|
||||
}
|
||||
if n := d.count(t, "SELECT COUNT(*) FROM `coredns_webui_audit` WHERE `operation` IN ('user_role', 'user_delete')"); n != 1 {
|
||||
if n := d.count(t, "SELECT COUNT(*) FROM {audit} WHERE `operation` IN ('user_role', 'user_delete')"); n != 1 {
|
||||
t.Fatalf("round %d: %d change rows", round, n)
|
||||
}
|
||||
}
|
||||
@@ -179,10 +179,10 @@ func TestIntegrationCheckAndAuditCommands(t *testing.T) {
|
||||
if code := c.run("check"); code != 0 || c.stdout.String() != "ZONE NAME TYPE ID SEVERITY PROBLEM\n" {
|
||||
t.Fatalf("%d %q %q", code, c.stdout.String(), c.stderr.String())
|
||||
}
|
||||
if d.count(t, "SELECT `version` FROM `dns_webui_schema`") != 2 {
|
||||
if d.count(t, "SELECT `version` FROM {schema}") != 2 {
|
||||
t.Fatal("check did not migrate")
|
||||
}
|
||||
d.rootExec(t, "INSERT INTO `dns_records` (`zone`, `name`, `ttl`, `content`, `record_type`) VALUES ('example.org.', 'www', NULL, '{\"ip\": \"192.0.2.1\"}', 'A')")
|
||||
d.rootExec(t, "INSERT INTO {records} (`zone`, `name`, `ttl`, `content`, `record_type`) VALUES ('example.org.', 'www', NULL, '{\"ip\": \"192.0.2.1\"}', 'A')")
|
||||
c = d.cli(t, "", time.Now())
|
||||
if code := c.run("check", "EXAMPLE.org"); code != 3 || !strings.Contains(c.stdout.String(), "ttl_null") || !strings.Contains(c.stdout.String(), "soa_missing") {
|
||||
t.Fatalf("%d %q %q", code, c.stdout.String(), c.stderr.String())
|
||||
@@ -240,7 +240,7 @@ func TestIntegrationServer(t *testing.T) {
|
||||
if results["/health"] != `200 OK {"status":"ok"}` || !strings.Contains(results["/version"], "CoreDNS Web UI") {
|
||||
t.Fatalf("%v", results)
|
||||
}
|
||||
if d.count(t, "SELECT `version` FROM `coredns_webui_schema`") != 2 {
|
||||
if d.count(t, "SELECT `version` FROM {schema}") != 2 {
|
||||
t.Fatal("server did not migrate")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user