Example #1
0
 def test_setPasswordInvalidUser(self):
     user = RestAuthUser(self.conn, username)
     try:
         user.set_password(password)
         self.fail()
     except error.ResourceNotFound as e:
         self.assertEqual(e.get_type(), "user")
Example #2
0
 def test_getGroupsInvalidUser(self):
     user = RestAuthUser(self.conn, "foobar")
     try:
         user.get_groups()
         self.fail()
     except error.ResourceNotFound as e:
         self.assertEqual("user", e.get_type())
Example #3
0
 def test_forbidden(self):
     conn = RestAuthConnection(rest_host, 'example.net', 'nopass')
     try:
         RestAuthUser.get_all(conn)
         self.fail()
     except error.Forbidden:
         pass
Example #4
0
 def test_wrongHost(self):
     conn = RestAuthConnection('http://[:2]:8003', 'wrong', 'credentials', timeout=1.0)
     try:
         RestAuthUser.get(conn, 'foobar')
         self.fail()
     except HttpException as e:
         e.get_cause()
Example #5
0
 def test_removeInvalidUser(self):
     user = RestAuthUser(self.conn, "invalid")
     try:
         user.remove()
         self.fail()
     except error.ResourceNotFound as e:
         self.assertEqual("user", e.get_type())
Example #6
0
    def test_removePropertyWithInvalidUser(self):
        user = RestAuthUser(self.conn, "new user")

        try:
            user.remove_property("foobar")
            self.fail()
        except error.ResourceNotFound as e:
            self.assertEqual("user", e.get_type())
Example #7
0
 def test_invalidUser(self):
     properties = {propKey1: propVal1}
     user = RestAuthUser(self.conn, "invalid")
     try:
         user.set_properties(properties)
         self.fail()
     except error.ResourceNotFound:
         pass
Example #8
0
 def test_createUserTwice(self):
     user = RestAuthUser.create(self.conn, "mati", "password")
     try:
         RestAuthUser.create(self.conn, "mati", "new password")
         self.fail()
     except UserExists:
         self.assertEqual([user], RestAuthUser.get_all(self.conn))
         self.assertTrue(user.verify_password("password"))
         self.assertFalse(user.verify_password("new password"))
Example #9
0
    def setUp(self):
        super(SimpleUserGroupTests, self).setUp()
        if RestAuthUser.get_all(self.conn):
            raise RuntimeError("Found leftover users.")
        if RestAuthGroup.get_all(self.conn):
            raise RuntimeError("Found leftover groups.")

        self.user = RestAuthUser.create(self.conn, username, password)
        self.group = RestAuthGroup.create(self.conn, groupname)
Example #10
0
    def test_existingUser(self):
        user = RestAuthUser.create(self.conn, username)

        try:
            RestAuthUser.create_test(self.conn, username)
            self.fail()
        except UserExists:
            self.assertEqual([user], RestAuthUser.get_all(self.conn))
        finally:
            user.remove()
Example #11
0
    def test_removeUser(self):
        user = RestAuthUser.create(self.conn, username, password)
        user.remove()

        self.assertEqual([], RestAuthUser.get_all(self.conn))
        try:
            RestAuthUser.get(self.conn, username)
            self.fail()
        except error.ResourceNotFound as e:
            self.assertEqual("user", e.get_type())
Example #12
0
    def test_setPropertyWithInvalidUser(self):
        user = RestAuthUser(self.conn, username + " foo")
        try:
            user.set_property(propKey, propVal)
            self.fail()
        except error.ResourceNotFound as e:
            self.assertEqual("user", e.get_type())

            # verify that no user was created:
            self.assertNotEqual(user, self.user)
            self.assertEqual([self.user], RestAuthUser.get_all(self.conn))
Example #13
0
 def test_setTooShortPassword(self):
     user = RestAuthUser.create(self.conn, username, password)
     try:
         user.set_password("x")
         self.fail()
     except error.PreconditionFailed:
         self.assertTrue(user.verify_password(password))
         self.assertFalse(user.verify_password("x"))
Example #14
0
    def test_getAll(self):
        self.assertEqual([], RestAuthUser.get_all(self.conn, flat=True))

        RestAuthUser.create(self.conn, username)
        self.assertEqual([username], RestAuthUser.get_all(self.conn, flat=True))

        RestAuthUser.create(self.conn, username2)
        self.assertCountEqual([username, username2], RestAuthUser.get_all(self.conn, flat=True))
Example #15
0
    def test_removeInvalidProperty(self):
        self.assertEquals(None, self.user.create_property(propKey, propVal))

        try:
            self.user.remove_property(propKey + " foo")
            self.fail()
        except error.ResourceNotFound as e:
            self.assertEqual("property", e.get_type())
            self.assertEqual([self.user], RestAuthUser.get_all(self.conn))
            self.assertProperties(**{propKey: propVal})
Example #16
0
    def test_disableUser(self):
        newpass = "******" + password
        user = RestAuthUser.create(self.conn, username, password)
        self.assertTrue(user.verify_password(password))
        self.assertFalse(user.verify_password(newpass))

        user.set_password()
        self.assertFalse(user.verify_password(password))
        self.assertFalse(user.verify_password(newpass))
        self.assertFalse(user.verify_password(""))
Example #17
0
    def test_badRequestPut(self):
        # we need to create it first, otherwise we might get a 404 instead
        user = RestAuthUser.create(self.conn, 'testuser', 'password')
        try:
            self.conn.put(str('/users/testuser/'), {'bad': 'request'})
            self.fail()
        except error.BadRequest:
            pass

        user.remove()
Example #18
0
    def test_UnsupportedMediaTypePut(self):
        # we need to create it first, otherwise we might get a 404 instead
        old = self.conn.content_handler
        user = RestAuthUser.create(self.conn, 'testuser', 'password')
        self.conn.set_content_handler(wrongContentHandler())

        try:
            self.conn.put('/users/testuser/', {'foo': 'bar'})
            self.fail()
        except error.UnsupportedMediaType:
            pass
        finally:
            user.remove()
        self.conn.set_content_handler(old)
Example #19
0
    def test_removePropertyFromWrongUser(self):
        """
        Purpose of this test is to add a property to one user, and
        verify that deleting it from the *other* user does not delete it
        for the original user.
        """

        user_2 = RestAuthUser.create(self.conn, "new user", "password")
        self.assertEquals(None, self.user.create_property(propKey, propVal))

        try:
            user_2.remove_property(propKey)
            self.fail()
        except error.ResourceNotFound as e:
            self.assertEqual("property", e.get_type())

        self.assertProperties(user=user_2, **{})
Example #20
0
    def test_createUserWithNoPassword(self):
        user1 = RestAuthUser.create(self.conn, username)
        self.assertEqual([user1], RestAuthUser.get_all(self.conn))
        self.assertEqual(user1, RestAuthUser.get(self.conn, username))
        # check that no password verifies as correct
        self.assertFalse(user1.verify_password(""))
        self.assertFalse(user1.verify_password(password))

        # use empty string instead:
        user2 = RestAuthUser.create(self.conn, username + "1", "")
        self.assertCountEqual([user1, user2], RestAuthUser.get_all(self.conn))
        self.assertEqual(user2, RestAuthUser.get(self.conn, username + "1"))
        # check that no password verifies as correct
        self.assertFalse(user2.verify_password(""))
        self.assertFalse(user2.verify_password(password))
        if checked is True:
            sys.exit(0)
        elif checked is False:
            sys.exit(1)
        # else: cache miss

from RestAuthClient.common import RestAuthConnection
from RestAuthClient.user import RestAuthUser as User

# Setup RestAuth connection
conn = RestAuthConnection(
    config.get(section, 'server'),
    config.get(section, 'user'),
    config.get(section, 'password'),
)
user = User(conn, username)

# Actual RestAuth queries in case cache does not match
if authtype == 'pass':
    if user.verify_password(line2):
        # set in cache if defined
        if cache is not None:
            cache.set_password(username, line2)

        sys.exit(0)
    else:
        sys.exit(1)

elif authtype == 'group':
    checked = set(line2.split())
    groups = set([g.name for g in user.get_groups()])
Example #22
0
 def test_createUserTestWithInvalidUsername(self):
     try:
         RestAuthUser.create_test(self.conn, "foo/bar")
         self.fail()
     except error.PreconditionFailed:
         self.assertEqual([], RestAuthUser.get_all(self.conn))
Example #23
0
    def setUp(self):
        super(PropertyBaseTests, self).setUp()
        if RestAuthUser.get_all(self.conn):
            raise RuntimeError("Found leftover users.")

        self.user = RestAuthUser.create(self.conn, username, password)
Example #24
0
 def test_createUserWithInvalidProperties(self):
     properties = {propKey: propVal, "foo:bar": propVal2}
     args = [self.conn, username, password, properties]
     self.assertRaises(error.PreconditionFailed, RestAuthUser.create, *args)
     self.assertEqual([], RestAuthUser.get_all(self.conn))
Example #25
0
 def test_createUserWithProperty(self):
     properties = {propKey: propVal}
     user = RestAuthUser.create(self.conn, username, password, properties)
     self.assertProperties(user=user, **properties)
Example #26
0
    def test_createUserUnicode(self):
        user = RestAuthUser.create(self.conn, username, "password")

        self.assertEqual([user], RestAuthUser.get_all(self.conn))
        self.assertEqual(user, RestAuthUser.get(self.conn, username))
Example #27
0
    def test_createUserWithSpace(self):
        user = RestAuthUser.create(self.conn, "mati space", "password")

        self.assertEqual([user], RestAuthUser.get_all(self.conn))
        self.assertEqual(user, RestAuthUser.get(self.conn, "mati space"))
Example #28
0
 def test_createPropertyForInvalidUser(self):
     user = RestAuthUser(self.conn, "foo:bar")
     try:
         user.create_property_test(propKey, propVal)
     except error.ResourceNotFound as e:
         self.assertEqual("user", e.get_type())
Example #29
0
 def tearDown(self):
     for user in RestAuthUser.get_all(self.conn):
         user.remove()
Example #30
0
 def tearDown(self):
     for user in RestAuthUser.get_all(self.conn):
         user.remove()
     for grp in RestAuthGroup.get_all(self.conn):
         grp.remove()
Example #31
0
 def setUp(self):
     super(BasicTests, self).setUp()
     if RestAuthUser.get_all(self.conn):
         raise RuntimeError("Found leftover users.")