server: auth schema, keys, sessions, connection registry (#17)

This commit is contained in:
2026-11-14 22:13:04 +01:00
parent c89c8eab42
commit e612db5826
11 changed files with 915 additions and 13 deletions
+32
View File
@@ -0,0 +1,32 @@
## Data-dir lock (#17): an exclusive advisory lock in the state dir outlives nothing by accident.
## Contention between two processes is exercised by the Node harness (the server holds it while
## `gm-key --new` must refuse); in-process fcntl locks are per process, so only acquire/release here.
import std/[unittest, os, strutils]
import instancelock
proc tmpDir(): string =
result = getTempDir() / "ffflock-" & $getCurrentProcessId()
removeDir(result)
createDir(result)
suite "instance lock":
test "acquires, creates the lock file, releases and re-acquires":
let d = tmpDir()
defer: removeDir(d)
var lock = tryAcquire(d)
check lock.held
check fileExists(d / InstanceLockName)
check readFile(d / InstanceLockName).strip == $getCurrentProcessId()
lock.release()
check not lock.held
var again = tryAcquire(d)
check again.held
again.release()
test "release is idempotent":
let d = tmpDir()
defer: removeDir(d)
var lock = tryAcquire(d)
lock.release()
lock.release()
check not lock.held