Example #1
0
 def test_common_methods(self):
     auth = DummyAuthorizer()
     # create user
     auth.add_user(USER, PASSWD, HOME)
     auth.add_anonymous(HOME)
     # check credentials
     auth.validate_authentication(USER, PASSWD, None)
     self.assertRaises(AuthenticationFailed, auth.validate_authentication,
                       USER, 'wrongpwd', None)
     auth.validate_authentication('anonymous', 'foo', None)
     auth.validate_authentication('anonymous', '', None)  # empty passwd
     # remove them
     auth.remove_user(USER)
     auth.remove_user('anonymous')
     # raise exc if user does not exists
     self.assertRaises(KeyError, auth.remove_user, USER)
     # raise exc if path does not exist
     self.assertRaisesRegex(ValueError, 'no such directory', auth.add_user,
                            USER, PASSWD, '?:\\')
     self.assertRaisesRegex(ValueError, 'no such directory',
                            auth.add_anonymous, '?:\\')
     # raise exc if user already exists
     auth.add_user(USER, PASSWD, HOME)
     auth.add_anonymous(HOME)
     self.assertRaisesRegex(ValueError, 'user %r already exists' % USER,
                            auth.add_user, USER, PASSWD, HOME)
     self.assertRaisesRegex(ValueError, "user 'anonymous' already exists",
                            auth.add_anonymous, HOME)
     auth.remove_user(USER)
     auth.remove_user('anonymous')
     # raise on wrong permission
     self.assertRaisesRegex(ValueError,
                            "no such permission",
                            auth.add_user,
                            USER,
                            PASSWD,
                            HOME,
                            perm='?')
     self.assertRaisesRegex(ValueError,
                            "no such permission",
                            auth.add_anonymous,
                            HOME,
                            perm='?')
     # expect warning on write permissions assigned to anonymous user
     for x in "adfmw":
         self.assertRaisesRegex(
             RuntimeWarning,
             "write permissions assigned to anonymous user.",
             auth.add_anonymous,
             HOME,
             perm=x)
Example #2
0
 def test_common_methods(self):
     auth = DummyAuthorizer()
     # create user
     auth.add_user(USER, PASSWD, HOME)
     auth.add_anonymous(HOME)
     # check credentials
     auth.validate_authentication(USER, PASSWD, None)
     self.assertRaises(AuthenticationFailed,
                       auth.validate_authentication, USER, 'wrongpwd', None)
     auth.validate_authentication('anonymous', 'foo', None)
     auth.validate_authentication('anonymous', '', None)  # empty passwd
     # remove them
     auth.remove_user(USER)
     auth.remove_user('anonymous')
     # raise exc if user does not exists
     self.assertRaises(KeyError, auth.remove_user, USER)
     # raise exc if path does not exist
     self.assertRaisesRegex(ValueError,
                            'no such directory',
                            auth.add_user, USER, PASSWD, '?:\\')
     self.assertRaisesRegex(ValueError,
                            'no such directory',
                            auth.add_anonymous, '?:\\')
     # raise exc if user already exists
     auth.add_user(USER, PASSWD, HOME)
     auth.add_anonymous(HOME)
     self.assertRaisesRegex(ValueError,
                            'user %r already exists' % USER,
                            auth.add_user, USER, PASSWD, HOME)
     self.assertRaisesRegex(ValueError,
                            "user 'anonymous' already exists",
                            auth.add_anonymous, HOME)
     auth.remove_user(USER)
     auth.remove_user('anonymous')
     # raise on wrong permission
     self.assertRaisesRegex(ValueError,
                            "no such permission",
                            auth.add_user, USER, PASSWD, HOME, perm='?')
     self.assertRaisesRegex(ValueError,
                            "no such permission",
                            auth.add_anonymous, HOME, perm='?')
     # expect warning on write permissions assigned to anonymous user
     for x in "adfmw":
         self.assertRaisesRegex(
             RuntimeWarning,
             "write permissions assigned to anonymous user.",
             auth.add_anonymous, HOME, perm=x)