github.com/crowdsecurity/crowdsec@v1.6.1/docker/test/tests/test_local_api_url.py (about)

     1  #!/usr/bin/env python
     2  
     3  from http import HTTPStatus
     4  
     5  import pytest
     6  
     7  pytestmark = pytest.mark.docker
     8  
     9  
    10  def test_local_api_url_default(crowdsec, flavor):
    11      """Test LOCAL_API_URL (default)"""
    12      with crowdsec(flavor=flavor) as cs:
    13          cs.wait_for_log([
    14              "*CrowdSec Local API listening on *:8080*",
    15              "*Starting processing data*"
    16          ])
    17          cs.wait_for_http(8080, '/health', want_status=HTTPStatus.OK)
    18          res = cs.cont.exec_run('cscli lapi status')
    19          assert res.exit_code == 0
    20          stdout = res.output.decode()
    21          assert "on http://0.0.0.0:8080/" in stdout
    22          assert "You can successfully interact with Local API (LAPI)" in stdout
    23  
    24  
    25  def test_local_api_url(crowdsec, flavor):
    26      """Test LOCAL_API_URL (custom)"""
    27      env = {
    28          "LOCAL_API_URL": "http://127.0.0.1:8080"
    29      }
    30      with crowdsec(flavor=flavor, environment=env) as cs:
    31          cs.wait_for_log([
    32              "*CrowdSec Local API listening on *:8080*",
    33              "*Starting processing data*"
    34          ])
    35          cs.wait_for_http(8080, '/health', want_status=HTTPStatus.OK)
    36          res = cs.cont.exec_run('cscli lapi status')
    37          assert res.exit_code == 0
    38          stdout = res.output.decode()
    39          assert "on http://127.0.0.1:8080/" in stdout
    40          assert "You can successfully interact with Local API (LAPI)" in stdout
    41  
    42  
    43  def test_local_api_url_ipv6(crowdsec, flavor):
    44      """Test LOCAL_API_URL (custom with ipv6)"""
    45      pytest.skip("ipv6 not supported yet")
    46  
    47      # how to configure docker with ipv6 in a custom network?
    48      # FIXME: https://forums.docker.com/t/assigning-default-ipv6-addresses/128665/3
    49      # FIXME: https://github.com/moby/moby/issues/41438
    50  
    51      env = {
    52          "LOCAL_API_URL": "http://[::1]:8080"
    53      }
    54      with crowdsec(flavor=flavor, environment=env) as cs:
    55          cs.wait_for_log([
    56              "*Starting processing data*",
    57              "*CrowdSec Local API listening on [::1]:8080*",
    58          ])
    59          cs.wait_for_http(8080, '/health', want_status=HTTPStatus.OK)
    60          res = cs.cont.exec_run('cscli lapi status')
    61          assert res.exit_code == 0
    62          stdout = res.output.decode()
    63          assert "on http://[::1]:8080/" in stdout
    64          assert "You can successfully interact with Local API (LAPI)" in stdout