github.com/crowdsecurity/crowdsec@v1.6.1/docker/test/tests/test_capi_whitelists.py (about) 1 #!/usr/bin/env python 2 3 from http import HTTPStatus 4 import yaml 5 6 import pytest 7 8 pytestmark = pytest.mark.docker 9 10 11 def test_capi_whitelists(crowdsec, tmp_path_factory, flavor,): 12 """Test CAPI_WHITELISTS_PATH""" 13 env = { 14 "CAPI_WHITELISTS_PATH": "/path/to/whitelists.yaml" 15 } 16 17 whitelists = tmp_path_factory.mktemp("whitelists") 18 with open(whitelists / "whitelists.yaml", "w") as f: 19 yaml.dump({"ips": ["1.2.3.4", "2.3.4.5"], "cidrs": ["1.2.3.0/24"]}, f) 20 21 volumes = { 22 whitelists / "whitelists.yaml": {"bind": "/path/to/whitelists.yaml", "mode": "ro"} 23 } 24 25 with crowdsec(flavor=flavor, environment=env, volumes=volumes) as cs: 26 cs.wait_for_log("*Starting processing data*") 27 cs.wait_for_http(8080, '/health', want_status=HTTPStatus.OK) 28 res = cs.cont.exec_run('cscli config show-yaml') 29 assert res.exit_code == 0 30 stdout = res.output.decode() 31 y = yaml.safe_load(stdout) 32 assert y['api']['server']['capi_whitelists_path'] == '/path/to/whitelists.yaml'