Row-level security hid every row from the data changes in migrations 00009 and 00012: existing members did not receive the Viewer role and the built-in Admin role lacked tokens.manage. Built-in roles were also not writable in the system scope. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
36 lines
871 B
Go
36 lines
871 B
Go
package migrations
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"slices"
|
|
"testing"
|
|
|
|
"github.com/jackc/pgx/v5"
|
|
)
|
|
|
|
// TestDataMigrationsApply catches data changes that row-level security
|
|
// silently filtered out, as happened to 00009 and 00012.
|
|
func TestDataMigrationsApply(t *testing.T) {
|
|
dsn := os.Getenv("UPTIME_TEST_DATABASE_URL")
|
|
if dsn == "" {
|
|
t.Skip("UPTIME_TEST_DATABASE_URL not set")
|
|
}
|
|
ctx := context.Background()
|
|
if _, err := Up(ctx, dsn); err != nil {
|
|
t.Fatalf("Up() failed: %v", err)
|
|
}
|
|
conn, err := pgx.Connect(ctx, dsn)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer func() { _ = conn.Close(ctx) }()
|
|
var perms []string
|
|
if err := conn.QueryRow(ctx, `SELECT permissions FROM roles WHERE key = 'admin'`).Scan(&perms); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !slices.Contains(perms, "tokens.manage") {
|
|
t.Errorf("admin role permissions = %v, want tokens.manage", perms)
|
|
}
|
|
}
|