test_exceptions.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:sanic 作者: channelcat 项目源码 文件源码
def test_unauthorized_exception(exception_app):
    """Test the built-in Unauthorized exception"""
    request, response = exception_app.test_client.get('/401')
    assert response.status == 401

    request, response = exception_app.test_client.get('/401/basic')
    assert response.status == 401
    assert response.headers.get('WWW-Authenticate') is not None
    assert response.headers.get('WWW-Authenticate') == "Basic realm='Sanic'"

    request, response = exception_app.test_client.get('/401/digest')
    assert response.status == 401

    auth_header = response.headers.get('WWW-Authenticate')
    assert auth_header is not None
    assert auth_header.startswith('Digest')
    assert "qop='auth, auth-int'" in auth_header
    assert "algorithm='MD5'" in auth_header
    assert "nonce='abcdef'" in auth_header
    assert "opaque='zyxwvu'" in auth_header

    request, response = exception_app.test_client.get('/401/bearer')
    assert response.status == 401
    assert response.headers.get('WWW-Authenticate') == "Bearer"
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号