Compare commits

...

2 Commits

Author SHA1 Message Date
Kenneth Kehl
31bde31d31 try looking at certificate 2025-06-05 13:03:08 -07:00
Kenneth Kehl
9f6e449b5e whoops, put test back 2025-06-05 10:01:57 -07:00
2 changed files with 149 additions and 1 deletions

View File

@@ -1,13 +1,83 @@
# import datetime
import logging
import os
import socket
import ssl
import requests
from requests.exceptions import RequestException
# from pprint import pprint
logger = logging.getLogger(__name__)
def inspect_certificate():
try:
cert_string = ""
context = ssl.create_default_context()
with socket.create_connection(
("notify-api-staging.apps.internal", "61443"), timeout=10
) as sock:
with context.wrap_socket(
sock, server_hostname="notify-api-staging.apps.internal"
) as ssock:
cert = ssock.getpeercert(binary_form=False)
cert_string.append("Certificate Details:\n")
cert_string.append("-" * 50)
cert_string.append("\nSubject:")
for _, value in cert.get("subject", []):
for k, v in value:
cert_string.append(f" {k}: {v}")
cert_string.append("\nIssuer")
for _, value in cert.get("issuer", []):
for k, v in value:
cert_string.append(f" {k}: {v}")
not_before = cert.get("notBefore")
not_after = cert.get("notAfter")
cert_string.append(f"\nValid From: {not_before}")
cert_string.append(f"\nValid Until: {not_after}")
cert_string.append(
f"\nSerial Number: {cert.get('serialNumber', 'N/A')}"
)
cert_string.append(f"Version: {cert.get('version', 'N/A')}")
cert_string.append("\nExtensions:")
for ext in cert.get("extensions", []):
ext_name = ext.get("oid", "Unknown")
critical = "Critical" if ext.get("critical") else "Non-critical"
value = ext.get("value", "N/A")
cert_string.append(f" {ext_name} ({critical}): {value}")
key_usage = next(
(
ext
for ext in cert.get("extensions", [])
if ext.get("old") == "keyUsage"
),
None,
)
if key_usage:
cert_string.append(f"\nKey Usage (Detailed): {key_usage['value']}")
else:
cert_string.append("\nKey Usage: Not present")
logger.warning(f"CERT STRING {cert_string}")
except ssl.SSLCertVerificationError as e:
logger.error(f"SSL Certification Verification Error: {e}")
logger.error("This may be the cause of the 'key usage extension' error")
except socket.gaierror:
logger.error(
"Error: could not resolve hostname 'notify-api-staging.apps.internal'"
)
except socket.timeout:
logger.error("Connection timed out")
except Exception as e:
logger.error(f"Unexpected exception occurred {e}")
def is_api_down():
inspect_certificate()
api_base_url = os.getenv("API_HOST_NAME")
try:
response = requests.get(api_base_url, timeout=2)

View File

@@ -98,7 +98,85 @@ async def create_new_template(page):
assert "Test message for e2e test" in page.content()
#
# @pytest.mark.asyncio
# async def test_create_new_template(end_to_end_context):
# page = end_to_end_context.new_page()
# page.goto(f"{E2E_TEST_URI}/sign-in")
# # Wait for the next page to fully load.
# page.wait_for_load_state("domcontentloaded")
# check_axe_report(page)
# current_date_time = datetime.datetime.now()
# new_service_name = "E2E Federal Test Service {now} - {browser_type}".format(
# now=current_date_time.strftime("%m/%d/%Y %H:%M:%S"),
# browser_type=page.context.browser.browser_type.name,
# )
# page.goto(f"{E2E_TEST_URI}/accounts")
# # Check to make sure that we've arrived at the next page.
# page.wait_for_load_state("domcontentloaded")
# check_axe_report(page)
# # Check to make sure that we've arrived at the next page.
# # Check the page title exists and matches what we expect.
# expect(page).to_have_title(re.compile("Choose service"))
# # Check for the sign in heading.
# sign_in_heading = page.get_by_role("heading", name="Choose service")
# expect(sign_in_heading).to_be_visible()
# # Retrieve some prominent elements on the page for testing.
# add_service_button = page.get_by_role(
# "button", name=re.compile("Add a new service")
# )
# expect(add_service_button).to_be_visible()
# existing_service_link = page.get_by_role("link", name=new_service_name)
# # Check to see if the service was already created - if so, we should fail.
# # TODO: Figure out how to make this truly isolated, and/or work in a
# # delete service workflow.
# expect(existing_service_link).to_have_count(0)
# # Click on add a new service.
# add_service_button.click()
# # Check to make sure that we've arrived at the next page.
# page.wait_for_load_state("domcontentloaded")
# check_axe_report(page)
# # Check for the sign in heading.
# about_heading = page.get_by_role("heading", name="About your service")
# expect(about_heading).to_be_visible()
# # Retrieve some prominent elements on the page for testing.
# service_name_input = page.locator('xpath=//input[@name="name"]')
# add_service_button = page.get_by_role("button", name=re.compile("Add service"))
# expect(service_name_input).to_be_visible()
# expect(add_service_button).to_be_visible()
# # Fill in the form.
# service_name_input.fill(new_service_name)
# # Click on add service.
# add_service_button.click()
# # Check to make sure that we've arrived at the next page.
# page.wait_for_load_state("domcontentloaded")
# check_axe_report(page)
# # TODO this fails on staging due to duplicate results on 'get_by_text'
# # Check for the service name title and heading.
# # service_heading = page.get_by_text(new_service_name, exact=True)
# # expect(service_heading).to_be_visible()
# expect(page).to_have_title(re.compile(new_service_name))
# create_new_template(page)
# _teardown(page)
def _teardown(page):