def test_file_children(self): user1 = User(self.db) name = "/file/name" data = "/etc/group" file1 = File.create_file(self.db, name, user1, data, pynimbusauthz.object_type_s3) self.db.commit() child1 = File.create_file(self.db, "kid", user1, data, pynimbusauthz.object_type_s3, parent=file1) self.db.commit() p2 = child1.get_parent() self.assertEqual(p2, file1, "parent not set properly") x = child1.get_all_children() self.assertEqual(len(list(x)), 0, "The file should have no children") x = file1.get_all_children() found = False for f in x: if f == child1: found = True self.assertTrue(found, "We should have found that kid!")
def main(argv=sys.argv[1:]): try: con_str = pynimbusauthz.get_db_connection_string() db_obj = DB(con_str=con_str) (opts, args) = setup_options(argv) if len(args) != 3: raise AuthzException( 'CLI_PARAMETER', "You must specify a username filename and a datakey\nTry --help" ) user_name = args[0] object_name = args[1] data = args[2] user = User(db_obj, uu=user_name) parent = None if opts.parent != None: parent = File.get_file(db_obj, opts.parent, opts.type) if parent == None: raise AuthzException('FILE_EXISTS', "parent %s not found" % (opts.parent)) File.create_file(db_obj, object_name, user, data, opts.type, parent=parent) db_obj.commit() except AuthzException, ae: print ae return ae.get_rc()
def test_file_and_bucket(self): user1 = User(self.db) fname = "NAME" data = "data" b1 = File.create_file(self.db, "bucket", user1, data, pynimbusauthz.object_type_s3) f1 = File.create_file(self.db, fname, user1, data, pynimbusauthz.object_type_s3, parent=b1) f2 = File.create_file(self.db, fname, user1, data, pynimbusauthz.object_type_s3) self.db.commit() self.assertNotEqual(f1.get_id(), f2.get_id()) f3 = File.get_file(self.db, fname, pynimbusauthz.object_type_s3, parent=b1) f4 = File.get_file(self.db, fname, pynimbusauthz.object_type_s3) self.assertEqual(f1.get_id(), f3.get_id()) self.assertEqual(f2.get_id(), f4.get_id()) self.assertNotEqual(f3.get_id(), f4.get_id()) self.db.commit()
def test_many_change_but_not_all(self): name = "/file/name" old_base = "/OLD" new_base = "/NEW" other_base = "/NOTHERE" count = 10 for i in range(0, count): keyname = str(uuid.uuid1()) oldkey = old_base + "/" + keyname File.create_file(self.db, name + oldkey, self.user1, oldkey, pynimbusauthz.object_type_s3) for i in range(0, count * 2): keyname = str(uuid.uuid1()) oldkey = other_base + "/" + keyname File.create_file(self.db, name + oldkey, self.user1, oldkey, pynimbusauthz.object_type_s3) self.db.commit() rc = pynimbusauthz.rebase.main([old_base, new_base]) self.assertEqual(rc, 0, "rc should be 0, is %d" % (rc)) f2a = File.find_files_from_data(self.db, new_base + "%") f2a = list(f2a) self.assertEqual( len(f2a), count, "length of the new items should be %d is %s" % (count, len(f2a)))
def main(argv=sys.argv[1:]): try: con_str = pynimbusauthz.get_db_connection_string() db_obj = DB(con_str=con_str) (opts, args) = setup_options(argv) if len(args) != 3: raise AuthzException("CLI_PARAMETER", "You must specify a username filename and a datakey\nTry --help") user_name = args[0] object_name = args[1] data = args[2] user = User(db_obj, uu=user_name) parent = None if opts.parent != None: parent = File.get_file(db_obj, opts.parent, opts.type) if parent == None: raise AuthzException("FILE_EXISTS", "parent %s not found" % (opts.parent)) File.create_file(db_obj, object_name, user, data, opts.type, parent=parent) except AuthzException, ae: print ae return ae.get_rc()
def test_bucket(self): # create a file and a bucket b1 = File.create_file(self.db, "bucket", self.user1, self.data, pynimbusauthz.object_type_s3) f2 = File.create_file(self.db, self.name, self.user1, self.data, pynimbusauthz.object_type_s3, parent=b1) self.db.commit() new_perms = "WR" rc = pynimbusauthz.chmod.main(["-t", f2.get_object_type(), "-p", b1.get_name(), self.user1.get_id(), f2.get_name(), new_perms]) self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
def test_single_change(self): name = "/file/name" old_base = "/OLD" new_base = "/NEW" data = "/etc/group" key = old_base + data file1 = File.create_file(self.db, name, self.user1, key, pynimbusauthz.object_type_s3) self.db.commit() rc = pynimbusauthz.rebase.main([old_base, new_base]) self.assertEqual(rc, 0, "rc should be 0, is %d" % (rc)) f2a = File.find_files_from_data(self.db, key) f2a = list(f2a) self.assertEqual(len(f2a), 0, "should be no values with key %s len is %d" % (old_base, len(f2a))) key = new_base + data f2a = File.find_files_from_data(self.db, key) f2a = list(f2a) self.assertNotEqual(len(f2a), 0, "length should be greater than 0 is %d" % (len(f2a))) found = False for f2 in f2a: tst_key = f2.get_data_key() if tst_key == key: found = True self.assertTrue(found, "key not found")
def xtest_international_file(self): user1 = User(self.db) name = os.environ['CUMULUS_WORD'] data = "/etc/group" file1 = File.create_file(self.db, name, user1, data, pynimbusauthz.object_type_s3) self.db.commit()
def test_change_key(self): user1 = User(self.db) name = "/file/name" old_base = "/old/path/base" fname = "/etc/group" new_base = "/new/base/location/dir" f = File.create_file(self.db, name, user1, old_base + fname, pynimbusauthz.object_type_s3) self.assertEqual(old_base + fname, f.get_data_key(), "old value not euqal") new_key = new_base + fname f.set_data_key(new_key) self.db.commit() tst_new_key = f.get_data_key() self.assertEqual(tst_new_key, new_key, "%s should equal %s" % (tst_new_key, new_key)) f2 = File.get_file(self.db, name, pynimbusauthz.object_type_s3) tst_new_key = f2.get_data_key() self.assertEqual(tst_new_key, new_key, "%s should equal %s" % (tst_new_key, new_key))
def test_single_change(self): name = "/file/name" old_base = "/OLD" new_base = "/NEW" data = "/etc/group" key = old_base + data file1 = File.create_file(self.db, name, self.user1, key, pynimbusauthz.object_type_s3) self.db.commit() rc = pynimbusauthz.rebase.main([old_base, new_base]) self.assertEqual(rc, 0, "rc should be 0, is %d" % (rc)) f2a = File.find_files_from_data(self.db, key) f2a = list(f2a) self.assertEqual( len(f2a), 0, "should be no values with key %s len is %d" % (old_base, len(f2a))) key = new_base + data f2a = File.find_files_from_data(self.db, key) f2a = list(f2a) self.assertNotEqual( len(f2a), 0, "length should be greater than 0 is %d" % (len(f2a))) found = False for f2 in f2a: tst_key = f2.get_data_key() if tst_key == key: found = True self.assertTrue(found, "key not found")
def test_file_and_bucket(self): user1 = User(self.db) fname = "NAME" data = "data" b1 = File.create_file(self.db, "bucket", user1, data, pynimbusauthz.object_type_s3) f1 = File.create_file(self.db, fname, user1, data, pynimbusauthz.object_type_s3, parent=b1) f2 = File.create_file(self.db, fname, user1, data, pynimbusauthz.object_type_s3) self.db.commit() self.assertNotEqual(f1.get_id(), f2.get_id()) f3 = File.get_file(self.db, fname, pynimbusauthz.object_type_s3, parent=b1) f4 = File.get_file(self.db, fname, pynimbusauthz.object_type_s3) self.assertEqual(f1.get_id(), f3.get_id()) self.assertEqual(f2.get_id(), f4.get_id()) self.assertNotEqual(f3.get_id(), f4.get_id()) self.db.commit()
def main(argv=sys.argv[1:]): try: repo_dir = argv[0] con_str = pynimbusauthz.get_db_connection_string() db_obj = DB(con_str=con_str) user = User(db_obj, uu="CumulusPublicUser") if user == None: raise Exception("No public user") File.create_file(db_obj, repo_dir, user, repo_dir, pynimbusauthz.alias_type_s3) db_obj.commit() except: raise return 0
def test_many_change(self): name = "/file/name" old_base = "/OLD" new_base = "/NEW" count = 10 for i in range(0, count): keyname = str(uuid.uuid1()) oldkey = old_base + "/" + keyname File.create_file(self.db, name+oldkey, self.user1, oldkey, pynimbusauthz.object_type_s3) self.db.commit() rc = pynimbusauthz.rebase.main([old_base, new_base]) self.assertEqual(rc, 0, "rc should be 0, is %d" % (rc)) f2a = File.find_files_from_data(self.db, new_base + "%") f2a = list(f2a) self.assertEqual(len(f2a), count, "length of the new items should be %d is %s" % (count, len(f2a)))
def setUp(self): # os.environ['CUMULUS_AUTHZ_DDL'] = "/home/bresnaha/Dev/Nimbus/nimbus/cumulus/authz/etc/acl.sql" con = pynimbusauthz.db.make_test_database() self.db = DB(con=con) self.user1 = User(self.db) self.name = "/file/name" self.data = "/etc/group" self.file1 = File.create_file(self.db, self.name, self.user1, self.data, pynimbusauthz.object_type_s3) self.uf = UserFile(self.file1)
def main(argv=sys.argv[1:]): try: repo_dir = argv[0] repo_dir = str(repo_dir).strip() con_str = pynimbusauthz.get_db_connection_string() db_obj = DB(con_str=con_str) user = User(db_obj, uu="CumulusPublicUser") if user == None: raise Exception("No public user") File.create_file(db_obj, repo_dir, user, repo_dir, pynimbusauthz.alias_type_s3) db_obj.commit() except: raise return 0
def setUp(self): # os.environ['CUMULUS_AUTHZ_DDL'] = "/home/bresnaha/Dev/Nimbus/nimbus/cumulus/authz/etc/acl.sql" con = pynimbusauthz.db.make_test_database() self.db = DB(con=con) self.user1 = User(self.db) self.name = "/file/name" self.data = "/etc/group" self.file1 = File.create_file(self.db, self.name, self.user1, self.data, pynimbusauthz.object_type_s3) self.uf = UserFile(self.file1)
def test_add_file_usage_one_file(self): size1 = 100 name = "/file/name" data = "/etc/group" file1 = File.create_file(self.db, name, self.user, data, pynimbusauthz.object_type_s3, size=size1) self.db.commit() u = self.user.get_quota_usage() self.assertEqual(u, size1)
def test_bucket(self): # create a file and a bucket b1 = File.create_file(self.db, "bucket", self.user1, self.data, pynimbusauthz.object_type_s3) f2 = File.create_file(self.db, self.name, self.user1, self.data, pynimbusauthz.object_type_s3, parent=b1) self.db.commit() new_perms = "WR" rc = pynimbusauthz.chmod.main([ "-t", f2.get_object_type(), "-p", b1.get_name(), self.user1.get_id(), f2.get_name(), new_perms ]) self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
def setUp(self): (osf, self.fname) = tempfile.mkstemp() os.close(osf) # os.environ['CUMULUS_AUTHZ_DDL'] = "/home/bresnaha/Dev/Nimbus/nimbus/cumulus/authz/etc/acl.sql" os.environ["NIMBUS_AUTHZ_DB"] = self.fname pynimbusauthz.db.make_test_database(self.fname) self.db = DB(con_str=self.fname) self.user1 = User(self.db) self.name = "/file/name" self.data = "/etc/group" self.file1 = File.create_file(self.db, self.name, self.user1, self.data, pynimbusauthz.object_type_s3) self.uf = UserFile(self.file1) self.db.commit()
def test_add_file_usage_many_files(self): size1 = 100 name = "/file/name" data = "/etc/group" total = 0 for i in range(0, 10): file1 = File.create_file(self.db, name+str(i), self.user, data, pynimbusauthz.object_type_s3, size=size1) total = total + size1 self.db.commit() u = self.user.get_quota_usage() self.assertEqual(u, total)
def test_children(self): child1 = File.create_file(self.db, "kid", self.user1, self.data, pynimbusauthz.object_type_s3, parent=self.file1) self.db.commit() x = child1.get_all_children() self.assertEqual(len(list(x)), 0, "The file should have no children") x = self.uf.get_all_children() found = False for f in x: if f.get_file() == child1: found = True self.assertTrue(found, "We should have found that kid!")
def setUp(self): (osf, self.fname) = tempfile.mkstemp() os.close(osf) # os.environ['CUMULUS_AUTHZ_DDL'] = "/home/bresnaha/Dev/Nimbus/nimbus/cumulus/authz/etc/acl.sql" os.environ['NIMBUS_AUTHZ_DB'] = self.fname pynimbusauthz.db.make_test_database(self.fname) self.db = DB(con_str=self.fname) self.user1 = User(self.db) self.name = "/file/name" self.data = "/etc/group" self.file1 = File.create_file(self.db, self.name, self.user1, self.data, pynimbusauthz.object_type_s3) self.uf = UserFile(self.file1) self.db.commit()
def test_file_children(self): user1 = User(self.db) name = "/file/name" data = "/etc/group" file1 = File.create_file(self.db, name, user1, data, pynimbusauthz.object_type_s3) self.db.commit() child1 = File.create_file(self.db, "kid", user1, data, pynimbusauthz.object_type_s3, parent=file1) self.db.commit() p2 = child1.get_parent() self.assertEqual(p2, file1, "parent not set properly") x = child1.get_all_children() self.assertEqual(len(list(x)), 0, "The file should have no children") x = file1.get_all_children() found = False for f in x: if f == child1: found = True self.assertTrue(found, "We should have found that kid!")
def test_find_by_key(self): user1 = User(self.db) name = "/file/name" key = "/old/path/base" f = File.create_file(self.db, name, user1, key, pynimbusauthz.object_type_s3) self.db.commit() f2a = File.find_files_from_data(self.db, key) found = False for f2 in f2a: tst_key = f2.get_data_key() if tst_key == key: found = True self.assertTrue(found, "key not found")
def test_find_by_key(self): user1 = User(self.db) name = "/file/name" key = "/old/path/base" f = File.create_file(self.db, name, user1, key, pynimbusauthz.object_type_s3) self.db.commit() f2a = File.find_files_from_data(self.db, key) found = False for f2 in f2a: tst_key = f2.get_data_key() if tst_key == key: found = True self.assertTrue(found, "key not found")
def put_object(self, data_obj, bucketName, objectName): data_key = data_obj.get_data_key() md5sum = data_obj.get_md5() fsize = data_obj.get_size() try: # it is ok for someone to put to an existing object # we just need to delete the existing one file = self.get_file_obj(bucketName, objectName) if file != None: pycb.config.bucket.delete_object(file.get_data_key()) file.delete() bf = self.get_file_obj(bucketName) f = File.create_file(self.db_obj, objectName, self.user, data_key, pynimbusauthz.alias_type_s3, parent=bf, size=fsize, md5sum=md5sum) finally: self.db_obj.commit()
def test_basic_file(self): user1 = User(self.db) name = "/file/name" data = "/etc/group" file1 = File.create_file(self.db, name, user1, data, pynimbusauthz.object_type_s3) self.db.commit() x = file1.get_all_children() self.assertEqual(len(list(x)), 0, "The file should have no children") n2 = file1.get_name() self.assertEqual(name, n2, "Names not equal") d2 = file1.get_data_key() self.assertEqual(data, d2, "Data not equal") o2 = file1.get_owner() self.assertEqual(user1, o2, "Owner not equal") p2 = file1.get_parent() self.assertEqual(None, p2, "There should be no parent") b2 = file1.get_object_type() self.assertEqual(pynimbusauthz.object_type_s3, b2, "Type wrong")
def test_children(self): child1 = File.create_file(self.db, "kid", self.user1, self.data, pynimbusauthz.object_type_s3, parent=self.file1) self.db.commit() x = child1.get_all_children() self.assertEqual(len(list(x)), 0, "The file should have no children") x = self.uf.get_all_children() found = False for f in x: if f.get_file() == child1: found = True self.assertTrue(found, "We should have found that kid!")
def test_basic_file(self): user1 = User(self.db) name = "/file/name" data = "/etc/group" file1 = File.create_file(self.db, name, user1, data, pynimbusauthz.object_type_s3) self.db.commit() x = file1.get_all_children() self.assertEqual(len(list(x)), 0, "The file should have no children") n2 = file1.get_name() self.assertEqual(name, n2, "Names not equal") d2 = file1.get_data_key() self.assertEqual(data, d2, "Data not equal") o2 = file1.get_owner() self.assertEqual(user1, o2, "Owner not equal") p2 = file1.get_parent() self.assertEqual(None, p2, "There should be no parent") b2 = file1.get_object_type() self.assertEqual(pynimbusauthz.object_type_s3, b2, "Type wrong")
def test_change_key(self): user1 = User(self.db) name = "/file/name" old_base = "/old/path/base" fname = "/etc/group" new_base = "/new/base/location/dir" f = File.create_file(self.db, name, user1, old_base + fname, pynimbusauthz.object_type_s3) self.assertEqual(old_base + fname, f.get_data_key(), "old value not euqal") new_key = new_base + fname f.set_data_key(new_key) self.db.commit() tst_new_key = f.get_data_key() self.assertEqual(tst_new_key, new_key, "%s should equal %s" % (tst_new_key, new_key)) f2 = File.get_file(self.db, name, pynimbusauthz.object_type_s3) tst_new_key = f2.get_data_key() self.assertEqual(tst_new_key, new_key, "%s should equal %s" % (tst_new_key, new_key))
def put_object(self, data_obj, bucketName, objectName): data_key = data_obj.get_data_key() md5sum = data_obj.get_md5() fsize = data_obj.get_size() try: # it is ok for someone to put to an existing object # we just need to delete the existing one file = self.get_file_obj(bucketName, objectName) if file != None: pycb.config.bucket.delete_object(file.get_data_key()) file.delete() bf = self.get_file_obj(bucketName) f = File.create_file(self.db_obj, objectName, self.user, data_key, pynimbusauthz.alias_type_s3, parent=bf, size=fsize, md5sum=md5sum) finally: self.db_obj.commit()
def put_bucket(self, bucketName): try: f = File.create_file(self.db_obj, bucketName, self.user, bucketName, pynimbusauthz.alias_type_s3) finally: self.db_obj.commit()
def xtest_international_file(self): user1 = User(self.db) name = os.environ["CUMULUS_WORD"] data = "/etc/group" file1 = File.create_file(self.db, name, user1, data, pynimbusauthz.object_type_s3) self.db.commit()
def put_bucket(self, bucketName): pycb.log(logging.INFO, "===== def put_bucket of cbAuthzSecurity.py") try: f = File.create_file(self.db_obj, bucketName, self.user, bucketName, pynimbusauthz.alias_type_s3) finally: self.db_obj.commit()
def put_bucket(self, bucketName): try: f = File.create_file(self.db_obj, bucketName, self.user, bucketName, pynimbusauthz.alias_type_s3) finally: self.db_obj.commit()