10 TEST_DIR=os.environ.get("TESTDIR", ".")
12 BASIC_ACL_TEXT="u::rw,g::r,o::-"
14 def has_from_mode(fn):
15 """Decorator to skip tests based on platform support"""
16 if not posix1e.HAS_ACL_FROM_MODE:
17 new_fn = lambda x: None
18 new_fn.__doc__ = "SKIPPED %s" % fn.__doc__
23 def has_acl_entry(fn):
24 """Decorator to skip tests based on platform support"""
25 if not posix1e.HAS_ACL_ENTRY:
26 new_fn = lambda x: None
27 new_fn.__doc__ = "SKIPPED %s" % fn.__doc__
32 def has_acl_check(fn):
33 """Decorator to skip tests based on platform support"""
34 if not posix1e.HAS_ACL_CHECK:
35 new_fn = lambda x: None
36 new_fn.__doc__ = "SKIPPED %s" % fn.__doc__
42 """Support functions ACLs"""
50 """tear down function"""
51 for fname in self.rmfiles:
53 for dname in self.rmdirs:
57 """create a temp file"""
58 fh, fname = tempfile.mkstemp(".test", "xattr-", TEST_DIR)
59 self.rmfiles.append(fname)
63 """create a temp dir"""
64 dname = tempfile.mkdtemp(".test", "xattr-", TEST_DIR)
65 self.rmdirs.append(dname)
68 def _getsymlink(self):
69 """create a symlink"""
70 fh, fname = self._getfile()
73 os.symlink(fname + ".non-existent", fname)
77 class LoadTests(aclTest, unittest.TestCase):
78 """Load/create tests"""
79 def testFromFile(self):
80 """Test loading ACLs from a file"""
81 _, fname = self._getfile()
82 acl1 = posix1e.ACL(file=fname)
83 self.failUnless(acl1.valid(), "ACL read from file should be valid")
85 def testFromDir(self):
86 """Test loading ACLs from a directory"""
87 dname = self._getdir()
88 acl1 = posix1e.ACL(file=dname)
89 acl2 = posix1e.ACL(filedef=dname)
90 self.failUnless(acl1.valid(),
91 "ACL read from directory should be valid")
92 # default ACLs might or might not be valid; missing ones are
93 # not valid, so we don't test acl2 for validity
96 """Test loading ACLs from a file descriptor"""
97 fd, _ = self._getfile()
98 acl1 = posix1e.ACL(fd=fd)
99 self.failUnless(acl1.valid(), "ACL read from fd should be valid")
101 def testFromEmpty(self):
102 """Test creating an empty ACL"""
104 self.failIf(acl1.valid(), "Empty ACL should not be valid")
106 def testFromText(self):
107 """Test creating an ACL from text"""
108 acl1 = posix1e.ACL(text=BASIC_ACL_TEXT)
109 self.failUnless(acl1.valid(),
110 "ACL based on standard description should be valid")
112 class AclExtensions(aclTest, unittest.TestCase):
113 """ACL extensions checks"""
116 def testFromMode(self):
117 """Test loading ACLs from an octal mode"""
118 acl1 = posix1e.ACL(mode=0644)
119 self.failUnless(acl1.valid(),
120 "ACL created via octal mode shoule be valid")
123 def testAclCheck(self):
124 """Test the acl_check method"""
125 acl1 = posix1e.ACL(text=BASIC_ACL_TEXT)
126 self.failIf(acl1.check(), "ACL is not valid")
128 self.failUnless(acl2.check(), "Empty ACL should not be valid")
131 class WriteTests(aclTest, unittest.TestCase):
134 def testDeleteDefault(self):
135 """Test removing the default ACL"""
136 dname = self._getdir()
137 posix1e.delete_default(dname)
139 def testReapply(self):
140 """Test re-applying an ACL"""
141 fd, fname = self._getfile()
142 acl1 = posix1e.ACL(fd=fd)
145 dname = self._getdir()
146 acl2 = posix1e.ACL(file=fname)
150 class ModificationTests(aclTest, unittest.TestCase):
151 """ACL modification tests"""
154 def testAppend(self):
155 """Test append a new Entry to the ACL"""
158 e.tag_type = posix1e.ACL_OTHER
162 def testDelete(self):
163 """Test delete Entry from the ACL"""
166 e.tag_type = posix1e.ACL_OTHER
172 def testDoubleEntries(self):
173 """Test double entries"""
174 acl = posix1e.ACL(text=BASIC_ACL_TEXT)
175 self.failUnless(acl.valid(), "ACL is not valid")
176 for tag_type in (posix1e.ACL_USER_OBJ, posix1e.ACL_GROUP_OBJ,
179 e.tag_type = tag_type
181 self.failIf(acl.valid(),
182 "ACL containing duplicate entries should not be valid")
186 def testMultipleGoodEntries(self):
187 """Test multiple valid entries"""
188 acl = posix1e.ACL(text=BASIC_ACL_TEXT)
189 self.failUnless(acl.valid(), "ACL is not valid")
190 for tag_type in (posix1e.ACL_USER,
192 for obj_id in range(5):
194 e.tag_type = tag_type
198 self.failUnless(acl.valid(),
199 "ACL should be able to hold multiple"
200 " user/group entries")
202 def testMultipleBadEntries(self):
203 """Test multiple invalid entries"""
204 acl = posix1e.ACL(text=BASIC_ACL_TEXT)
205 self.failUnless(acl.valid(), "ACL built from standard description"
207 for tag_type in (posix1e.ACL_USER,
210 e1.tag_type = tag_type
214 self.failUnless(acl.valid(), "ACL should be able to add a"
217 e2.tag_type = tag_type
221 self.failIf(acl.valid(), "ACL should not validate when"
222 " containing two duplicate entries")
227 def testPermset(self):
228 """Test permissions"""
234 posix1e.ACL_READ: "read",
235 posix1e.ACL_WRITE: "write",
236 posix1e.ACL_EXECUTE: "execute",
239 self.failIf(ps.test(perm), "Empty permission set should not"
240 " have permission '%s'" % pmap[perm])
242 self.failUnless(ps.test(perm), "Permission '%s' should exist"
243 " after addition" % pmap[perm])
245 self.failIf(ps.test(perm), "Permission '%s' should not exist"
246 " after deletion" % pmap[perm])
249 if __name__ == "__main__":