예제 #1
0
파일: http.py 프로젝트: miscs/vdirsyncer
def _verify_fingerprint_works():
    try:
        from pkg_resources import parse_version as ver

        return ver(requests.__version__) >= ver('2.4.1')
    except Exception:
        return False
예제 #2
0
def _fingerprints_broken():
    from pkg_resources import parse_version as ver
    tolerant_python = (
        utils.compat.PY2 and platform.python_implementation() != 'PyPy'
    )
    broken_urllib3 = ver(requests.__version__) <= ver('2.5.1')
    return broken_urllib3 and not tolerant_python
예제 #3
0
    def setup(self, request, tmpdir):
        if ver(radicale.VERSION) < ver('2.0.0-pre'):
            raise RuntimeError('Testing against Radicale only works with '
                               'Radicale >= 2.0.0')

        def get_app():
            config = radicale.config.load(())
            config.set('storage', 'filesystem_folder', str(tmpdir))
            config.set('rights', 'type', 'owner_only')

            app = radicale.Application(config, logger)

            def is_authenticated(user, password):
                return user == 'bob' and password == 'bob'

            app.is_authenticated = is_authenticated
            return app

        wsgi_intercept.requests_intercept.install()
        wsgi_intercept.add_wsgi_intercept('127.0.0.1', 80, get_app)

        def teardown():
            wsgi_intercept.remove_wsgi_intercept('127.0.0.1', 80)
            wsgi_intercept.requests_intercept.uninstall()

        request.addfinalizer(teardown)
예제 #4
0
    def setup(self, request, tmpdir):
        if ver(radicale.VERSION) < ver('2.0.0-pre'):
            raise RuntimeError('Testing against Radicale only works with '
                               'Radicale >= 2.0.0')

        def get_app():
            config = radicale.config.load(())
            config.set('storage', 'filesystem_folder', str(tmpdir))
            config.set('rights', 'type', 'owner_only')

            app = radicale.Application(config, logger)

            def is_authenticated(user, password):
                return user == 'bob' and password == 'bob'

            app.is_authenticated = is_authenticated
            return app

        wsgi_intercept.requests_intercept.install()
        wsgi_intercept.add_wsgi_intercept('127.0.0.1', 80, get_app)

        def teardown():
            wsgi_intercept.remove_wsgi_intercept('127.0.0.1', 80)
            wsgi_intercept.requests_intercept.uninstall()
        request.addfinalizer(teardown)
예제 #5
0
def test_request_ssl(httpsserver):
    sha1 = '94:FD:7A:CB:50:75:A4:69:82:0A:F8:23:DF:07:FC:69:3E:CD:90:CA'
    md5 = '19:90:F7:23:94:F2:EF:AB:2B:64:2D:57:3D:25:95:2D'

    httpsserver.serve_content('')  # we need to serve something

    with pytest.raises(requests.exceptions.SSLError) as excinfo:
        utils.http.request('GET', httpsserver.url)
    assert 'certificate verify failed' in str(excinfo.value)

    utils.http.request('GET', httpsserver.url, verify=False)

    # https://github.com/shazow/urllib3/issues/529
    from pkg_resources import parse_version as ver
    tolerant_python = (utils.compat.PY2
                       and platform.python_implementation() != 'PyPy')
    broken_urllib3 = ver(requests.__version__) <= ver('2.5.1')
    if broken_urllib3 and not tolerant_python:
        return

    utils.http.request('GET', httpsserver.url, verify_fingerprint=sha1)
    utils.http.request('GET', httpsserver.url, verify_fingerprint=md5)
    with pytest.raises(requests.exceptions.SSLError) as excinfo:
        utils.http.request('GET',
                           httpsserver.url,
                           verify_fingerprint=''.join(reversed(sha1)))
    assert 'Fingerprints did not match' in str(excinfo.value)
예제 #6
0
def test_request_ssl(httpsserver):
    sha1 = '94:FD:7A:CB:50:75:A4:69:82:0A:F8:23:DF:07:FC:69:3E:CD:90:CA'
    md5 = '19:90:F7:23:94:F2:EF:AB:2B:64:2D:57:3D:25:95:2D'

    httpsserver.serve_content('')  # we need to serve something

    with pytest.raises(requests.exceptions.SSLError) as excinfo:
        utils.http.request('GET', httpsserver.url)
    assert 'certificate verify failed' in str(excinfo.value)

    utils.http.request('GET', httpsserver.url, verify=False)

    # https://github.com/shazow/urllib3/issues/529
    from pkg_resources import parse_version as ver
    tolerant_python = (
        utils.compat.PY2 and platform.python_implementation() != 'PyPy'
    )
    broken_urllib3 = ver(requests.__version__) <= ver('2.5.1')
    if broken_urllib3 and not tolerant_python:
        return

    utils.http.request('GET', httpsserver.url,
                       verify_fingerprint=sha1)
    utils.http.request('GET', httpsserver.url, verify_fingerprint=md5)
    with pytest.raises(requests.exceptions.SSLError) as excinfo:
        utils.http.request('GET', httpsserver.url,
                           verify_fingerprint=''.join(reversed(sha1)))
    assert 'Fingerprints did not match' in str(excinfo.value)
예제 #7
0
def _fingerprints_broken():
    from pkg_resources import parse_version as ver
    broken_urllib3 = ver(requests.__version__) <= ver('2.5.1')
    return broken_urllib3
예제 #8
0
def _fingerprints_broken():
    from pkg_resources import parse_version as ver
    broken_urllib3 = ver(requests.__version__) <= ver('2.5.1')
    return broken_urllib3