예제 #1
0
def http_auth_handler(req, response):
    # Allow the test to specify the username and password
    params = dict(urlparse.parse_qsl(req.url_parts.query))
    username = params.get("username", "guest")
    password = params.get("password", "guest")

    auth = request.Authentication(req.headers)
    content = """<!doctype html>
<title>HTTP Authentication</title>
<p id="status">{}</p>"""

    if auth.username == username and auth.password == password:
        response.status = 200
        response.content = content.format("success")

    else:
        response.status = 401
        response.headers.set("WWW-Authenticate", "Basic realm=\"secret\"")
        response.content = content.format("restricted")
예제 #2
0
def basic_auth_handler(req, response):
    # Allow the test to specify the username and password

    username = b"mozilla"
    password = b"mozilla"

    auth = request.Authentication(req.headers)
    content = """<!doctype html>
        <title>HTTP Authentication</title>
        <p id="status">{}</p>"""

    if auth.username == username and auth.password == password:
        response.status = 200
        response.content = content.format("success")

    else:
        response.status = 401
        response.headers.set("WWW-Authenticate", "Basic realm=\"secret\"")
        response.content = content.format("restricted")