10 TEST_DIR=os.environ.get("TESTDIR", ".")
13 def has_from_mode(fn):
14 """Decorator to skip tests based on platform support"""
15 if not posix1e.HAS_ACL_FROM_MODE:
16 new_fn = lambda x: None
17 new_fn.__doc__ = "SKIPPED %s" % fn.__doc__
22 def has_acl_entry(fn):
23 """Decorator to skip tests based on platform support"""
24 if not posix1e.HAS_ACL_ENTRY:
25 new_fn = lambda x: None
26 new_fn.__doc__ = "SKIPPED %s" % fn.__doc__
31 def has_acl_check(fn):
32 """Decorator to skip tests based on platform support"""
33 if not posix1e.HAS_ACL_CHECK:
34 new_fn = lambda x: None
35 new_fn.__doc__ = "SKIPPED %s" % fn.__doc__
41 """Support functions ACLs"""
49 """tear down function"""
50 for fname in self.rmfiles:
52 for dname in self.rmdirs:
56 """create a temp file"""
57 fh, fname = tempfile.mkstemp(".test", "xattr-", TEST_DIR)
58 self.rmfiles.append(fname)
62 """create a temp dir"""
63 dname = tempfile.mkdtemp(".test", "xattr-", TEST_DIR)
64 self.rmdirs.append(dname)
67 def _getsymlink(self):
68 """create a symlink"""
69 fh, fname = self._getfile()
72 os.symlink(fname + ".non-existent", fname)
76 class LoadTests(aclTest, unittest.TestCase):
77 """Load/create tests"""
78 def testFromFile(self):
79 """Test loading ACLs from a file"""
80 _, fname = self._getfile()
81 acl1 = posix1e.ACL(file=fname)
82 self.failUnless(acl1.valid(), "ACL read from file should be valid")
84 def testFromDir(self):
85 """Test loading ACLs from a directory"""
86 dname = self._getdir()
87 acl1 = posix1e.ACL(file=dname)
88 acl2 = posix1e.ACL(filedef=dname)
89 self.failUnless(acl1.valid(),
90 "ACL read from directory should be valid")
91 # default ACLs might or might not be valid; missing ones are
92 # not valid, so we don't test acl2 for validity
95 """Test loading ACLs from a file descriptor"""
96 fd, _ = self._getfile()
97 acl1 = posix1e.ACL(fd=fd)
98 self.failUnless(acl1.valid(), "ACL read from fd should be valid")
100 def testFromEmpty(self):
101 """Test creating an empty ACL"""
103 self.failIf(acl1.valid(), "Empty ACL should not be valid")
105 def testFromText(self):
106 """Test creating an ACL from text"""
107 acl1 = posix1e.ACL(text="u::rx,g::-,o::-")
108 self.failUnless(acl1.valid(),
109 "ACL based on standard description should be valid")
111 class AclExtensions(aclTest, unittest.TestCase):
112 """ACL extensions checks"""
115 def testFromMode(self):
116 """Test loading ACLs from an octal mode"""
117 acl1 = posix1e.ACL(mode=0644)
118 self.failUnless(acl1.valid(),
119 "ACL created via octal mode shoule be valid")
122 def testAclCheck(self):
123 """Test the acl_check method"""
124 acl1 = posix1e.ACL(text="u::rx,g::-,o::-")
125 self.failIf(acl1.check(), "ACL is not valid")
127 self.failUnless(acl2.check(), "Empty ACL should not be valid")
130 class WriteTests(aclTest, unittest.TestCase):
133 def testDeleteDefault(self):
134 """Test removing the default ACL"""
135 dname = self._getdir()
136 posix1e.delete_default(dname)
138 def testReapply(self):
139 """Test re-applying an ACL"""
140 fd, fname = self._getfile()
141 acl1 = posix1e.ACL(fd=fd)
144 dname = self._getdir()
145 acl2 = posix1e.ACL(file=fname)
149 class ModificationTests(aclTest, unittest.TestCase):
150 """ACL modification tests"""
153 def testAppend(self):
154 """Test append a new Entry to the ACL"""
157 e.tag_type = posix1e.ACL_OTHER
161 def testDelete(self):
162 """Test delete Entry from the ACL"""
165 e.tag_type = posix1e.ACL_OTHER
171 def testDoubleEntries(self):
172 """Test double entries"""
173 acl = posix1e.ACL(text="u::rx,g::-,o::-")
174 self.failUnless(acl.valid(), "ACL is not valid")
175 for tag_type in (posix1e.ACL_USER_OBJ, posix1e.ACL_GROUP_OBJ,
178 e.tag_type = tag_type
180 self.failIf(acl.valid(),
181 "ACL containing duplicate entries should not be valid")
185 def testMultipleGoodEntries(self):
186 """Test multiple valid entries"""
187 acl = posix1e.ACL(text="u::rx,g::-,o::-")
188 self.failUnless(acl.valid(), "ACL is not valid")
189 for tag_type in (posix1e.ACL_USER,
191 for obj_id in range(5):
193 e.tag_type = tag_type
197 self.failUnless(acl.valid(),
198 "ACL should be able to hold multiple"
199 " user/group entries")
201 def testMultipleBadEntries(self):
202 """Test multiple invalid entries"""
203 acl = posix1e.ACL(text="u::rx,g::-,o::-")
204 self.failUnless(acl.valid(), "ACL built from standard description"
206 for tag_type in (posix1e.ACL_USER,
209 e1.tag_type = tag_type
213 self.failUnless(acl.valid(), "ACL should be able to add a"
216 e2.tag_type = tag_type
220 self.failIf(acl.valid(), "ACL should not validate when"
221 " containing two duplicate entries")
226 def testPermset(self):
227 """Test permissions"""
233 posix1e.ACL_READ: "read",
234 posix1e.ACL_WRITE: "write",
235 posix1e.ACL_EXECUTE: "execute",
238 self.failIf(ps.test(perm), "Empty permission set should not"
239 " have permission '%s'" % pmap[perm])
241 self.failUnless(ps.test(perm), "Permission '%s' should exist"
242 " after addition" % pmap[perm])
244 self.failIf(ps.test(perm), "Permission '%s' should not exist"
245 " after deletion" % pmap[perm])
248 if __name__ == "__main__":