Changeset 0.24.0 (#156)
This commit is contained in:
13
server/database/migrations/018_auth_abstraction.sql
Normal file
13
server/database/migrations/018_auth_abstraction.sql
Normal file
@@ -0,0 +1,13 @@
|
||||
-- Chat Switchboard — 018 Auth Abstraction (v0.24.0)
|
||||
ALTER TABLE users
|
||||
ADD COLUMN IF NOT EXISTS auth_source VARCHAR(20) NOT NULL DEFAULT 'builtin'
|
||||
CHECK (auth_source IN ('builtin', 'mtls', 'oidc'));
|
||||
ALTER TABLE users ADD COLUMN IF NOT EXISTS external_id TEXT;
|
||||
ALTER TABLE users ADD COLUMN IF NOT EXISTS handle VARCHAR(100);
|
||||
ALTER TABLE users ALTER COLUMN password_hash DROP NOT NULL;
|
||||
UPDATE users SET handle = LOWER(REPLACE(REPLACE(username, ' ', '-'), '_', '-'))
|
||||
WHERE handle IS NULL;
|
||||
ALTER TABLE users ALTER COLUMN handle SET NOT NULL;
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_users_handle ON users(LOWER(handle));
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_users_external_id
|
||||
ON users(auth_source, external_id) WHERE external_id IS NOT NULL;
|
||||
@@ -0,0 +1,8 @@
|
||||
-- Chat Switchboard — 018 Auth Abstraction (SQLite) (v0.24.0)
|
||||
ALTER TABLE users ADD COLUMN auth_source TEXT NOT NULL DEFAULT 'builtin';
|
||||
ALTER TABLE users ADD COLUMN external_id TEXT;
|
||||
ALTER TABLE users ADD COLUMN handle TEXT;
|
||||
UPDATE users SET handle = LOWER(REPLACE(REPLACE(username, ' ', '-'), '_', '-'))
|
||||
WHERE handle IS NULL;
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_users_handle ON users(handle COLLATE NOCASE);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_users_external_id ON users(auth_source, external_id);
|
||||
@@ -356,12 +356,13 @@ func TruncateAll(t *testing.T) {
|
||||
// SeedTestUser creates a test user and returns the user ID.
|
||||
func SeedTestUser(t *testing.T, username, email string) string {
|
||||
t.Helper()
|
||||
handle := strings.ToLower(strings.ReplaceAll(username, " ", "-"))
|
||||
if IsSQLite() {
|
||||
id := uuid.New().String()
|
||||
_, err := DB.Exec(`
|
||||
INSERT INTO users (id, username, email, password_hash, role)
|
||||
VALUES (?, ?, ?, '$2a$10$dummy.hash.for.testing.only.000000000000000000000', 'user')
|
||||
`, id, username, email)
|
||||
INSERT INTO users (id, username, email, password_hash, role, auth_source, handle)
|
||||
VALUES (?, ?, ?, '$2a$10$dummy.hash.for.testing.only.000000000000000000000', 'user', 'builtin', ?)
|
||||
`, id, username, email, handle)
|
||||
if err != nil {
|
||||
t.Fatalf("SeedTestUser: %v", err)
|
||||
}
|
||||
@@ -369,10 +370,10 @@ func SeedTestUser(t *testing.T, username, email string) string {
|
||||
}
|
||||
var id string
|
||||
err := DB.QueryRow(`
|
||||
INSERT INTO users (username, email, password_hash, role)
|
||||
VALUES ($1, $2, '$2a$10$dummy.hash.for.testing.only.000000000000000000000', 'user')
|
||||
INSERT INTO users (username, email, password_hash, role, auth_source, handle)
|
||||
VALUES ($1, $2, '$2a$10$dummy.hash.for.testing.only.000000000000000000000', 'user', 'builtin', $3)
|
||||
RETURNING id
|
||||
`, username, email).Scan(&id)
|
||||
`, username, email, handle).Scan(&id)
|
||||
if err != nil {
|
||||
t.Fatalf("SeedTestUser: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user