feat(backend): boxSettings table + box password actions
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { normalizeBoxPassword } from '../../convex/boxPassword';
|
||||
|
||||
describe('normalizeBoxPassword', () => {
|
||||
it('treats null/empty as an explicit clear', () => {
|
||||
expect(normalizeBoxPassword(null)).toEqual({ ok: true, value: null });
|
||||
expect(normalizeBoxPassword(undefined)).toEqual({ ok: true, value: null });
|
||||
expect(normalizeBoxPassword('')).toEqual({ ok: true, value: null });
|
||||
});
|
||||
|
||||
it('enforces the 8..128 length bounds', () => {
|
||||
expect(normalizeBoxPassword('short')).toMatchObject({ ok: false });
|
||||
expect(normalizeBoxPassword('a'.repeat(7))).toMatchObject({ ok: false });
|
||||
expect(normalizeBoxPassword('a'.repeat(8))).toEqual({
|
||||
ok: true,
|
||||
value: 'a'.repeat(8),
|
||||
});
|
||||
expect(normalizeBoxPassword('a'.repeat(128))).toMatchObject({ ok: true });
|
||||
expect(normalizeBoxPassword('a'.repeat(129))).toMatchObject({ ok: false });
|
||||
});
|
||||
|
||||
it('rejects control characters that would corrupt the chpasswd stdin line', () => {
|
||||
expect(normalizeBoxPassword('has\nnewline1')).toMatchObject({ ok: false });
|
||||
expect(normalizeBoxPassword('has\ttab-char1')).toMatchObject({ ok: false });
|
||||
});
|
||||
|
||||
it('allows colons and spaces (chpasswd splits on the first colon only)', () => {
|
||||
expect(normalizeBoxPassword('pa:ss wo:rd')).toEqual({
|
||||
ok: true,
|
||||
value: 'pa:ss wo:rd',
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user