github.com/crowdsecurity/crowdsec@v1.6.1/docker/test/tests/test_capi.py (about) 1 #!/usr/bin/env python 2 3 from http import HTTPStatus 4 5 import pytest 6 pytestmark = pytest.mark.docker 7 8 9 def test_no_capi(crowdsec, flavor): 10 """Test no CAPI (disabled by default in tests)""" 11 12 env = { 13 'DISABLE_ONLINE_API': 'true', 14 } 15 16 with crowdsec(flavor=flavor, environment=env) as cs: 17 cs.wait_for_log("*Starting processing data*") 18 cs.wait_for_http(8080, '/health', want_status=HTTPStatus.OK) 19 res = cs.cont.exec_run('cscli capi status') 20 assert res.exit_code == 1 21 assert "You can successfully interact with Central API (CAPI)" not in res.output.decode() 22 23 logs = cs.log_lines() 24 assert not any("Successfully registered to Central API (CAPI)" in line for line in logs) 25 assert not any("Registration to online API done" in line for line in logs) 26 27 28 def test_capi(crowdsec, flavor): 29 """Test CAPI""" 30 31 env = { 32 'DISABLE_ONLINE_API': 'false', 33 } 34 35 with crowdsec(flavor=flavor, environment=env) as cs: 36 cs.wait_for_log("*Starting processing data*") 37 cs.wait_for_http(8080, '/health', want_status=HTTPStatus.OK) 38 res = cs.cont.exec_run('cscli capi status') 39 assert res.exit_code == 0 40 assert "You can successfully interact with Central API (CAPI)" in res.output.decode() 41 42 cs.wait_for_log([ 43 "*Successfully registered to Central API (CAPI)*", 44 "*Registration to online API done*", 45 ])