def test_create_same_alias(self): user1 = User(self.db) alias1 = user1.create_alias("/name/", pynimbusauthz.alias_type_s3, "name@") try: alias2 = user1.create_alias("/name/", pynimbusauthz.alias_type_s3, "name@") self.fail("This should have caused an conflict on insert") except: pass
def test_create_alias_simple(self): user1 = User(self.db) alias1 = user1.create_alias("/name/", pynimbusauthz.alias_type_s3, "testname@") user2 = alias1.get_canonical_user() self.assertEqual(user1.get_id(), user2.get_id(), "User IDs should be equal") alias1 = user1.create_alias("/name2", pynimbusauthz.alias_type_s3, "name2@", "pooP") user2 = alias1.get_canonical_user() self.assertEqual(user1.get_id(), user2.get_id(), "User IDs should be equal") print alias1
def create_user(self, display_name, id, pw, opts): pycb.log(logging.INFO, "===== def create_user of cbAuthzSecurity.py") db_obj = DB(con_str=self.con_str) user = User(db_obj, friendly=display_name) user_alias = user.create_alias(id, "s3", display_name, alias_data=pw) db_obj.commit() db_obj.close()
def test_delete_alias(self): user1 = User(self.db) alias1 = user1.create_alias("/name/", pynimbusauthz.alias_type_s3, "name@") alias1.remove() alias2 = user1.get_alias("/name/", pynimbusauthz.alias_type_s3) self.assertEqual(alias2, None, "The alias should be gone")
def test_find_user_alias(self): user1 = User(self.db) self.db.commit() alias_name = "helloname" alias1 = user1.create_alias(alias_name, pynimbusauthz.alias_type_s3, alias_name) self.db.commit() fid = "%%" + alias_name[1:] lid = alias_name[:-1] + "%%" mid = "%%" + alias_name[1:-1] + "%%" # find by exact id u_all = UserAlias.find_alias(self.db, alias_name) self.assertNotEqual(u_all, None, "we should have found somethings") self.assertTrue(self.find_user_id(alias1, u_all)) # find by exact partial 1 u_all = UserAlias.find_alias(self.db, fid) self.assertTrue(self.find_user_id(alias1, u_all)) # find by exact partial 1 u_all = UserAlias.find_alias(self.db, lid) self.assertTrue(self.find_user_id(alias1, u_all)) # find by exact partial 1 u_all = UserAlias.find_alias(self.db, mid) self.assertNotEqual(u_all, None, "we should have found somethings") self.assertTrue(self.find_user_id(alias1, u_all))
def test_alias_lookup_simple(self): user1 = User(self.db) alias1 = user1.create_alias("/name/", pynimbusauthz.alias_type_s3, "name1@") alias2 = user1.get_alias("/name/", pynimbusauthz.alias_type_s3) self.assertEqual(alias1.get_name(), alias2.get_name(), "Alias names should be the same") self.assertEqual(alias1.get_type(), alias2.get_type(), "Alias types should be the same") self.assertEqual(alias1.get_data(), alias2.get_data(), "Alias data should be the same")
def test_alias_lookup(self): user1 = User(self.db) alias1 = user1.create_alias("/name/", pynimbusauthz.alias_type_s3, "1") aliasX = user1.create_alias("/name2", pynimbusauthz.alias_type_s3, "2") aliasX = user1.create_alias("/name3", pynimbusauthz.alias_type_s3, "3") aliasX = user1.create_alias("/name4", pynimbusauthz.alias_type_s3, "4") all_alias = user1.get_all_alias() found = False for a in all_alias: if a.get_name() == alias1.get_name() and a.get_type() == alias1.get_type(): found = True self.assertTrue(found, "We should have found the alias") all_alias = user1.get_alias_by_type(pynimbusauthz.alias_type_s3) found = False for a in all_alias: if a.get_name() == alias1.get_name() and a.get_type() == alias1.get_type(): found = True self.assertTrue(found, "We should have found the alias")
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) user_uu = None if len(args) == 1: user_uu = args[0] if opts.new: user = User(db_obj, user_uu, friendly=opts.friendlyname, create=True) pynimbusauthz.print_msg(opts, 0, "User %s added" % (user.get_id())) else: user = User(db_obj, user_uu) pynimbusauthz.print_msg(opts, 0, "User %s" % (user.get_id())) if opts.alias != None: user_alias = user.get_alias(opts.alias, opts.type) if user_alias == None: user_alias = user.create_alias(opts.alias, opts.type, opts.friendlyname) pynimbusauthz.print_msg( opts, 0, "Creating new alias %s:%s" % (opts.type, opts.alias)) if opts.genkey: data = pynimbusauthz.random_string_gen(42) pynimbusauthz.print_msg(opts, 0, "Key generated %s" % (data)) user_alias.set_data(data) elif opts.setkey != None: data = opts.setkey user_alias.set_data(data) pynimbusauthz.print_msg(opts, 0, "updated the alias key") if opts.remove_alias != None: user_alias = user.get_alias(opts.remove_alias, opts.type) user_alias.remove() if opts.remove: pynimbusauthz.print_msg(opts, 1, "Removing user %s" % (user.get_id())) if opts.force: pynimbusauthz.print_msg(opts, 1, "Removing all references") user.destroy_brutally() else: user.destroy() db_obj.commit() except AuthzException, ae: print ae return ae.get_rc()
def test_set_alias_data(self): user1 = User(self.db) self.db.commit() alias_name = "helloname" alias1 = user1.create_alias(alias_name, pynimbusauthz.alias_type_s3, alias_name) key = "helloworld" alias1.set_data(key) self.db.commit() alias2 = user1.get_alias(alias_name, pynimbusauthz.alias_type_s3) self.assertEqual(alias1.get_data(), alias2.get_data(), "alias not equal") self.assertEqual(key, alias2.get_data(), "alias not equal")
def test_alias_lookup(self): user1 = User(self.db) alias1 = user1.create_alias("/name/", pynimbusauthz.alias_type_s3, "1") aliasX = user1.create_alias("/name2", pynimbusauthz.alias_type_s3, "2") aliasX = user1.create_alias("/name3", pynimbusauthz.alias_type_s3, "3") aliasX = user1.create_alias("/name4", pynimbusauthz.alias_type_s3, "4") all_alias = user1.get_all_alias() found = False for a in all_alias: if a.get_name() == alias1.get_name() and a.get_type( ) == alias1.get_type(): found = True self.assertTrue(found, "We should have found the alias") all_alias = user1.get_alias_by_type(pynimbusauthz.alias_type_s3) found = False for a in all_alias: if a.get_name() == alias1.get_name() and a.get_type( ) == alias1.get_type(): found = True self.assertTrue(found, "We should have found the alias")
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) user_uu = None if len(args) == 1: user_uu = args[0] if opts.new: user = User(db_obj, user_uu, friendly=opts.friendlyname, create=True) pynimbusauthz.print_msg(opts, 0, "User %s added" % (user.get_id())) else: user = User(db_obj, user_uu) pynimbusauthz.print_msg(opts, 0, "User %s" % (user.get_id())) if opts.alias != None: user_alias = user.get_alias(opts.alias, opts.type) if user_alias == None: user_alias = user.create_alias(opts.alias, opts.type, opts.friendlyname) pynimbusauthz.print_msg(opts, 0, "Creating new alias %s:%s" % (opts.type,opts.alias)) if opts.genkey: data = pynimbusauthz.random_string_gen(42) pynimbusauthz.print_msg(opts, 0, "Key generated %s" % (data)) user_alias.set_data(data) elif opts.setkey != None: data = opts.setkey user_alias.set_data(data) pynimbusauthz.print_msg(opts, 0, "updated the alias key") if opts.remove_alias != None: user_alias = user.get_alias(opts.remove_alias, opts.type) user_alias.remove() if opts.remove: pynimbusauthz.print_msg(opts, 1, "Removing user %s" % (user.get_id())) if opts.force: pynimbusauthz.print_msg(opts, 1, "Removing all references") user.destroy_brutally() else: user.destroy() db_obj.commit() except AuthzException, ae: print ae return ae.get_rc()
def create_user(self, display_name, id, pw, opts): db_obj = DB(con_str=self.con_str) user = User(db_obj, friendly=display_name) user_alias = user.create_alias(id, "s3", display_name, alias_data=pw) db_obj.commit() db_obj.close()