Skip to content

Commit

Permalink
chore(helm chart test): tests can be run in environment with self-sig…
Browse files Browse the repository at this point in the history
…ned certificate (#1997)

- introduces a VERIFY_CERTIFICATE environment variable
  • Loading branch information
iainsproat authored Jan 26, 2024
1 parent c16c5be commit c979c97
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
2 changes: 1 addition & 1 deletion utils/test-deployment/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
specklepy==2.9.0
specklepy==2.17.17
requests==2.31.0
44 changes: 27 additions & 17 deletions utils/test-deployment/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@
SPECKLE_SERVER = os.getenv("SPECKLE_SERVER", "")
if not SPECKLE_SERVER:
print(
"Error: No Speckle server specified. Use SPECKLE_SERVER environment variable or pass it as the first command-line argument"
"Error: No Speckle server specified. Use SPECKLE_SERVER environment variable or pass it as the first command-line argument"
)
exit(1)

VERIFY_CERTIFICATE = (
True if os.getenv("VERIFY_CERTIFICATE", "1") != "0" else False
) # default to True except in very narrow case where value is explicitly "0"

FRONTEND_VERSION = os.getenv("FRONTEND_VERSION", "")
if not FRONTEND_VERSION:
print(
"Error: No frontend version specified. Use FRONTEND_VERSION environment variable."
"Error: No frontend version specified. Use FRONTEND_VERSION environment variable."
)
exit(1)

Expand All @@ -35,31 +39,37 @@
):
SPECKLE_SERVER = "http://" + SPECKLE_SERVER

print(f"Using Speckle server '{SPECKLE_SERVER}'")
print(f"ℹ️ Using Speckle server '{SPECKLE_SERVER}'")

# Test if frontend is accessible
if FRONTEND_VERSION == "1":
frontend_response = requests.get(urllib.parse.urljoin(SPECKLE_SERVER, "logo.svg"))
frontend_response = requests.get(
urllib.parse.urljoin(SPECKLE_SERVER, "logo.svg"), verify=VERIFY_CERTIFICATE
)
# don't check for status code, the frontend app will server the 404 page with a status code 200
# even if the rote doesn't exist
assert frontend_response.headers.get("Content-Type", "").startswith(
"image/"
), "Frontend logo Content-Type is not an image"
), "Frontend logo Content-Type is not an image"
elif FRONTEND_VERSION == "2":
frontend_response = requests.get(SPECKLE_SERVER)
frontend_response = requests.get(SPECKLE_SERVER, verify=VERIFY_CERTIFICATE)
assert (
frontend_response.status_code == 200
), "Frontend did not return a 200 status code"
), f"❌ Frontend did not return a 200 status code, instead returned status code is {frontend_response.status_code}."
else:
print(f"Unknown frontend version '{FRONTEND_VERSION}'")
print(f"Unknown frontend version '{FRONTEND_VERSION}'")
exit(1)
print("Frontend accessible")
print("Frontend accessible")

# Test basic unauthenticated operation using specklepy
client = SpeckleClient(SPECKLE_SERVER, use_ssl=SPECKLE_SERVER.startswith("https://"))
client = SpeckleClient(
SPECKLE_SERVER,
use_ssl=SPECKLE_SERVER.startswith("https://"),
verify_certificate=VERIFY_CERTIFICATE,
)
server_info = client.server.get()
assert isinstance(server_info, ServerInfo), "GraphQL ServerInfo query error"
print(f"GraphQL operation succeeded. Server name: {server_info.name}")
assert isinstance(server_info, ServerInfo), "GraphQL ServerInfo query error"
print(f"GraphQL operation succeeded. Server name: {server_info.name}")

# Test that the deployed server version matches the expected version
SERVER_VERSION = ""
Expand All @@ -71,13 +81,13 @@
if not SERVER_VERSION == "latest":
assert server_info.version.startswith(
SERVER_VERSION
), f"The deployed version {server_info.version} should match, or be prefixed by, the expected {SERVER_VERSION}"
print(f"Server version {SERVER_VERSION} is deployed and available")
), f"The deployed version {server_info.version} should match, or be prefixed by, the expected {SERVER_VERSION}"
print(f"Server version {SERVER_VERSION} is deployed and available")
else:
print("Not testing server version, as it was set to 'latest'")
print("🟡 Not testing server version, as it was set to 'latest'")
else:
print(
"Not testing server version, as an expected value was not provided via environment variables or command-line argument"
"🟡 Not testing server version, as an expected value was not provided via environment variables or command-line argument"
)

print("Deployment tests PASS")
print("Deployment tests PASS")

0 comments on commit c979c97

Please sign in to comment.