def test_remove_user_from_namespace_fail_no_such_user(idstorage):
    idstorage.create_namespace(NamespaceID('foo'))
    idstorage.add_user_to_namespace(NamespaceID('foo'),
                                    User(AuthsourceID('as'), Username('u')))
    fail_remove_namespace_user(
        idstorage, NamespaceID('foo'), User(AuthsourceID('as'),
                                            Username('u1')),
        NoSuchUserError('User as/u1 does not administrate namespace foo'))
示例#2
0
 def _check_valid_user(self, user):
     """
     :raises NoSuchAuthsourceError: if there's no handler for the user's authsource.
     :raises NoSuchUserError: if the user is invalid according to the appropriate user handler.
     """
     not_none(user, 'user')
     if not self._lookup.is_valid_user(user):
         raise NoSuchUserError('{}/{}'.format(user.authsource_id.id,
                                              user.username.name))
示例#3
0
def test_add_user_to_namespace_fail_no_such_user():
    storage = create_autospec(IDMappingStorage, spec_set=True, instance=True)
    handlers = create_autospec(UserLookupSet, spec_set=True, instance=True)

    idm = IDMapper(handlers, set([AuthsourceID('asone')]), storage)

    handlers.get_user.return_value = (User(AuthsourceID('asone'), Username('bar')), True)
    handlers.is_valid_user.return_value = False

    fail_add_user_to_namespace(idm, AuthsourceID('asone'), Token('t'), NamespaceID('n'),
                               User(AuthsourceID('asone'), Username('u')),
                               NoSuchUserError('asone/u'))
示例#4
0
 def set_local_user_as_admin(self, username: Username, admin: bool) -> None:
     not_none(username, 'username')
     admin = True if admin else False  # more readable than admin and True
     try:
         res = self._db[_COL_USERS].update_one(
             {_FLD_USER: username.name}, {'$set': {
                 _FLD_ADMIN: admin
             }})
         if res.matched_count != 1:  # don't care if user was updated or not, just found
             raise NoSuchUserError(username.name)
     except PyMongoError as e:
         raise IDMappingStorageError('Connection to database failed: ' +
                                     str(e)) from e
示例#5
0
def test_user_fail_new_token():
    builder = create_autospec(IDMappingBuilder, spec_set=True, instance=True)
    luh = create_autospec(LocalUserLookup, spec_set=True, instance=True)
    out = Mock()
    err = Mock()

    builder.build_local_user_lookup.return_value = luh
    luh.new_token.side_effect = NoSuchUserError('foo')

    assert IDMappingCLI(builder, ['--user', 'foo', '--new-token'], out,
                        err).execute() == 1

    assert out.write.call_args_list == []
    assert err.write.call_args_list == [
        (('Error: 50000 No such user: foo\n', ), {})
    ]
示例#6
0
 def update_local_user_token(self, username: Username,
                             token: HashedToken) -> None:
     not_none(username, 'username')
     not_none(token, 'token')
     try:
         res = self._db[_COL_USERS].update_one(
             {_FLD_USER: username.name},
             {'$set': {
                 _FLD_TOKEN: token.token_hash
             }})
         if res.matched_count != 1:  # don't care if user was updated or not, just found
             raise NoSuchUserError(username.name)
     except DuplicateKeyError as e:
         # since only the token can cause a duplicate key error here, we assume something
         # crazy isn't going and just raise that exception
         raise ValueError(
             'The provided token already exists in the database')
     except PyMongoError as e:
         raise IDMappingStorageError('Connection to database failed: ' +
                                     str(e)) from e
def test_set_local_user_as_admin_fail_no_such_user(idstorage):
    idstorage.create_local_user(Username('bar'), HashedToken('whoo'))
    fail_set_local_user_as_admin(idstorage, Username('foo'),
                                 NoSuchUserError('foo'))
def test_update_user_token_fail_no_such_user(idstorage):
    idstorage.create_local_user(Username('u'), HashedToken('t'))
    fail_update_user_token(idstorage, Username('u1'), HashedToken('t1'),
                           NoSuchUserError('u1'))