コード例 #1
0
def test_digest_next_nonce_nc():
    # Test that if the server sets nextnonce that we reset
    # the nonce count back to 1
    http = httplib2.Http()
    password = tests.gen_password()
    grenew_nonce = [None]
    handler = tests.http_reflect_with_auth(
        allow_scheme='digest',
        allow_credentials=(('joe', password), ),
        out_renew_nonce=grenew_nonce,
    )
    with tests.server_request(handler, request_count=5) as uri:
        http.add_credentials('joe', password)
        response1, _ = http.request(uri, 'GET')
        info = httplib2._parse_www_authenticate(response1,
                                                'authentication-info')
        assert response1.status == 200
        assert info.get('digest', {}).get('nc') == '00000001', info
        assert not info.get('digest', {}).get('nextnonce'), info
        response2, _ = http.request(uri, 'GET')
        info2 = httplib2._parse_www_authenticate(response2,
                                                 'authentication-info')
        assert info2.get('digest', {}).get('nc') == '00000002', info2
        grenew_nonce[0]()
        response3, content = http.request(uri, 'GET')
        info3 = httplib2._parse_www_authenticate(response3,
                                                 'authentication-info')
        assert response3.status == 200
        assert info3.get('digest', {}).get('nc') == '00000001', info3
コード例 #2
0
ファイル: test_auth.py プロジェクト: httplib2/httplib2
def test_digest_next_nonce_nc():
    # Test that if the server sets nextnonce that we reset
    # the nonce count back to 1
    http = httplib2.Http()
    password = tests.gen_password()
    grenew_nonce = [None]
    handler = tests.http_reflect_with_auth(
        allow_scheme="digest",
        allow_credentials=(("joe", password),),
        out_renew_nonce=grenew_nonce,
    )
    with tests.server_request(handler, request_count=5) as uri:
        http.add_credentials("joe", password)
        response1, _ = http.request(uri, "GET")
        info = httplib2._parse_www_authenticate(response1, "authentication-info")
        assert response1.status == 200
        assert info.get("digest", {}).get("nc") == "00000001", info
        assert not info.get("digest", {}).get("nextnonce"), info
        response2, _ = http.request(uri, "GET")
        info2 = httplib2._parse_www_authenticate(response2, "authentication-info")
        assert info2.get("digest", {}).get("nc") == "00000002", info2
        grenew_nonce[0]()
        response3, content = http.request(uri, "GET")
        info3 = httplib2._parse_www_authenticate(response3, "authentication-info")
        assert response3.status == 200
        assert info3.get("digest", {}).get("nc") == "00000001", info3
コード例 #3
0
def test_parse_www_authenticate_malformed():
    # TODO: test (and fix) header value 'barbqwnbm-bb...:asd' leads to dead loop
    with tests.assert_raises(httplib2.MalformedHeader):
        httplib2._parse_www_authenticate({
            'www-authenticate':
            'OAuth "Facebook Platform" "invalid_token" "Invalid OAuth access token."'
        })
コード例 #4
0
def test_digest_auth_stale():
    # Test that we can handle a nonce becoming stale
    http = httplib2.Http()
    password = tests.gen_password()
    grenew_nonce = [None]
    requests = []
    handler = tests.http_reflect_with_auth(
        allow_scheme='digest',
        allow_credentials=(('joe', password), ),
        out_renew_nonce=grenew_nonce,
        out_requests=requests,
    )
    with tests.server_request(handler, request_count=4) as uri:
        http.add_credentials('joe', password)
        response, _ = http.request(uri, 'GET')
        assert response.status == 200
        info = httplib2._parse_www_authenticate(requests[0][1].headers,
                                                'www-authenticate')
        grenew_nonce[0]()
        response, _ = http.request(uri, 'GET')
        assert response.status == 200
        assert not response.fromcache
        assert getattr(response, '_stale_digest', False)
        info2 = httplib2._parse_www_authenticate(requests[2][1].headers,
                                                 'www-authenticate')
        nonce1 = info.get('digest', {}).get('nonce', '')
        nonce2 = info2.get('digest', {}).get('nonce', '')
        assert nonce1 != ''
        assert nonce2 != ''
        assert nonce1 != nonce2, (nonce1, nonce2)
コード例 #5
0
ファイル: test_auth.py プロジェクト: httplib2/httplib2
def test_digest_auth_stale():
    # Test that we can handle a nonce becoming stale
    http = httplib2.Http()
    password = tests.gen_password()
    grenew_nonce = [None]
    requests = []
    handler = tests.http_reflect_with_auth(
        allow_scheme="digest",
        allow_credentials=(("joe", password),),
        out_renew_nonce=grenew_nonce,
        out_requests=requests,
    )
    with tests.server_request(handler, request_count=4) as uri:
        http.add_credentials("joe", password)
        response, _ = http.request(uri, "GET")
        assert response.status == 200
        info = httplib2._parse_www_authenticate(
            requests[0][1].headers, "www-authenticate"
        )
        grenew_nonce[0]()
        response, _ = http.request(uri, "GET")
        assert response.status == 200
        assert not response.fromcache
        assert getattr(response, "_stale_digest", False)
        info2 = httplib2._parse_www_authenticate(
            requests[2][1].headers, "www-authenticate"
        )
        nonce1 = info.get("digest", {}).get("nonce", "")
        nonce2 = info2.get("digest", {}).get("nonce", "")
        assert nonce1 != ""
        assert nonce2 != ""
        assert nonce1 != nonce2, (nonce1, nonce2)
コード例 #6
0
def test_digest_next_nonce_nc():
    # Test that if the server sets nextnonce that we reset
    # the nonce count back to 1
    http = httplib2.Http()
    password = tests.gen_password()
    grenew_nonce = [None]
    handler = tests.http_reflect_with_auth(
        allow_scheme="digest",
        allow_credentials=(("joe", password), ),
        out_renew_nonce=grenew_nonce,
    )
    with tests.server_request(handler, request_count=5) as uri:
        http.add_credentials("joe", password)
        response1, _ = http.request(uri, "GET")
        info = httplib2._parse_www_authenticate(response1,
                                                "authentication-info")
        assert response1.status == 200
        assert info.get("digest", {}).get("nc") == "00000001", info
        assert not info.get("digest", {}).get("nextnonce"), info
        response2, _ = http.request(uri, "GET")
        info2 = httplib2._parse_www_authenticate(response2,
                                                 "authentication-info")
        assert info2.get("digest", {}).get("nc") == "00000002", info2
        grenew_nonce[0]()
        response3, content = http.request(uri, "GET")
        info3 = httplib2._parse_www_authenticate(response3,
                                                 "authentication-info")
        assert response3.status == 200
        assert info3.get("digest", {}).get("nc") == "00000001", info3
コード例 #7
0
ファイル: test_auth.py プロジェクト: httplib2/httplib2
def test_parse_www_authenticate_malformed():
    # TODO: test (and fix) header value 'barbqwnbm-bb...:asd' leads to dead loop
    with tests.assert_raises(httplib2.MalformedHeader):
        httplib2._parse_www_authenticate(
            {
                "www-authenticate": 'OAuth "Facebook Platform" "invalid_token" "Invalid OAuth access token."'
            }
        )
コード例 #8
0
def test_parse_www_authenticate_correct(data, strict):
    headers, info = data
    # FIXME: move strict to parse argument
    httplib2.USE_WWW_AUTH_STRICT_PARSING = strict
    try:
        assert httplib2._parse_www_authenticate(headers) == info
    finally:
        httplib2.USE_WWW_AUTH_STRICT_PARSING = 0
コード例 #9
0
ファイル: test_auth.py プロジェクト: httplib2/httplib2
def test_parse_www_authenticate_correct(data, strict):
    headers, info = data
    # FIXME: move strict to parse argument
    httplib2.USE_WWW_AUTH_STRICT_PARSING = strict
    try:
        assert httplib2._parse_www_authenticate(headers) == info
    finally:
        httplib2.USE_WWW_AUTH_STRICT_PARSING = 0
コード例 #10
0
ファイル: cclib.py プロジェクト: cloudControl/pycclib
    def create_ssh_token(self):
        try:
            token_request = _Request(url=self.ssh_token_source_url)
            token_request.request('', 'POST')
            raise APIException('Expected UnauthorizedError has not been raised')

        except UnauthorizedError as e:
            result = httplib2._parse_www_authenticate(e.response)

            try:
                ssh_token = result['ccssh']['sshtoken']
            except KeyError, TypeError:
                raise APIException('SSH token was not created')

            if not ssh_token:
                raise APIException('Empty SSH token.')

            return ssh_token