def test_bad_fails(request_with):
    # once to get a WWW-Authenticate header
    auther = inbound_responder(_auth_func("username", "password"), realm="*****@*****.**")
    response = raises(Response, request_with, '', auther).value
    # do something with the header
    auth_headers = _auth_headers(response)
    http_authorization = _digest_auth_for(auth_headers, "username", "badpassword")
    response = raises(Response, request_with, http_authorization, auther).value
    assert response.code == 401
    assert not response.request.auth.authorized()
def test_bad_fails():
    request = StubRequest()
    # once to get a WWW-Authenticate header
    hook = inbound_responder(_auth_func("username", "password"), realm="*****@*****.**")
    response = assert_raises(Response, hook, request)
    # do something with the header
    auth_headers = _auth_headers(response)
    request.headers['Authorization'] = _digest_auth_for(auth_headers, "username", "badpassword")
    response = assert_raises(Response, hook, request)
    assert response.code == 401, response
    assert not request.auth.authorized()
def test_good_works(request_with):
    # once to get a WWW-Authenticate header
    auth_func = _auth_func("username", "password")
    auther = inbound_responder(auth_func, realm="*****@*****.**")
    response = raises(Response, request_with, '', auther).value
    # do something with the header
    auth_headers = _auth_headers(response)
    http_authorization = _digest_auth_for(auth_headers, "username", "password")
    request = request_with(http_authorization, auther)
    assert request.auth.authorized()
    assert request.auth.username() == "username"
def test_bad_fails():
    request = StubRequest()
    # once to get a WWW-Authenticate header
    hook = inbound_responder(_auth_func("username", "password"), realm="*****@*****.**")
    response = raises(Response, hook, request).value
    # do something with the header
    auth_headers = _auth_headers(response)
    request.headers['Authorization'] = _digest_auth_for(auth_headers, "username", "badpassword")
    response = raises(Response, hook, request).value
    assert response.code == 401, response
    assert not request.auth.authorized()
def test_good_works():
    request = StubRequest()
    # once to get a WWW-Authenticate header
    hook = inbound_responder(_auth_func("username", "password"), realm="*****@*****.**")
    response = assert_raises(Response, hook, request)
    # do something with the header
    auth_headers = _auth_headers(response)
    request.headers['Authorization'] = _digest_auth_for(auth_headers, "username", "password")
    #print repr(request.headers['Authorization'])
    response = hook(request)
    success = request.auth.authorized()
    assert success
    assert request.auth.username() == "username", request.auth.username()
def test_good_works():
    request = StubRequest()
    # once to get a WWW-Authenticate header
    hook = inbound_responder(_auth_func("username", "password"), realm="*****@*****.**")
    response = raises(Response, hook, request).value
    # do something with the header
    auth_headers = _auth_headers(response)
    request.headers['Authorization'] = _digest_auth_for(auth_headers, "username", "password")
    #print repr(request.headers['Authorization'])
    response = hook(request)
    success = request.auth.authorized()
    assert success
    assert request.auth.username() == "username", request.auth.username()
def _request_with(authfunc, auth_header):
    request = StubRequest()
    if auth_header is not None:
        request.headers['Authorization'] = auth_header
    hook = inbound_responder(authfunc)
    return hook(request)
def test_wrong_auth(request_with):
    auth = lambda u, p: u == "username" and p == "password"
    auther = inbound_responder(auth, realm="*****@*****.**")
    response = raises(Response, request_with, "Wacky xxx", auther).value
    assert response.code == 400, response
Example #9
0
def _request_with(authfunc, auth_header):
    request = StubRequest()
    if auth_header is not None:
        request.headers['Authorization'] = auth_header
    hook = inbound_responder(authfunc)
    return hook(request)