示例#1
0
    def test_coll_read_ticket_between_rodsusers(self):
        t = None
        data_objs = []
        tmpfiles = []
        try:
            # Create ticket for read access to alice's home collection.
            alice = self.login(self.alice)
            tc = Ticket(alice)
            home = self.irods_homedir(alice)
            tc.issue('read', home.path)

            # Create 'x' and 'y' in alice's home collection
            data_objs = [
                helpers.make_object(alice,
                                    home.path + "/" + name,
                                    content='abcxyz') for name in ('x', 'y')
            ]

            with self.login(self.bob) as bob:
                ts = Ticket(bob, tc.string)
                ts.supply()
                # Check collection access ticket allows bob to list both subobjects
                self.assertEqual(len(self.list_objects(bob)), 2)
                # and that we can get (and read) them properly.
                for name in ('x', 'y'):
                    with tempfile.NamedTemporaryFile(delete=False) as tmpf:
                        tmpfiles += [tmpf]
                    bob.data_objects.get(home.path + "/" + name, tmpf.name,
                                         **{kw.FORCE_FLAG_KW: ''})
                    with open(tmpf.name, 'r') as tmpread:
                        self.assertEqual(tmpread.read(), 'abcxyz')

            td = Ticket(alice)
            td.issue('read', home.path + "/x")

            with self.login(self.bob) as bob:
                ts = Ticket(bob, td.string)
                ts.supply()

                # Check data access ticket allows bob to list only one data object
                self.assertEqual(len(self.list_objects(bob)), 1)

                # ... and fetch that object (verifying content)
                with tempfile.NamedTemporaryFile(delete=False) as tmpf:
                    tmpfiles += [tmpf]
                bob.data_objects.get(home.path + "/x", tmpf.name,
                                     **{kw.FORCE_FLAG_KW: ''})
                with open(tmpf.name, 'r') as tmpread:
                    self.assertEqual(tmpread.read(), 'abcxyz')

                # ... but not fetch the other data object owned by alice.
                with self.assertRaises(ex.DataObjectDoesNotExist):
                    bob.data_objects.get(home.path + "/y")
        finally:
            if t: t.delete()
            for d in data_objs:
                d.unlink(force=True)
            for file_ in tmpfiles:
                os.unlink(file_.name)
            alice.cleanup()
示例#2
0
    def setUp(self):
        """Create objects for test"""
        self.sess = helpers.make_session()
        user = self.sess.users.get(self.sess.username)
        if user.type != 'rodsadmin':
            self.skipTest('''Test runnable only by rodsadmin.''')

        admin = self.sess
        delete_my_tickets(admin)

        # Create test collection

        self.coll_path = '/{}/home/{}/ticket_test_dir'.format(
            admin.zone, admin.username)
        self.coll = helpers.make_collection(admin, self.coll_path)

        # Create anonymous test user
        self.user = admin.users.create('anonymous', 'rodsuser')
        self.rodsuser_params = {
            'host': admin.host,
            'port': admin.port,
            'user': '******',
            'password': '',
            'zone': admin.zone
        }

        # make new data object in the test collection with some initialized content

        self.INITIALIZED_DATA = b'1' * 16
        self.data_path = '{self.coll_path}/ticketed_data'.format(**locals())
        helpers.make_object(admin,
                            self.data_path,
                            content=self.INITIALIZED_DATA)

        self.MODIFIED_DATA = b'2' * 16

        # make new tickets for the various combinations

        self.tickets = {'coll': {}, 'data': {}}
        for obj_type in ('coll', 'data'):
            for access in ('read', 'write'):
                ticket = Ticket(admin)
                self.tickets[obj_type][access] = ticket.string
                ticket.issue(access, getattr(self, obj_type + '_path'))
示例#3
0
 def ticket(self, path):
     ticket = Ticket(self.prc)
     # print("TEST", self.prc, path)
     ticket.issue('read', path)
     return ticket