def test_get(self): acls = SynoACLTool.get(self.testDir) expectedACLs = SynoACLSet([ SynoACL.fromString("user:guest:allow:rwxpd--------:fd--"), SynoACL.fromString("group:administrators:allow:rwxpdDaARWc--:fd--") ], [0, 1]) self.assertAclsEqual(acls, expectedACLs)
def test_eq(self): aclString = TestSynoACL.TEST_ROLE + ":" + TestSynoACL.TEST_NAME + ":" + \ TestSynoACL.TEST_TYPE + ":" + TestSynoACL.TEST_PERMISSIONS + ":" + TestSynoACL.TEST_INHERITANCE acl1 = SynoACL.fromString(aclString) acl2 = SynoACL.fromString(aclString) self.assertEqual(acl1, acl2)
def test_toString(self): inheritance = SynoACL.Inheritance(noPropagate=True) self.assertEqual(str(inheritance), TestInheritance.INHERIT_NOTHING) inheritance = SynoACL.Inheritance(fileInherited=True, directoryInherited=True, inheritOnly=True) self.assertEqual(str(inheritance), TestInheritance.INHERIT_ALL)
def test_ne(self): inheritance1 = SynoACL.Inheritance(noPropagate=True) inheritance2 = SynoACL.Inheritance.fromString( TestInheritance.INHERIT_ALL) self.assertNotEqual(inheritance1, inheritance2) inheritance1 = SynoACL.Inheritance(fileInherited=True, directoryInherited=True, inheritOnly=True) inheritance2 = SynoACL.Inheritance.fromString( TestInheritance.INHERIT_NOTHING) self.assertNotEqual(inheritance1, inheritance2)
def test_mixedCtor(self): testACLs = [{ "acl": SynoACL.Permissions(), "level": 0 }, { "acl": SynoACL.Permissions.fromString("rwx----------"), "level": 1 }, { "acl": SynoACL.Permissions.fromString("rwxpdD-------"), "level": 1 }] testDirectACLs = list( map(lambda entry: entry["acl"], filter(lambda entry: entry["level"] == 0, testACLs))) allACLs = list(map(lambda entry: entry["acl"], testACLs)) levels = list(map(lambda entry: entry["level"], testACLs)) acls = SynoACLSet(allACLs, levels) directACLs = acls.getDirect() expectedDirectACLCount = sum(1 if entry["level"] == 0 else 0 for entry in testACLs) self.assertEqual(len(directACLs), expectedDirectACLCount) for i in range(len(directACLs)): self.assertEqual(directACLs[i], testDirectACLs[i]) allACLs = acls.getAll() self.assertEqual(len(allACLs), len(allACLs)) for i in range(len(allACLs)): entry = allACLs[i] self.assertEqual(entry["acl"], testACLs[i]["acl"]) self.assertEqual(entry["level"], testACLs[i]["level"])
def test_fromString(self): aclString = TestSynoACL.TEST_ROLE + ":" + TestSynoACL.TEST_NAME + ":" + \ TestSynoACL.TEST_TYPE + ":" + TestSynoACL.TEST_PERMISSIONS + ":" + TestSynoACL.TEST_INHERITANCE acl = SynoACL.fromString(aclString) self.assertEqual(acl.role, TestSynoACL.TEST_ROLE) self.assertEqual(acl.name, TestSynoACL.TEST_NAME) self.assertEqual(acl.aclType, TestSynoACL.TEST_TYPE) self.assertEqual(str(acl.permissions), TestSynoACL.TEST_PERMISSIONS) self.assertEqual(str(acl.inheritMode), TestSynoACL.TEST_INHERITANCE)
def test_toString(self): acl = SynoACL( TestSynoACL.TEST_ROLE, TestSynoACL.TEST_NAME, TestSynoACL.TEST_TYPE, SynoACL.Permissions.fromString(TestSynoACL.TEST_PERMISSIONS), SynoACL.Inheritance.fromString(TestSynoACL.TEST_INHERITANCE)) aclString = TestSynoACL.TEST_ROLE + ":" + TestSynoACL.TEST_NAME + ":" + \ TestSynoACL.TEST_TYPE + ":" + TestSynoACL.TEST_PERMISSIONS + ":" + TestSynoACL.TEST_INHERITANCE self.assertEqual(aclString, str(acl))
def test_ne(self): permissions1 = SynoACL.Permissions() permissions2 = SynoACL.Permissions.fromString( TestPermissions.ALL_RIGHTS) self.assertNotEqual(permissions1, permissions2) permissions1 = SynoACL.Permissions.fromString( TestPermissions.NO_RIGHTS) permissions2 = SynoACL.Permissions.fromString( TestPermissions.ALL_RIGHTS) self.assertNotEqual(permissions1, permissions2)
def test_toString(self): permissions = SynoACL.Permissions() self.assertEqual(str(permissions), TestPermissions.NO_RIGHTS) permissions = SynoACL.Permissions(readData=True, writeData=True, execute=True) self.assertEqual(str(permissions), TestPermissions.RWX_RIGHTS) permissions = SynoACL.Permissions(readData=True, writeData=True, execute=True, appendData=True, delete=True, deleteChild=True, readAttribute=True, writeAttribute=True, readXAttr=True, writeXAttr=True, readAcl=True, writeAcl=True, getOwnership=True) self.assertEqual(str(permissions), TestPermissions.ALL_RIGHTS)
def test_onlyDirectCtor(self): testACLs = [ SynoACL.Permissions(), SynoACL.Permissions.fromString("rwx----------"), SynoACL.Permissions.fromString("rwxpdD-------") ] acls = SynoACLSet(testACLs) directACLs = acls.getDirect() self.assertEqual(len(directACLs), len(testACLs)) for i in range(len(directACLs)): self.assertEqual(directACLs[i], testACLs[i]) allACLs = acls.getAll() self.assertEqual(len(allACLs), len(allACLs)) for i in range(len(allACLs)): entry = allACLs[i] self.assertEqual(entry["acl"], testACLs[i]) self.assertEqual(entry["level"], 0)
def test_ne(self): aclString = TestSynoACL.TEST_ROLE + ":" + TestSynoACL.TEST_NAME + ":" + \ TestSynoACL.TEST_TYPE + ":" + TestSynoACL.TEST_PERMISSIONS + ":" + TestSynoACL.TEST_INHERITANCE acl1 = SynoACL.fromString(aclString) acl2 = SynoACL.fromString(aclString) acl2.role = "other" self.assertNotEqual(acl1, acl2) acl2 = SynoACL.fromString(aclString) acl2.name = "other" self.assertNotEqual(acl1, acl2) acl2 = SynoACL.fromString(aclString) acl2.aclType = "other" self.assertNotEqual(acl1, acl2) acl2 = SynoACL.fromString(aclString) acl2.permissions = SynoACL.Permissions() self.assertNotEqual(acl1, acl2) acl2 = SynoACL.fromString(aclString) acl2.inheritMode = SynoACL.Inheritance() self.assertNotEqual(acl1, acl2)