def test_access_with_explicit_arguments(self): with session.make_session_for_existing_admin() as admin: try: file_name = 'test_access_object' lib.make_file(file_name, 1024) admin.assert_icommand(['iput', file_name]) admin.assert_icommand(['ils', '-l'], 'STDOUT_SINGLELINE', file_name) pwd, _ = lib.execute_command(['ipwd']) pwd = pwd.rstrip() logical_path = os.path.join(pwd, file_name) token = irods_rest.authenticate('rods', 'rods', 'native') # The settings for the ticket. ticket_type = 'write' use_count = 50 write_file_count = 100 write_byte_count = 9999 seconds_until_expiration = 45 users = 'rods' groups = 'rodsadmin' hosts = 'irods.org' json_string = irods_rest.access(token, logical_path, ticket_type, use_count, write_file_count, write_byte_count, seconds_until_expiration, users, groups, hosts) json_object = json.loads(json_string) ticket_id = json_object['headers']['irods-ticket'][0] # Verify that the properties for the ticket are what we expect. _, out, _ = admin.assert_icommand(['iticket', 'ls', ticket_id], 'STDOUT', [ 'ticket type: ' + ticket_type, 'uses limit: ' + str(use_count), 'write file limit: ' + str(write_file_count), 'write byte limit: ' + str(write_byte_count), 'restricted-to user: '******'restricted-to group: ' + str(groups) ]) # Expiration time and host restrictions must be checked separately because the # values for these fields are non-deterministic. The best we can do is show that # the values did change. self.assertNotIn('expire time: none', out) self.assertNotIn('No host restrictions', out) self.assertIn('restricted-to host: ', out) admin.assert_icommand(['iticket', 'delete', ticket_id]) finally: os.remove(file_name) admin.assert_icommand(['irm', '-f', file_name])
def test_access(self): with session.make_session_for_existing_admin() as admin: try: file_name = 'test_access_object' lib.make_file(file_name, 1024) admin.assert_icommand(['iput', file_name]) admin.assert_icommand(['ils', '-l'], 'STDOUT_SINGLELINE', file_name) pwd, _ = lib.execute_command(['ipwd']) pwd = pwd.rstrip() logical_path = os.path.join(pwd, file_name) token = irods_rest.authenticate('rods', 'rods', 'native') result = irods_rest.access(token, logical_path) assert (result.find('error') == -1) finally: os.remove(file_name) admin.assert_icommand(['irm', '-f', file_name])
def test_access_with_default_arguments(self): with session.make_session_for_existing_admin() as admin: try: file_name = 'test_access_object' lib.make_file(file_name, 1024) admin.assert_icommand(['iput', file_name]) admin.assert_icommand(['ils', '-l'], 'STDOUT_SINGLELINE', file_name) pwd, _ = lib.execute_command(['ipwd']) pwd = pwd.rstrip() logical_path = os.path.join(pwd, file_name) token = irods_rest.authenticate('rods', 'rods', 'native') json_string = irods_rest.access(token, logical_path) assert(json_string.find('error') == -1) json_object = json.loads(json_string) ticket_id = json_object['headers']['irods-ticket'][0] # Verify that the properties for the ticket are what we expect. _, out, _ = admin.assert_icommand(['iticket', 'ls', ticket_id], 'STDOUT', [ 'ticket type: read', 'uses limit: 0', 'write file limit: 0', 'write byte limit: 0', 'expire time: none', 'No user restrictions', 'No group restrictions', 'No host restrictions' ]) admin.assert_icommand(['iticket', 'delete', ticket_id]) finally: os.remove(file_name) admin.assert_icommand(['irm', '-f', file_name])
def test_access_returns_error_on_invalid_value_for_seconds_until_expiration_parameter(self): with session.make_session_for_existing_admin() as admin: try: file_name = 'test_access_object' lib.make_file(file_name, 1024) admin.assert_icommand(['iput', file_name]) admin.assert_icommand(['ils', '-l'], 'STDOUT_SINGLELINE', file_name) pwd, _ = lib.execute_command(['ipwd']) pwd = pwd.rstrip() logical_path = os.path.join(pwd, file_name) token = irods_rest.authenticate('rods', 'rods', 'native') json_string = irods_rest.access(token, logical_path, _seconds_until_expiration=-1) assert(json_string.find('error') > 0) json_object = json.loads(json_string) self.assertEqual(json_object['error_code'], -130000) finally: os.remove(file_name) admin.assert_icommand(['irm', '-f', file_name])