예제 #1
0
def test_build_ocsp_request_failure():
    """test an unsuccessful build_ocsp_request function invocation"""

    cert_chain = ["blah", "blah"]

    func_name: str = "build_ocsp_request"

    with pytest.raises(Exception) as excinfo:
        build_ocsp_request(cert_chain)

    assert str(
        excinfo.value) == f"{func_name}: Unable to load x509 certificate."
예제 #2
0
def test_build_ocsp_request_success():
    """test a successful build_ocsp_request function invocation"""

    host = "github.com"
    port = 443
    cert_chain = get_certificate_chain(host, port)
    ocsp_request_data = build_ocsp_request(cert_chain)

    assert ocsp_request_data == certs.github_ocsp_data
예제 #3
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"
예제 #4
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