SDK›Python SDK Manual Testing
Python SDK Manual Testing
This guide describes how to verify the connection, request interception, and mock capabilities of the Python SDK.
1Environment Configuration
Follow these steps to prepare your local terminal and CLI daemon before running any SDK tests:
Step A: Configure the Workspace & Mock Secrets
# Reset local CLI config agentsecrets init --force # Create test scope agentsecrets workspace create "Test Workspace" agentsecrets project create "sdk-test-project" agentsecrets environment switch "development" # Set a mock credential value in your OS Keychain agentsecrets secrets set MOCK_SERVICE_KEY="mock_secret_value_12345" # Authorize the target domain agentsecrets workspace allowlist add httpbin.org
Step B: Start the daemon
agentsecrets proxy start
2Manual Test Cases
Test 1: Verify Connection & Status
Verify that the SDK connects to the active daemon session and resolves context.
Create test_status.py:
from agentsecrets import AgentSecrets # Initialize client client = AgentSecrets() # Verify connection to local daemon status = client.proxy.status() print(f"✓ Connected on Port: {status.port}")
python test_status.py # Expected Output: # ✓ Connected on Port: 8765
Test 2: Secure API Calls (client.call())
Verify that credentials are dynamically resolved from your OS Keychain and injected at the transport boundary.
Create test_call.py:
from agentsecrets import AgentSecrets client = AgentSecrets() # Target httpbin to inspect request headers (the proxy will automatically redact # the reflected credential in the response before returning it to the SDK). response = client.call( "https://httpbin.org/headers", method="GET", bearer="MOCK_SERVICE_KEY" ) headers = response.json().get("headers", {}) print(f"✓ Authorization Injected: {headers.get('Authorization')}")
python test_call.py # Expected Output: # ✓ Authorization Injected: Bearer [REDACTED]
Test 3: Transparent Interception (init())
Verify that outgoing calls made by standard libraries (requests and httpx) are intercepted.
Create test_interception.py:
import httpx import requests from agentsecrets import init, credential # Register global interception hooks init() # 1. Verify requests library interception res_req = requests.get( "https://httpbin.org/headers", headers={"Authorization": f"Bearer {credential.MOCK_SERVICE_KEY}"} ) auth_req = res_req.json().get("headers", {}).get("Authorization") print(f"✓ Intercepted requests: {auth_req}") # 2. Verify httpx library interception with httpx.Client() as client: res_httpx = client.get( "https://httpbin.org/headers", headers={"Authorization": f"Bearer {credential.MOCK_SERVICE_KEY}"} ) auth_httpx = res_httpx.json().get("headers", {}).get("Authorization") print(f"✓ Intercepted httpx: {auth_httpx}")
python test_interception.py # Expected Output: # ✓ Intercepted requests: Bearer [REDACTED] # ✓ Intercepted httpx: Bearer [REDACTED]
3Clean Up
Shut down the daemon and reset the configuration:
agentsecrets proxy stop agentsecrets init --force
Was this helpful?
Thanks for your feedback!
Your feedback helps us improve the platform.