From 5eecf0957a8025774353c240815a165a53c552c2 Mon Sep 17 00:00:00 2001 From: jagnd1 Date: Wed, 18 Feb 2026 10:01:56 +0530 Subject: [PATCH] added integration testing --- .../integration_tests/test_config_driven.py | 37 ++++++++++ testing/integration_tests/test_scenarios.json | 71 +++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 testing/integration_tests/test_config_driven.py create mode 100644 testing/integration_tests/test_scenarios.json diff --git a/testing/integration_tests/test_config_driven.py b/testing/integration_tests/test_config_driven.py new file mode 100644 index 0000000..436be17 --- /dev/null +++ b/testing/integration_tests/test_config_driven.py @@ -0,0 +1,37 @@ +import json +import pytest +import httpx +import os + +# Config-driven test runner +def load_test_scenarios(): + config_path = os.path.join(os.path.dirname(__file__), "test_scenarios.json") + with open(config_path, "r") as f: + return json.load(f) + +scenarios = load_test_scenarios() + +@pytest.mark.asyncio +@pytest.mark.parametrize("scenario", scenarios, ids=lambda s: s["name"]) +async def test_api_integration(scenario): + base_url = "http://localhost:8001" # Target crypto_service + url = f"{base_url}{scenario['endpoint']}" + method = scenario.get("method", "POST") + payload = scenario.get("payload", {}) + expected = scenario.get("expected", {}) + expected_status = scenario.get("expected_status", 200) + + async with httpx.AsyncClient(timeout=10.0) as client: + if method == "POST": + resp = await client.post(url, json=payload, params={"hsm_name": "GP"}) + elif method == "GET": + resp = await client.get(url, params={"hsm_name": "GP"}) + + # Verify status code + assert resp.status_code == expected_status, f"Failed: {scenario['name']} - Content: {resp.text}" + + # Verify response body if expected data is provided + if expected and resp.status_code == 200: + resp_data = resp.json() + for key, value in expected.items(): + assert resp_data.get(key) == value, f"Mismatch in {key}: expected {value}, got {resp_data.get(key)}" diff --git a/testing/integration_tests/test_scenarios.json b/testing/integration_tests/test_scenarios.json new file mode 100644 index 0000000..331c30f --- /dev/null +++ b/testing/integration_tests/test_scenarios.json @@ -0,0 +1,71 @@ +[ + { + "name": "AES128 CBC Encryption Success", + "endpoint": "/v1/crypto/data_encr", + "method": "POST", + "payload": { + "key_lmk": "RDAxMTJEMEFCMDBFMDAwMEQ0MkRFOEU5MjU4RjkyOTBDMTJDQUQwQjZEM0JCMDk0MjBDRkFBMTMwNTY3REExODUzMEU0MTM2MTJFQzA5MUYyM0JFMjg0RTNDQkYxOTFBNkM0NURERkY5RDJCQUExMg==", + "encr_mode": "CBC", + "iv": "1234567812345678", + "msg": "1234567812345678", + "algo": "A128" + }, + "expected": { + "status": "success" + } + }, + { + "name": "AES128 CBC Decryption Success", + "endpoint": "/v1/crypto/data_decr", + "method": "POST", + "payload": { + "key_lmk": "RDAxMTJEMEFCMDBFMDAwMEQ0MkRFOEU5MjU4RjkyOTBDMTJDQUQwQjZEM0JCMDk0MjBDRkFBMTMwNTY3REExODUzMEU0MTM2MTJFQzA5MUYyM0JFMjg0RTNDQkYxOTFBNkM0NURERkY5RDJCQUExMg==", + "encr_mode": "CBC", + "iv": "1234567812345678", + "encr_msg": "a252f698cfddc8fdef524419b02ff72e", + "algo": "A128" + }, + "expected": { + "status": "success", + "msg": "31323334353637383132333435363738" + } + }, + { + "name": "Encryption Error - Invalid Key", + "endpoint": "/v1/crypto/data_encr", + "method": "POST", + "payload": { + "key_lmk": "INVALID_KEY", + "encr_mode": "CBC", + "iv": "1234567812345678", + "msg": "1234567812345678", + "algo": "A128" + }, + "expected_status": 422 + }, + { + "name": "Encryption Error - Missing IV for CBC", + "endpoint": "/v1/crypto/data_encr", + "method": "POST", + "payload": { + "key_lmk": "RDAxMTJEMEFCMDBFMDAwMEQ0MkRFOEU5MjU4RjkyOTBDMTJDQUQwQjZEM0JCMDk0MjBDRkFBMTMwNTY3REExODUzMEU0MTM2MTJFQzA5MUYyM0JFMjg0RTNDQkYxOTFBNkM0NURERkY5RDJCQUExMg==", + "encr_mode": "CBC", + "msg": "1234567812345678", + "algo": "A128" + }, + "expected_status": 422 + }, + { + "name": "Decryption Error - Wrong Key Length", + "endpoint": "/v1/crypto/data_decr", + "method": "POST", + "payload": { + "key_lmk": "RDAxMTJQ", + "encr_mode": "CBC", + "iv": "1234567812345678", + "encr_msg": "a252f698cfddc8fdef524419b02ff72e", + "algo": "A128" + }, + "expected_status": 422 + } +]