test_n8n_client_config.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. from pathlib import Path
  2. import pytest
  3. from app.core.data_factory.n8n_client import N8nClient, N8nClientError
  4. ROOT = Path(__file__).resolve().parents[1]
  5. def test_n8n_client_contains_no_committed_production_credentials():
  6. source = (ROOT / "app/core/data_factory/n8n_client.py").read_text(encoding="utf-8")
  7. config_source = (ROOT / "app/config/config.py").read_text(encoding="utf-8")
  8. combined = source + config_source
  9. assert "n8n.citupro.com" not in combined
  10. assert "DEFAULT_N8N_API_KEY" not in combined
  11. assert "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9" not in combined
  12. @pytest.mark.parametrize(
  13. ("api_url", "api_key", "message"),
  14. [
  15. ("", "local-key", "N8N_API_URL"),
  16. ("http://n8n:5678", "", "N8N_API_KEY"),
  17. ("https://n8n.example.com", "local-key", "N8N_API_URL"),
  18. ("http://n8n:5678", "replace-n8n-api-key", "N8N_API_KEY"),
  19. ],
  20. )
  21. def test_n8n_client_fails_closed_when_configuration_is_missing(
  22. api_url, api_key, message
  23. ):
  24. client = N8nClient(api_url=api_url, api_key=api_key, timeout=30)
  25. with pytest.raises(N8nClientError, match=message):
  26. client._get_headers()