github.com/crowdsecurity/crowdsec@v1.6.1/docker/test/tests/test_hub_postoverflows.py (about) 1 #!/usr/bin/env python 2 3 """ 4 Test postoverflow management 5 """ 6 7 from http import HTTPStatus 8 import json 9 import pytest 10 11 pytestmark = pytest.mark.docker 12 13 14 def test_install_two_postoverflows(crowdsec, flavor): 15 """Test installing postoverflows at startup""" 16 it1 = 'crowdsecurity/cdn-whitelist' 17 it2 = 'crowdsecurity/ipv6_to_range' 18 env = { 19 'POSTOVERFLOWS': f'{it1} {it2}' 20 } 21 with crowdsec(flavor=flavor, environment=env) as cs: 22 cs.wait_for_log([ 23 f'*postoverflows install "{it1}"*', 24 f'*postoverflows install "{it2}"*', 25 "*Starting processing data*" 26 ]) 27 cs.wait_for_http(8080, '/health', want_status=HTTPStatus.OK) 28 res = cs.cont.exec_run('cscli postoverflows list -o json') 29 assert res.exit_code == 0 30 j = json.loads(res.output) 31 items = {c['name']: c for c in j['postoverflows']} 32 assert items[it1]['status'] == 'enabled' 33 assert items[it2]['status'] == 'enabled' 34 35 36 def test_disable_postoverflow(): 37 """Test removing a pre-installed postoverflow at startup""" 38 pytest.skip("we don't preinstall postoverflows") 39 40 41 def test_install_and_disable_postoverflow(crowdsec, flavor): 42 """Declare a postoverflow to install AND disable: disable wins""" 43 it = 'crowdsecurity/cdn-whitelist' 44 env = { 45 'POSTOVERFLOWS': it, 46 'DISABLE_POSTOVERFLOWS': it, 47 } 48 with crowdsec(flavor=flavor, environment=env) as cs: 49 cs.wait_for_log("*Starting processing data*") 50 cs.wait_for_http(8080, '/health', want_status=HTTPStatus.OK) 51 res = cs.cont.exec_run('cscli postoverflows list -o json') 52 assert res.exit_code == 0 53 j = json.loads(res.output) 54 items = {c['name'] for c in j['postoverflows']} 55 assert it not in items 56 logs = cs.log_lines() 57 # check that there was no attempt to install 58 assert not any(f'postoverflows install "{it}"' in line for line in logs)