Example #1
0
class TestTouchCli(unittest.TestCase):

    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.db.commit()

    def tearDown(self):
        self.db.close()
        os.remove(self.fname)

    def test_basic_touch(self):
        fname = str(uuid.uuid1())
        data = str(uuid.uuid1())
        f = File.get_file(self.db, fname, pynimbusauthz.object_type_s3)
        self.assertEqual(f, None)
        rc = pynimbusauthz.touch.main([self.user1.get_id(), fname, data])
        self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
        f = File.get_file(self.db, fname, pynimbusauthz.object_type_s3)
        self.assertNotEqual(f, None)

    def test_bucket_touch(self):
        fname = str(uuid.uuid1())
        data = str(uuid.uuid1())
        rc = pynimbusauthz.touch.main(["-t", pynimbusauthz.object_type_s3, self.user1.get_id(), fname, data])
        self.assertEqual(rc, 0, "CLI should return success %d" % (rc))

        f = File.get_file(self.db, fname, pynimbusauthz.object_type_s3)
        self.assertNotEqual(f, None)

    def test_under_bucket_touch(self):
        bname = str(uuid.uuid1())
        fname = str(uuid.uuid1())
        data = str(uuid.uuid1())
        rc = pynimbusauthz.touch.main(["-t", pynimbusauthz.object_type_s3, self.user1.get_id(), bname, data])
        self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
        rc = pynimbusauthz.touch.main(["-p", bname, self.user1.get_id(), fname, data])
        self.assertEqual(rc, 0, "CLI should return success %d" % (rc))

        b1 = File.get_file(self.db, bname, pynimbusauthz.object_type_s3)
        f1 = File.get_file(self.db, fname, pynimbusauthz.object_type_s3, parent=b1)

        self.assertNotEqual(b1, None)
        self.assertNotEqual(f1, None)


    def test_bad_opts(self):
        bname = str(uuid.uuid1())
        fname = str(uuid.uuid1())
        data = str(uuid.uuid1())
        rc = pynimbusauthz.touch.main([bname, data])
        self.assertEqual(rc, 32, "CLI should return failure %d" % (rc))
        rc = pynimbusauthz.touch.main(["-p", bname, self.user1.get_id(), fname, data])
        self.assertEqual(rc, 33, "CLI should return failure %d" % (rc))
Example #2
0
    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
Example #3
0
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()
Example #4
0
    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
Example #5
0
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()
Example #6
0
    def test_destroy_user(self):
        user1 = User(self.db)
        uu = user1.get_id()
        user1.destroy_brutally()

        try:
            user1 = User(self.db, uu)
            self.fail("The uuid should have been deleted %s" % (uu))
        except:
            pass
Example #7
0
    def test_basic_stat(self):
        user2 = User(self.db)
        self.db.commit()

        rc = pynimbusauthz.chmod.main([user2.get_id(), self.name, "Rrw"])
        self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
        rc = pynimbusauthz.stat.main([self.name])
        self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
        rc = pynimbusauthz.stat.main(["-a", self.name])
        self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
Example #8
0
    def test_basic_stat(self):
        user2 = User(self.db)
        self.db.commit()

        rc = pynimbusauthz.chmod.main([user2.get_id(), self.name, "Rrw"])
        self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
        rc = pynimbusauthz.stat.main([self.name])
        self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
        rc = pynimbusauthz.stat.main(["-a", self.name])
        self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
Example #9
0
    def test_destroy_user(self):
        user1 = User(self.db)
        uu = user1.get_id()
        user1.destroy_brutally()

        try:
            user1 = User(self.db, uu)
            self.fail("The uuid should have been deleted %s" % (uu))
        except:
            pass
Example #10
0
 def test_basic_alias(self):
     user = User(self.db)
     uu = user.get_id()
     aname = "alias1"
     self.db.commit()
     rc = pynimbusauthz.add_user.main(["-a", aname, uu])
     self.assertEqual(rc, 0, "CLI should return success")
     ua = user.get_alias(aname, pynimbusauthz.alias_type_s3)
     self.assertNotEqual(ua, None, "alias not found")
     rc = pynimbusauthz.add_user.main(["-x", aname, uu])
     self.assertEqual(rc, 0, "CLI should return success")
     ua = user.get_alias(aname, pynimbusauthz.alias_type_s3)
     self.assertEqual(ua, None, "alias should not be found")
Example #11
0
 def test_basic_alias(self):
     user = User(self.db)
     uu = user.get_id()
     aname = "alias1"
     self.db.commit()
     rc = pynimbusauthz.add_user.main(["-a", aname, uu])
     self.assertEqual(rc, 0, "CLI should return success")
     ua = user.get_alias(aname, pynimbusauthz.alias_type_s3)
     self.assertNotEqual(ua, None, "alias not found")
     rc = pynimbusauthz.add_user.main(["-x", aname, uu])
     self.assertEqual(rc, 0, "CLI should return success")
     ua = user.get_alias(aname, pynimbusauthz.alias_type_s3)
     self.assertEqual(ua, None, "alias should not be found")
Example #12
0
    def test_find_user(self):
        user1 = User(self.db)
        self.db.commit()
        id = user1.get_id()
        fid = id[1:]
        lid = id[:-1]
        mid = id[1:-1]

        # find by exact id
        u_all = User.find_user(self.db, id)
        self.assertNotEqual(u_all, None, "we should have found somethings")
        self.assertTrue(self.find_user_id(user1, u_all))
        # find by exact partial 1
        u_all = User.find_user(self.db, fid)
        self.assertTrue(self.find_user_id(user1, u_all))
        # find by exact partial 1
        u_all = User.find_user(self.db, lid)
        self.assertTrue(self.find_user_id(user1, u_all))
        # find by exact partial 1
        u_all = User.find_user(self.db, mid)
        self.assertNotEqual(u_all, None, "we should have found somethings")
        self.assertTrue(self.find_user_id(user1, u_all))
Example #13
0
    def test_find_user(self):
        user1 = User(self.db)
        self.db.commit()
        id = user1.get_id()
        fid = id[1:]
        lid = id[:-1]
        mid = id[1:-1]

        # find by exact id
        u_all = User.find_user(self.db, id)
        self.assertNotEqual(u_all, None, "we should have found somethings")
        self.assertTrue(self.find_user_id(user1, u_all))
        # find by exact partial 1
        u_all = User.find_user(self.db, fid)
        self.assertTrue(self.find_user_id(user1, u_all))
        # find by exact partial 1
        u_all = User.find_user(self.db, lid)
        self.assertTrue(self.find_user_id(user1, u_all))
        # find by exact partial 1
        u_all = User.find_user(self.db, mid)
        self.assertNotEqual(u_all, None, "we should have found somethings")
        self.assertTrue(self.find_user_id(user1, u_all))
Example #14
0
class TestChmodCli(unittest.TestCase):
    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 tearDown(self):
        self.db.close()
        os.remove(self.fname)

    def validate_perms(self, new):
        f = File.get_file_from_db_id(self.db, self.file1.get_id())
        uf = UserFile(f, self.user1)
        perms = uf.get_perms(force=True)
        for p in new:
            self.assertTrue(p in perms,
                            "bad perms set %s != %s" % (new, perms))
        self.assertEqual(len(perms), len(new),
                         "perms dont match %s != %s" % (new, perms))

    def test_basic_chmod(self):
        uu = str(uuid.uuid1())
        new_perms = "WR"
        rc = pynimbusauthz.chmod.main(
            [self.user1.get_id(),
             self.file1.get_name(), new_perms])
        self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
        self.validate_perms(new_perms)

    def test_type_chmod(self):
        uu = str(uuid.uuid1())
        new_perms = "WRr"
        rc = pynimbusauthz.chmod.main([
            "-t",
            self.file1.get_object_type(),
            self.user1.get_id(),
            self.file1.get_name(), new_perms
        ])
        self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
        self.validate_perms(new_perms)

    def test_badopts(self):
        new_perms = "WR"

        rc = pynimbusauthz.chmod.main(
            ["-t", self.file1.get_object_type(),
             self.user1.get_id()])
        self.assertEqual(rc, 32, "CLI should return success %d" % (rc))

        rc = pynimbusauthz.chmod.main(
            [self.user1.get_id(), "notafile", new_perms])
        self.assertEqual(rc, 33, "CLI should return success %d" % (rc))
        rc = pynimbusauthz.chmod.main([
            "-t",
            self.file1.get_object_type(), "-p", "nobucket",
            self.user1.get_id(),
            self.file1.get_name(), new_perms
        ])
        self.assertEqual(rc, 33, "CLI should return success %d" % (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))
Example #15
0
    def test_basic_user(self):
        user1 = User(self.db)
        user2 = User(self.db, user1.get_id())

        self.assertEqual(user1.get_id(), user2.get_id(),
                         "User IDs should be equal")
Example #16
0
 def test_user_to_string(self):
     user1 = User(self.db)
     uu = user1.get_id()
     self.assertEqual(str(user1), uu,
                      "toString function not working for user")
Example #17
0
 def test_user_to_string(self):
     user1 = User(self.db)
     uu = user1.get_id()
     self.assertEqual(str(user1), uu, "toString function not working for user")
Example #18
0
    def test_basic_user(self):
        user1 = User(self.db)
        user2 = User(self.db, user1.get_id())

        self.assertEqual(user1.get_id(), user2.get_id(), "User IDs should be equal")
Example #19
0
class TestChmodCli(unittest.TestCase):

    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 tearDown(self):
        self.db.close()
        os.remove(self.fname)

    def validate_perms(self, new):
        f = File.get_file_from_db_id(self.db, self.file1.get_id())
        uf = UserFile(f, self.user1)
        perms = uf.get_perms(force=True)
        for p in new:
            self.assertTrue(p in perms, "bad perms set %s != %s" % (new, perms))
        self.assertEqual(len(perms), len(new), "perms dont match %s != %s" % (new, perms))

    def test_basic_chmod(self):
        uu = str(uuid.uuid1())
        new_perms = "WR"
        rc = pynimbusauthz.chmod.main([self.user1.get_id(), self.file1.get_name(), new_perms])
        self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
        self.validate_perms(new_perms)

    def test_type_chmod(self):
        uu = str(uuid.uuid1())
        new_perms = "WRr"
        rc = pynimbusauthz.chmod.main(["-t", self.file1.get_object_type(), self.user1.get_id(), self.file1.get_name(), new_perms])
        self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
        self.validate_perms(new_perms)

    def test_badopts(self):
        new_perms = "WR"

        rc = pynimbusauthz.chmod.main(["-t", self.file1.get_object_type(), self.user1.get_id()])
        self.assertEqual(rc, 32, "CLI should return success %d" % (rc))

        rc = pynimbusauthz.chmod.main([self.user1.get_id(), "notafile", new_perms])
        self.assertEqual(rc, 33, "CLI should return success %d" % (rc))
        rc = pynimbusauthz.chmod.main(["-t", self.file1.get_object_type(), "-p", "nobucket", self.user1.get_id(), self.file1.get_name(), new_perms])
        self.assertEqual(rc, 33, "CLI should return success %d" % (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))
Example #20
0
class TestTouchCli(unittest.TestCase):
    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.db.commit()

    def tearDown(self):
        self.db.close()
        os.remove(self.fname)

    def test_basic_touch(self):
        fname = str(uuid.uuid1())
        data = str(uuid.uuid1())
        f = File.get_file(self.db, fname, pynimbusauthz.object_type_s3)
        self.assertEqual(f, None)
        rc = pynimbusauthz.touch.main([self.user1.get_id(), fname, data])
        self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
        f = File.get_file(self.db, fname, pynimbusauthz.object_type_s3)
        self.assertNotEqual(f, None)

    def test_bucket_touch(self):
        fname = str(uuid.uuid1())
        data = str(uuid.uuid1())
        rc = pynimbusauthz.touch.main([
            "-t", pynimbusauthz.object_type_s3,
            self.user1.get_id(), fname, data
        ])
        self.assertEqual(rc, 0, "CLI should return success %d" % (rc))

        f = File.get_file(self.db, fname, pynimbusauthz.object_type_s3)
        self.assertNotEqual(f, None)

    def test_under_bucket_touch(self):
        bname = str(uuid.uuid1())
        fname = str(uuid.uuid1())
        data = str(uuid.uuid1())
        rc = pynimbusauthz.touch.main([
            "-t", pynimbusauthz.object_type_s3,
            self.user1.get_id(), bname, data
        ])
        self.assertEqual(rc, 0, "CLI should return success %d" % (rc))
        rc = pynimbusauthz.touch.main(
            ["-p", bname, self.user1.get_id(), fname, data])
        self.assertEqual(rc, 0, "CLI should return success %d" % (rc))

        b1 = File.get_file(self.db, bname, pynimbusauthz.object_type_s3)
        f1 = File.get_file(self.db,
                           fname,
                           pynimbusauthz.object_type_s3,
                           parent=b1)

        self.assertNotEqual(b1, None)
        self.assertNotEqual(f1, None)

    def test_bad_opts(self):
        bname = str(uuid.uuid1())
        fname = str(uuid.uuid1())
        data = str(uuid.uuid1())
        rc = pynimbusauthz.touch.main([bname, data])
        self.assertEqual(rc, 32, "CLI should return failure %d" % (rc))
        rc = pynimbusauthz.touch.main(
            ["-p", bname, self.user1.get_id(), fname, data])
        self.assertEqual(rc, 33, "CLI should return failure %d" % (rc))