admin) allow local login user management (#39)
All checks were successful
Build and Push Image / docker-build-and-push (push) Successful in 2m28s
All checks were successful
Build and Push Image / docker-build-and-push (push) Successful in 2m28s
Co-authored-by: Shaun Campbell <shaun@campbellwireless.net> Reviewed-on: #39 Co-authored-by: AI Agent <ai-agent@campbellwireless.net> Co-committed-by: AI Agent <ai-agent@campbellwireless.net>
This commit was merged in pull request #39.
This commit is contained in:
@@ -2,8 +2,10 @@ import { beforeEach, afterEach, describe, expect, it } from 'vitest';
|
||||
import { setupTestDb } from '../../tests/helpers.js';
|
||||
import type { Database } from './db/types.js';
|
||||
import {
|
||||
createLocalUser,
|
||||
deleteUser,
|
||||
listUsers,
|
||||
setLocalPasswordForUser,
|
||||
updateUser,
|
||||
upsertUserFromAuth,
|
||||
upsertUserProfile
|
||||
@@ -100,3 +102,50 @@ describe('deleteUser', () => {
|
||||
expect(listUsers().find((item) => item.id === 'u4')).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('createLocalUser', () => {
|
||||
it('creates a local user with credentials', async () => {
|
||||
const created = await createLocalUser({
|
||||
username: 'local-user',
|
||||
fullName: 'Local User',
|
||||
email: 'local@example.com',
|
||||
password: 'averysecurepassword'
|
||||
});
|
||||
expect(created.username).toBe('local-user');
|
||||
expect(created.auth_source).toBe('Local');
|
||||
const row = database.get<{ user_id: string; password_hash: string }>(
|
||||
'SELECT user_id, password_hash FROM local_credentials WHERE user_id = ?',
|
||||
[created.id]
|
||||
);
|
||||
expect(row?.user_id).toBe(created.id);
|
||||
expect(row?.password_hash).toBeTruthy();
|
||||
});
|
||||
|
||||
it('rejects duplicate usernames', async () => {
|
||||
await createLocalUser({
|
||||
username: 'dup-user',
|
||||
fullName: 'Dup User',
|
||||
password: 'averysecurepassword'
|
||||
});
|
||||
await expect(
|
||||
createLocalUser({
|
||||
username: 'dup-user',
|
||||
fullName: 'Dup User Two',
|
||||
password: 'averysecurepassword'
|
||||
})
|
||||
).rejects.toThrow('Username already exists');
|
||||
});
|
||||
});
|
||||
|
||||
describe('setLocalPasswordForUser', () => {
|
||||
it('sets local credentials for an existing user', async () => {
|
||||
upsertUserFromAuth({ id: 'u5', username: 'sarah', fullName: 'Sarah Lee' });
|
||||
await setLocalPasswordForUser('u5', 'averysecurepassword');
|
||||
const row = database.get<{ user_id: string; password_hash: string }>(
|
||||
'SELECT user_id, password_hash FROM local_credentials WHERE user_id = ?',
|
||||
['u5']
|
||||
);
|
||||
expect(row?.user_id).toBe('u5');
|
||||
expect(row?.password_hash).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user