Exemple #1
0
def test_get_ocsp_response_timeout():
    """test an unsuccessful get_ocsp_response function invocation
    with a bad url input"""

    func_name: str = "get_ocsp_response"

    ocsp_url = "http://blah.com:65534"
    ocsp_request_data = b"dummydata"

    with pytest.raises(Exception) as excinfo:
        get_ocsp_response(ocsp_url, ocsp_request_data)

    assert str(excinfo.value) == f"{func_name}: Request timeout for {ocsp_url}"
Exemple #2
0
def test_get_ocsp_response_connection_error():
    """test an unsuccessful get_ocsp_response function invocation
    with a bad url input"""

    func_name: str = "get_ocsp_response"

    ocsp_url = "http://blahhhhhhhh.com"
    ocsp_request_data = b"dummydata"

    with pytest.raises(Exception) as excinfo:
        get_ocsp_response(ocsp_url, ocsp_request_data)

    assert str(excinfo.value
               ) == f"{func_name}: Unknown Connection Error to {ocsp_url}"
Exemple #3
0
def test_get_ocsp_response_bad_url_format():
    """test an unsuccessful get_ocsp_response function invocation
    with a bad url format"""

    func_name: str = "get_ocsp_response"

    ocsp_url = "badurl"
    ocsp_request_data = b"dummydata"

    with pytest.raises(Exception) as excinfo:
        get_ocsp_response(ocsp_url, ocsp_request_data)

    assert str(
        excinfo.value) == f"{func_name}: URL failed validation for {ocsp_url}"
Exemple #4
0
def test_extract_ocsp_result_success():
    """test an unsuccessful extract_ocsp_result function invocation"""

    cert_chain = get_certificate_chain("github.com", 443)
    ocsp_url = extract_ocsp_url(cert_chain)
    ocsp_request = build_ocsp_request(cert_chain)
    ocsp_response = get_ocsp_response(ocsp_url, ocsp_request)

    ocsp_result = extract_ocsp_result(ocsp_response)

    assert ocsp_result == "OCSP Status: GOOD"
Exemple #5
0
def test_extract_ocsp_result_unauthorized():
    """test an unsuccessful extract_ocsp_result function invocation"""

    func_name: str = "extract_ocsp_result"

    ocsp_response = get_ocsp_response("http://ocsp.digicert.com",
                                      certs.unauthorized_ocsp_data)

    with pytest.raises(Exception) as excinfo:
        extract_ocsp_result(ocsp_response)

    assert str(
        excinfo.value) == f"{func_name}: OCSP Request Error: UNAUTHORIZED"
Exemple #6
0
def test_get_ocsp_response_success():
    """test an successful get_ocsp_response function invocation"""

    cert_chain = get_certificate_chain("github.com", 443)
    ocsp_url = extract_ocsp_url(cert_chain)
    ocsp_request = build_ocsp_request(cert_chain)

    ocsp_response = get_ocsp_response(ocsp_url, ocsp_request)

    for header in ocsp_response.headers:
        if "application/ocsp-response" in ocsp_response.headers[header]:
            # There may be a better way to do this, but this proves we got a response
            # from the OCSP server
            assert True