2022-11-07 14:54:24 +00:00
|
|
|
import std/unittest
|
|
|
|
import std/os
|
2023-08-01 23:47:57 +00:00
|
|
|
import pkg/questionable
|
2022-11-07 14:54:24 +00:00
|
|
|
import codex/utils/keyutils
|
2023-06-22 18:01:21 +00:00
|
|
|
import ../helpers
|
2022-11-07 14:54:24 +00:00
|
|
|
|
|
|
|
when defined(windows):
|
|
|
|
import stew/windows/acl
|
|
|
|
|
2023-06-22 18:01:21 +00:00
|
|
|
checksuite "keyutils":
|
2022-11-07 14:54:24 +00:00
|
|
|
let path = getTempDir() / "CodexTest"
|
|
|
|
|
|
|
|
setup:
|
|
|
|
os.createDir(path)
|
|
|
|
|
|
|
|
teardown:
|
|
|
|
os.removeDir(path)
|
|
|
|
|
|
|
|
test "creates a key file when it does not exist yet":
|
2023-08-01 23:47:57 +00:00
|
|
|
check setupKey(path / "keyfile").isOk
|
2022-11-07 14:54:24 +00:00
|
|
|
check fileExists(path / "keyfile")
|
|
|
|
|
|
|
|
test "stores key in a file that's only readable by the user":
|
2023-08-01 23:47:57 +00:00
|
|
|
discard setupKey(path / "keyfile").get()
|
2022-11-07 14:54:24 +00:00
|
|
|
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":
|
2023-08-01 23:47:57 +00:00
|
|
|
let key = setupKey(path / "keyfile").get()
|
|
|
|
check setupKey(path / "keyfile").get() == key
|
2022-11-07 14:54:24 +00:00
|
|
|
|