def test_nonanonymous_login_without_auth_file_fails__290(self): ses = self.admin if ses.users.get(ses.username).type != 'rodsadmin': self.skipTest('Only a rodsadmin may run this test.') try: ENV_DIR = tempfile.mkdtemp() ses.users.create('bob', 'rodsuser') ses.users.modify('bob', 'password', 'bpass') d = dict(password='******', user='******', host=ses.host, port=ses.port, zone=ses.zone) (bob_env, bob_auth) = helpers.make_environment_and_auth_files(ENV_DIR, **d) login_options = { 'irods_env_file': bob_env, 'irods_authentication_file': bob_auth } with helpers.make_session(**login_options) as s: s.users.get('bob') os.unlink(bob_auth) # -- Check that we raise an appropriate exception pointing to the missing auth file path -- with self.assertRaisesRegexp(NonAnonymousLoginWithoutPassword, bob_auth): with helpers.make_session(**login_options) as s: s.users.get('bob') finally: try: shutil.rmtree(ENV_DIR, ignore_errors=True) ses.users.get('bob').remove() except ex.UserDoesNotExist: pass
def connect(args): """Connect to the iRODS server""" if args.user is not None: if args.passwd is None: print("ERROR: --passwd required with --user") sys.exit() session = iRODSSession(host=args.host, port=args.port, user=args.user, password=args.passwd, zone=args.zone) else: try: session = helpers.make_session() except FileNotFoundError: sys.exit("ERROR: No irods_environment.json file found. Type 'pyicmd help' for details") # Test the connection try: session.server_version except CAT_INVALID_AUTHENTICATION: sys.exit("iRODS server authentication failed.") except CAT_INVALID_USER: sys.exit("Invalid iRODS user.") except CAT_INVALID_CLIENT_USER: sys.exit("Invalid client user. (Did you use the right zone?)") except NetworkException as exception: sys.exit(str(exception)) return session
def test_admin_keyword_for_tickets(self): N_TICKETS = 3 # Create some tickets as alice. with self.login(self.alice) as alice: alice_home_path = self.irods_homedir(alice, path_only=True) ticket_strings = [ Ticket(alice).issue('read', alice_home_path).string for _ in range(N_TICKETS) ] # As rodsadmin, use the ADMIN_KW flag to delete alice's tickets. with helpers.make_session() as ses: alices_tickets = [ t[TicketQuery.Ticket.string] for t in ses.query(TicketQuery.Ticket).filter( TicketQuery.Owner.name == 'alice') ] self.assertEqual(len(alices_tickets), N_TICKETS) for s in alices_tickets: Ticket(ses, s).delete(**{kw.ADMIN_KW: ''}) alices_tickets = [ t[TicketQuery.Ticket.string] for t in ses.query(TicketQuery.Ticket).filter( TicketQuery.Owner.name == 'alice') ] self.assertEqual(len(alices_tickets), 0)
def setUp(self): admin = self.admin = helpers.make_session() user = self.user = admin.users.create('anonymous', 'rodsuser', admin.zone) self.home = '/{admin.zone}/home/{user.name}'.format(**locals()) admin.collections.create(self.home) acl = iRODSAccess('own', self.home, user.name) admin.permissions.set(acl) self.env_file = os.path.expanduser( '~/.irods.anon/irods_environment.json') self.env_dir = (os.path.dirname(self.env_file)) self.auth_file = os.path.expanduser('~/.irods.anon/.irodsA') os.mkdir(os.path.dirname(self.env_file)) json.dump( { "irods_host": admin.host, "irods_port": admin.port, "irods_user_name": user.name, "irods_zone_name": admin.zone }, open(self.env_file, 'w'), indent=4)
def test_modify_password_with_incorrect_old_value__328(self): ses = self.sess if ses.users.get(ses.username).type != 'rodsadmin': self.skipTest('Only a rodsadmin may run this test.') OLDPASS = '******' NEWPASS = '******' ENV_DIR = tempfile.mkdtemp() try: ses.users.create('alice', 'rodsuser') ses.users.modify('alice', 'password', OLDPASS) d = dict(password=OLDPASS, user='******', host=ses.host, port=ses.port, zone=ses.zone) (alice_env, alice_auth) = helpers.make_environment_and_auth_files( ENV_DIR, **d) session_factories = [ (lambda: iRODSSession(**d)), (lambda: helpers.make_session(irods_env_file=alice_env, irods_authentication_file= alice_auth)), ] for factory in session_factories: with factory() as alice_ses: alice = alice_ses.users.get(alice_ses.username) with self.assertRaises(ex.CAT_PASSWORD_ENCODING_ERROR): alice.modify_password(OLDPASS + ".", NEWPASS) with iRODSSession(**d) as alice_ses: self.do_something(alice_ses) finally: shutil.rmtree(ENV_DIR) ses.users.remove('alice')
def setUp(self): self.sess = helpers.make_session() # Create test collection self.coll_path = '/{}/home/{}/test_dir'.format(self.sess.zone, self.sess.username) self.coll = helpers.make_collection(self.sess, self.coll_path)
def tearDownClass(cls): with helpers.make_session() as sess: try: if cls.register_resc: sess.resources.get(cls.register_resc).remove() except Exception as e: print( "Could not remove resc {!r} due to: {} ".format(cls.register_resc,e), file=sys.stderr)
def setUpClass(cls): cls.admin = helpers.make_session() if cls.test_rods_user in (row[User.name] for row in cls.admin.query(User.name)): cls.server_ssl_setting = cls.get_server_ssl_negotiation(cls.admin) cls.envdirs = cls.create_env_dirs() if not cls.envdirs: raise RuntimeError( 'Could not create one or more client environments')
def setUpClass(cls): # once only (before all tests), set up large collection print("Creating a large collection...", file=sys.stderr) with helpers.make_session() as sess: # Create test collection cls.coll_path = '/{}/home/{}/test_dir'.format( sess.zone, sess.username) cls.obj_count = 2500 cls.coll = helpers.make_test_collection(sess, cls.coll_path, cls.obj_count)
def test_login_from_environment(self): orig_env = os.environ.copy() try: os.environ["IRODS_ENVIRONMENT_FILE"] = self.env_file os.environ["IRODS_AUTHENTICATION_FILE"] = self.auth_file ses = helpers.make_session() ses.collections.get(self.home) finally: os.environ.clear() os.environ.update(orig_env)
def setUp(self): self.sess = helpers.make_session() self.coll_path = '/{}/home/{}/test_dir'.format(self.sess.zone, self.sess.username) # make list of unicode filenames, from file self.names = parse_xml_file(UNICODE_TEST_FILE) # Create test collection self.coll = helpers.make_collection( self.sess, self.coll_path, self.names)
def setUp(self): if os.path.expanduser('~') == '/var/lib/irods': self.skipTest('TestWithSSL may not be run by user irods') if not os.path.exists('/etc/irods/ssl'): self.skipTest( 'Running setupssl.py as irods user is prerequisite for this test.' ) with helpers.make_session() as session: if not session.host in ('localhost', socket.gethostname()): self.skipTest('Test must be run co-resident with server')
def setUp(self): self.sess = helpers.make_session() # test data self.coll_path = '/{}/home/{}/test_dir'.format(self.sess.zone, self.sess.username) self.obj_name = 'test1' self.obj_path = '{coll_path}/{obj_name}'.format(**vars(self)) # Create test collection and (empty) test object self.coll = self.sess.collections.create(self.coll_path) self.obj = self.sess.data_objects.create(self.obj_path)
def test_obj_put_to_default_resource_from_env_file(self): # Can't do one step open/create with older servers if self.sess.server_version <= (4, 1, 4): self.skipTest('For iRODS 4.1.5 and newer') # make another UFS resource session = self.sess resource_name = 'ufs' resource_type = 'unixfilesystem' resource_host = session.host resource_path = '/tmp/' + resource_name session.resources.create(resource_name, resource_type, resource_host, resource_path) # make a copy of the irods env file with 'ufs0' as the default resource env_file = os.path.expanduser('~/.irods/irods_environment.json') new_env_file = '/tmp/irods_environment.json' with open(env_file) as f, open(new_env_file, 'w') as new_f: irods_env = json.load(f) irods_env['irods_default_resource'] = resource_name json.dump(irods_env, new_f) # now open a new session with our modified environment file with helpers.make_session(irods_env_file=new_env_file) as new_session: # make a local file with random text content content = ''.join( random.choice(string.printable) for _ in range(1024)) filename = 'testfile.txt' file_path = os.path.join('/tmp', filename) with open(file_path, 'w') as f: f.write(content) # put file collection = self.coll_path obj_path = '{collection}/{filename}'.format(**locals()) new_session.data_objects.put(file_path, obj_path) # get object and confirm resource obj = new_session.data_objects.get(obj_path) self.assertEqual(obj.replicas[0].resource_name, resource_name) # remove object obj.unlink(force=True) # delete second resource session.resources.remove(resource_name) # cleanup os.remove(file_path) os.remove(new_env_file)
def test_obj_put_to_default_resource_from_env_file(self): # Can't do one step open/create with older servers if self.sess.server_version <= (4, 1, 4): self.skipTest('For iRODS 4.1.5 and newer') # make another UFS resource session = self.sess resource_name = 'ufs' resource_type = 'unixfilesystem' resource_host = session.host resource_path = '/tmp/' + resource_name session.resources.create(resource_name, resource_type, resource_host, resource_path) # make a copy of the irods env file with 'ufs0' as the default resource env_file = os.path.expanduser('~/.irods/irods_environment.json') new_env_file = '/tmp/irods_environment.json' with open(env_file) as f, open(new_env_file, 'w') as new_f: irods_env = json.load(f) irods_env['irods_default_resource'] = resource_name json.dump(irods_env, new_f) # now open a new session with our modified environment file with helpers.make_session(irods_env_file=new_env_file) as new_session: # make a local file with random text content content = ''.join(random.choice(string.printable) for _ in range(1024)) filename = 'testfile.txt' file_path = os.path.join('/tmp', filename) with open(file_path, 'w') as f: f.write(content) # put file collection = self.coll_path obj_path = '{collection}/{filename}'.format(**locals()) new_session.data_objects.put(file_path, obj_path) # get object and confirm resource obj = new_session.data_objects.get(obj_path) self.assertEqual(obj.replicas[0].resource_name, resource_name) # remove object obj.unlink(force=True) # delete second resource session.resources.remove(resource_name) # cleanup os.remove(file_path) os.remove(new_env_file)
def setUp(self): self.alice = self.bob = None with helpers.make_session() as ses: u = ses.users.get(ses.username) if u.type != 'rodsadmin': self.skipTest('''Test runnable only by rodsadmin.''') self.host = ses.host self.port = ses.port self.zone = ses.zone for newuser, passwd in self.users.items(): u = ses.users.create(newuser, 'rodsuser') setattr(self, newuser, u) u.modify('password', passwd)
def setUp(self): self.sess = helpers.make_session() # Create test collection self.coll_path = '/{}/home/{}/test_dir'.format(self.sess.zone, self.sess.username) self.coll = helpers.make_collection(self.sess, self.coll_path) VERSION_DEPENDENT_STRINGS = { 'MODIFY':'modify_object', 'READ':'read_object' } if self.sess.server_version >= (4,3) \ else { 'MODIFY':'modify object', 'READ':'read object' } self.mapping = dict([(i, i) for i in ('own', VERSION_DEPENDENT_STRINGS['MODIFY'], VERSION_DEPENDENT_STRINGS['READ'])] + [('write', VERSION_DEPENDENT_STRINGS['MODIFY']), ('read', VERSION_DEPENDENT_STRINGS['READ'])])
def test_modify_password_with_changing_auth_file__328(self): ses = self.sess if ses.users.get(ses.username).type != 'rodsadmin': self.skipTest('Only a rodsadmin may run this test.') OLDPASS = '******' def generator(p=OLDPASS): n = 1 old_pw = p while True: pw = p + str(n) yield old_pw, pw n += 1 old_pw = pw password_generator = generator() ENV_DIR = tempfile.mkdtemp() d = dict(password=OLDPASS, user='******', host=ses.host, port=ses.port, zone=ses.zone) (alice_env, alice_auth) = helpers.make_environment_and_auth_files(ENV_DIR, **d) try: ses.users.create('alice', 'rodsuser') ses.users.modify('alice', 'password', OLDPASS) for modify_option, sess_factory in [ (alice_auth, lambda: iRODSSession(**d)), (True, lambda: helpers.make_session(irods_env_file=alice_env, irods_authentication_file= alice_auth)) ]: OLDPASS, NEWPASS = next(password_generator) with sess_factory() as alice_ses: alice = alice_ses.users.get(alice_ses.username) alice.modify_password( OLDPASS, NEWPASS, modify_irods_authentication_file=modify_option) d['password'] = NEWPASS with iRODSSession(**d) as session: self.do_something( session ) # can we still do stuff with the final value of the password? finally: shutil.rmtree(ENV_DIR) ses.users.remove('alice')
def setUp(self): self.sess = helpers.make_session() # Create test collection self.coll_path = '/{}/home/{}/test_dir'.format(self.sess.zone, self.sess.username) self.collection = self.sess.collections.create(self.coll_path) self.obj_name = 'test1' self.content_str = u'blah' self.write_str = u'0123456789' self.write_str1 = u'INTERRUPT' self.test_obj_path = '{coll_path}/{obj_name}'.format(**vars(self)) # Create test object helpers.make_object(self.sess, self.test_obj_path, self.content_str)
def setUpClass(cls): # generate test env files using connect data from ~/.irods environment if USE_ONLY_LOCALHOST: return Nonlocal_Ext = ".test" with helpers.make_session() as session: cls.preferred_parameters = { 'irods_host':session.host, 'irods_port':session.port, 'irods_user_name':session.username, 'irods_zone_name':session.zone } test_configs_dir = os.path.join(irods_test_path(),"test-data") for config in [os.path.join(test_configs_dir,f) for f in os.listdir(test_configs_dir) if f.endswith(cls.config_extension)]: with open(config,"r") as in_, open(config + Nonlocal_Ext,"w") as out_: cf = json.load(in_) cf.update(cls.preferred_parameters) json.dump(cf, out_,indent=4) cls.test_extension = Nonlocal_Ext
def session(): try: session = helpers.make_session() except FileNotFoundError: session = iRODSSession(host="localhost", port=1247, user="******", password="******", zone="tempZone") if session.collections.exists(IRODS_TEST_DIR): coll = session.collections.get(IRODS_TEST_DIR) coll.remove(recursive=True, force=True) session.collections.create(IRODS_TEST_DIR) return session
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'))
def test_ssl_with_server_verify_set_to_none_281(self): env_file = os.path.expanduser('~/.irods/irods_environment.json') with helpers.file_backed_up(env_file): with open(env_file) as env_file_handle: env = json.load(env_file_handle) env.update({ "irods_client_server_negotiation": "request_server_negotiation", "irods_client_server_policy": "CS_NEG_REQUIRE", "irods_ssl_ca_certificate_file": "/path/to/some/file.crt", # does not need to exist "irods_ssl_verify_server": "none", "irods_encryption_key_size": 32, "irods_encryption_salt_size": 8, "irods_encryption_num_hash_rounds": 16, "irods_encryption_algorithm": "AES-256-CBC" }) with open(env_file, 'w') as f: json.dump(env, f) with helpers.make_session() as session: session.collections.get( '/{session.zone}/home/{session.username}'.format( **locals()))
def setUp(self): self.sess = helpers.make_session()
def setUp(self): admin = self.admin = helpers.make_session() if admin.users.get(admin.username).type != 'rodsadmin': self.skipTest('need admin privilege') admin.users.create('alice', 'rodsuser')
def tearDown(self): with helpers.make_session() as ses: for u in self.users: ses.users.remove(u)
def setUpClass(cls): cls.admin = helpers.make_session()
raise NullInput if __name__ == '__main__': OP = 'remove' if '-r' in optD else 'add' collection_ = ('-c' in optD) path_, arg = arg[0], arg[1:] def die(message='', code=123): print(message, file=sys.stderr) exit(code) with make_session() as ses: d = ses.data_objects.get( path_) if not collection_ else ses.collections.get(path_) operations = [] file_ = None if '-s' in optD: file_ = sys.stdin if optD['-s'] == '-' else open(optD['-s'], 'r') try: while True: if file_ is not None: line = next(file_) OP, a, v, u = get_operation(source_line=line) else: OP, a, v, u = get_operation(source_list=arg) if not OP: break if OP[-1:] in ('-', '+'):
def setUp(self): super(TestSpecificQuery, self).setUp() self.session = helpers.make_session()
def setUp(self): self.sess = helpers.make_session( irods_env_file="./test-data/irods_environment.json")
def setUpClass(cls): with helpers.make_session() as sess: resource_name = helpers.get_register_resource(sess) if resource_name: cls.register_resc = resource_name