Esempio n. 1
0
    def test_cap_rights_contains(self):
        big = self.cap_rights
        little = W.new_cap_rights()

        W.cap_rights_init(big, *self.SIMPLE_RIGHTS)
        W.cap_rights_init(little, self.SIMPLE_RIGHTS[0])

        self.assertTrue(W.cap_rights_contains(big, little))
        self.assertFalse(W.cap_rights_contains(little, big))
Esempio n. 2
0
    def test_cap_rights_remove(self):
        src = self.cap_rights
        dst = W.new_cap_rights()

        W.cap_rights_init(src, *self.SIMPLE_RIGHTS)
        W.cap_rights_init(dst, *self.SIMPLE_RIGHTS)

        W.cap_rights_remove(dst, src)

        for right in self.SIMPLE_RIGHTS:
            self.assertFalse(W.cap_rights_is_set(dst, right),
                             NAMES[right])
Esempio n. 3
0
    def test_cap_rights_clear(self):
        W.cap_rights_init(self.cap_rights)

        W.cap_rights_set(self.cap_rights, *self.SIMPLE_RIGHTS)

        remaining = set(self.SIMPLE_RIGHTS)
        while remaining:
            right = remaining.pop()
            W.cap_rights_clear(self.cap_rights, right)
            self.assertFalse(W.cap_rights_is_set(self.cap_rights, right),
                             NAMES[right])
            self.assertTrue(W.cap_rights_is_set(self.cap_rights, *remaining),
                            NAMES[right])
Esempio n. 4
0
    def test_cap_rights_get_fails(self):
        goodRights = W.cap_rights_init(W.new_cap_rights())

        with self.assertRaisesWithErrno(W.SpyceError, errno.EFAULT):
            W.cap_rights_get(self.f.fileno(),
                             W.ffi.cast('cap_rights_t *', W.ffi.NULL))

        with self.assertRaisesWithErrno(W.SpyceError, errno.EBADF):
            W.cap_rights_get(-1, goodRights)
Esempio n. 5
0
    def test_cap_rights_set(self):
        so_far = set()
        remaining = set(self.SIMPLE_RIGHTS)

        W.cap_rights_init(self.cap_rights)

        while remaining:
            self.assertFalse(W.cap_rights_is_set(self.cap_rights, *remaining))

            right = remaining.pop()
            so_far.add(right)

            W.cap_rights_set(self.cap_rights, right)

            self.assertTrue(W.cap_rights_is_set(self.cap_rights, right),
                            NAMES[right])
            self.assertTrue(W.cap_rights_is_set(self.cap_rights, *so_far),
                            NAMES[right])

            W.cap_rights_set(self.cap_rights, *so_far)

            self.assertTrue(W.cap_rights_is_set(self.cap_rights, *so_far),
                            NAMES[right])
Esempio n. 6
0
    def test_cap_rights_limit_fails(self):
        goodRights = W.cap_rights_init(W.new_cap_rights())

        with self.assertRaisesWithErrno(W.SpyceError, errno.EINVAL):
            W.cap_rights_limit(self.f.fileno(), W.new_cap_rights())

        with self.assertRaisesWithErrno(W.SpyceError, errno.EBADF):
            W.cap_rights_limit(-1, goodRights)

        # can't increase the rights on a file
        W.cap_rights_limit(self.f.fileno(), goodRights)

        W.cap_rights_set(goodRights, W.lib.CAP_WRITE)

        with self.assertRaisesWithErrno(W.SpyceError, W.ENOTCAPABLE):
            W.cap_rights_limit(self.f.fileno(), goodRights)
Esempio n. 7
0
    def test_cap_rights_limit_and_get(self):
        self.f.write(b'foobar')
        self.f.flush()
        self.f.seek(0)

        rights = W.cap_rights_init(W.new_cap_rights(), W.lib.CAP_READ)

        W.cap_rights_limit(self.f.fileno(), rights)

        self.assertEqual(self.f.read(), b'foobar')

        with self.assertRaisesWithErrno(IOError, W.ENOTCAPABLE):
            self.f.write(b'fails')
            self.f.flush()

        fdRights = W.new_cap_rights()
        W.cap_rights_get(self.f.fileno(), fdRights)

        self.assertTrue(W.cap_rights_contains(rights, fdRights))
        self.assertTrue(W.cap_rights_contains(fdRights, rights))
Esempio n. 8
0
 def test_cap_rights_is_valid(self):
     self.assertFalse(W.cap_rights_is_valid(self.cap_rights))
     W.cap_rights_init(self.cap_rights)
     self.assertTrue(W.cap_rights_is_valid(self.cap_rights))
Esempio n. 9
0
    def test_cap_rights_init_with_args(self):
        W.cap_rights_init(self.cap_rights, *self.SIMPLE_RIGHTS)

        for right in self.SIMPLE_RIGHTS:
            self.assertTrue(W.cap_rights_is_set(self.cap_rights, right),
                            NAMES[right])
Esempio n. 10
0
    def test_cap_rights_init(self):
        W.cap_rights_init(self.cap_rights)

        for right in self.SIMPLE_RIGHTS:
            self.assertFalse(W.cap_rights_is_set(self.cap_rights, right),
                             NAMES[right])