2022-07-18 11:02:40 +00:00
|
|
|
# Copyright (c) 2020-2022 Status Research & Development GmbH
|
|
|
|
# Licensed and distributed under either of
|
|
|
|
# * MIT license: http://opensource.org/licenses/MIT
|
|
|
|
# * Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
|
|
|
{.used.}
|
|
|
|
|
2022-07-08 09:34:21 +00:00
|
|
|
import unittest2
|
2020-10-15 12:27:58 +00:00
|
|
|
|
|
|
|
when defined(windows):
|
|
|
|
import ../stew/windows/acl
|
|
|
|
|
|
|
|
suite "Windows security descriptor tests suite":
|
|
|
|
test "File/Folder user-only ACL create/verify test":
|
|
|
|
when defined(windows):
|
|
|
|
proc performTest(path1: string, path2: string): IoResult[bool] =
|
2020-10-20 14:43:38 +00:00
|
|
|
let path3 = path1 & "\\" & path1
|
|
|
|
let path4 = path1 & "\\" & path2
|
|
|
|
var sdd = ? createFoldersUserOnlySecurityDescriptor()
|
|
|
|
var sdf = ? createFilesUserOnlySecurityDescriptor()
|
2020-10-15 12:27:58 +00:00
|
|
|
# Create directory
|
2020-10-20 14:43:38 +00:00
|
|
|
? createPath(path1, secDescriptor = sdd.getDescriptor())
|
|
|
|
# Create file outside of directory
|
|
|
|
? writeFile(path2, "TESTBLOB", secDescriptor = sdf.getDescriptor())
|
|
|
|
# Create directory inside of directory
|
|
|
|
? createPath(path3, secDescriptor = sdd.getDescriptor())
|
|
|
|
# Create file inside of directory
|
|
|
|
? writeFile(path4, "TESTLBOB", secDescriptor = sdf.getDescriptor())
|
2020-10-15 12:27:58 +00:00
|
|
|
let res1 = ? checkCurrentUserOnlyACL(path1)
|
|
|
|
let res2 = ? checkCurrentUserOnlyACL(path2)
|
2020-10-20 14:43:38 +00:00
|
|
|
let res3 = ? checkCurrentUserOnlyACL(path3)
|
|
|
|
let res4 = ? checkCurrentUserOnlyACL(path4)
|
|
|
|
? removeFile(path4)
|
|
|
|
? removeDir(path3)
|
2020-10-15 12:27:58 +00:00
|
|
|
? removeFile(path2)
|
|
|
|
? removeDir(path1)
|
2020-10-20 14:43:38 +00:00
|
|
|
if res1 and res2 and res3 and res4:
|
2020-10-15 12:27:58 +00:00
|
|
|
ok(true)
|
|
|
|
else:
|
|
|
|
err(IoErrorCode(UserErrorCode))
|
|
|
|
check:
|
|
|
|
performTest("testblob14", "testblob15").isOk()
|
|
|
|
else:
|
|
|
|
skip()
|