Files
OSIT-AE-API-FastAPI/tests/integration/test_int_v3_auth_security.py
Scott Idem b2384f2869 Tests: Reorganize test suite into functional subdirectories
- Categorized scripts into tests/unit/, tests/integration/, tests/e2e/, and tests/tools/.
- Adopted consistent naming prefixes (test_unit_*, test_int_*, test_e2e_*, tool_*).
- Renamed conftest_mock.py to mock_config_helper.py for clarity.
- Updated test_int_boot_diagnosis.py with sys.path setup for root-level execution.
2026-01-16 10:46:19 -05:00

51 lines
1.8 KiB
Python

import sys
import os
from fastapi.testclient import TestClient
# Add the project root to sys.path so we can import 'app'
sys.path.append(os.getcwd())
from app.main import app
client = TestClient(app)
def test_site_domain_unauthenticated_search():
"""Test that searching site_domain works without authentication."""
print("Testing unauthenticated site_domain search...")
# Using a simple search query that would typically be used to resolve FQDN
search_payload = {
"and_filters": [
{"field": "fqdn", "op": "eq", "value": "aether.osit.dev"}
]
}
response = client.post("/v3/crud/site_domain/search", json=search_payload)
print(f"Response Status: {response.status_code}")
print(f"Response Body: {response.json()}")
# We expect 200 OK (even if empty results, the point is it's not 403)
assert response.status_code == 200
assert response.json()["status"] == "success"
def test_account_unauthenticated_search_blocked():
"""Test that searching other objects (e.g., account) is blocked without authentication."""
print("\nTesting unauthenticated account search (should be blocked)...")
search_payload = {
"and_filters": []
}
response = client.post("/v3/crud/account/search", json=search_payload)
print(f"Response Status: {response.status_code}")
# We expect 403 Forbidden
assert response.status_code == 403
assert "Authentication required" in response.json()["status_message"]
if __name__ == "__main__":
try:
test_site_domain_unauthenticated_search()
test_account_unauthenticated_search_blocked()
print("\nSUCCESS: V3 Auth Isolation bypass for site_domain is working correctly.")
except Exception as e:
print(f"\nFAILURE: {e}")
sys.exit(1)