예제 #1
0
def test_bad_authentication_when_authenticated_should_invalidate_the_session(keyspace):
    config.set('requirepass', 'secret')
    k = Keyspace()

    assert run_command(k, 'auth', ('secret',))
    try:
        run_command(k, 'auth', ('wrongpass',))
    except DredisError:
        pass

    with pytest.raises(AuthenticationRequiredError) as exc:
        run_command(k, 'incrby', ('counter', '1'))

    assert str(exc.value) == 'NOAUTH Authentication required.'
예제 #2
0
파일: lua.py 프로젝트: Yipit/dredis
 def call(self, cmd, *args):
     try:
         result = run_command(self._keyspace, cmd, args)
     except CommandNotFound:
         raise RedisScriptError(
             '@user_script: Unknown Redis command called from Lua script')
     except DredisError as exc:
         raise RedisScriptError(exc.msg)
     else:
         return self._convert_redis_types_to_lua_types(result)
예제 #3
0
def execute_cmd(keyspace, send_fn, cmd, *args):
    try:
        result = run_command(keyspace, cmd, args)
    except DredisError as exc:
        transmit(send_fn, exc)
    except Exception as exc:
        # no tests cover this part because it's meant for internal errors,
        # such as unexpected bugs in dredis.
        transmit(send_fn, Exception(traceback.format_exc()))
        logger.exception(str(exc))
    else:
        transmit(send_fn, result)
예제 #4
0
def test_raises_error_if_not_authenticated(keyspace):
    config.set('requirepass', 'test')
    with pytest.raises(AuthenticationRequiredError) as exc:
        run_command(Keyspace(), 'get', ('test',))

    assert str(exc.value) == 'NOAUTH Authentication required.'
예제 #5
0
def test_should_raise_error_when_authenticating_when_there_is_no_password(keyspace):
    with pytest.raises(DredisError) as exc:
        run_command(keyspace, 'auth', ('secret',))

    assert str(exc.value) == 'ERR client sent AUTH, but no password is set'
예제 #6
0
def test_allows_commands_when_password_is_valid(keyspace):
    config.set('requirepass', 'secret')
    k = Keyspace()

    assert run_command(k, 'auth', ('secret',))
    assert run_command(k, 'incrby', ('counter', '1')) == 1