E M d62fbf5d52
WIP renaming
# Conflicts:
#	library/libstorage.nim

# Conflicts:
#	storage/rest/api.nim
#	storage/storage.nim
2026-02-19 15:08:16 +11:00

34 lines
849 B
Nim

import std/os
import pkg/unittest2
import pkg/storage/utils/keyutils
import ../helpers
when defined(windows):
import stew/windows/acl
suite "keyutils":
let path = getTempDir() / "StorageTest"
setup:
os.createDir(path)
teardown:
os.removeDir(path)
test "creates a key file when it does not exist yet":
check setupKey(path / "keyfile").isOk
check fileExists(path / "keyfile")
test "stores key in a file that's only readable by the user":
discard setupKey(path / "keyfile").get()
when defined(posix):
check getFilePermissions(path / "keyfile") == {fpUserRead, fpUserWrite}
when defined(windows):
check checkCurrentUserOnlyACL(path / "keyfile").get()
test "reads key file when it does exist":
let key = setupKey(path / "keyfile").get()
check setupKey(path / "keyfile").get() == key