🤬
  • Improving test coverage with live squid server

  • Loading...
  • dgtlmoon committed 2 years ago
    a10a6d6c
    1 parent d4d06973
  • ■ ■ ■ ■ ■ ■
    changedetectionio/run_all_tests.sh
    skipped 48 lines
    49 49   
    50 50  unset PLAYWRIGHT_DRIVER_URL
    51 51  docker kill $$-test_browserless
     52 + 
     53 +# Test proxy list handling, starting two squids on different ports
     54 +# Each squid adds a different header to the response, which is the main thing we test for.
     55 +docker run -d --name $$-squid-one --rm -v `pwd`/tests/proxy_list/squid.conf:/etc/squid/conf.d/debian.conf -p 3128:3128 ubuntu/squid:4.13-21.10_edge
     56 +docker run -d --name $$-squid-two --rm -v `pwd`/tests/proxy_list/squid.conf:/etc/squid/conf.d/debian.conf -p 3129:3128 ubuntu/squid:4.13-21.10_edge
     57 + 
     58 + 
     59 +# So, basic HTTP as env var test
     60 +export HTTP_PROXY=http://localhost:3128
     61 +export HTTPS_PROXY=http://localhost:3128
     62 +pytest tests/proxy_list/test_proxy.py
     63 +docker logs $$-squid-one 2>/dev/null|grep one.changedetection.io
     64 +if [ $? -ne 0 ]
     65 +then
     66 + echo "Did not see a request to one.changedetection.io in the squid logs (while checking env vars HTTP_PROXY/HTTPS_PROXY)"
     67 +fi
     68 +unset HTTP_PROXY
     69 +unset HTTPS_PROXY
     70 + 
     71 + 
     72 +# 2nd test actually choose the preferred proxy from proxies.json
     73 +#cp tests/proxy_list/proxies.json-example ./test-datastore/proxies.json
     74 +#pytest tests/proxy_list/test_multiple_proxy.py
     75 + 
     76 + 
     77 +docker kill $$-squid-one
     78 +docker kill $$-squid-two
     79 + 
     80 + 
     81 + 
  • ■ ■ ■ ■ ■ ■
    changedetectionio/tests/proxy_list/__init__.py
     1 +"""Tests for the app."""
     2 + 
     3 + 
  • ■ ■ ■ ■ ■ ■
    changedetectionio/tests/proxy_list/conftest.py
     1 +#!/usr/bin/python3
     2 + 
     3 +from .. import conftest
     4 + 
     5 +#def pytest_addoption(parser):
     6 +# parser.addoption("--url_suffix", action="store", default="identifier for request")
     7 + 
     8 + 
     9 +#def pytest_generate_tests(metafunc):
     10 +# # This is called for every test. Only get/set command line arguments
     11 +# # if the argument is specified in the list of test "fixturenames".
     12 +# option_value = metafunc.config.option.url_suffix
     13 +# if 'url_suffix' in metafunc.fixturenames and option_value is not None:
     14 +# metafunc.parametrize("url_suffix", [option_value])
  • ■ ■ ■ ■ ■ ■
    changedetectionio/tests/proxy_list/proxies.json-example
     1 +{
     2 + "proxy-one": {
     3 + "label": "One",
     4 + "url": "http://127.0.0.1:3128"
     5 + },
     6 + "proxy-two": {
     7 + "label": "two",
     8 + "url": "http://127.0.0.1:3129"
     9 + }
     10 +}
     11 + 
  • ■ ■ ■ ■ ■ ■
    changedetectionio/tests/proxy_list/squid.conf
     1 +acl localnet src 0.0.0.1-0.255.255.255 # RFC 1122 "this" network (LAN)
     2 +acl localnet src 10.0.0.0/8 # RFC 1918 local private network (LAN)
     3 +acl localnet src 100.64.0.0/10 # RFC 6598 shared address space (CGN)
     4 +acl localnet src 169.254.0.0/16 # RFC 3927 link-local (directly plugged) machines
     5 +acl localnet src 172.16.0.0/12 # RFC 1918 local private network (LAN)
     6 +acl localnet src 192.168.0.0/16 # RFC 1918 local private network (LAN)
     7 +acl localnet src fc00::/7 # RFC 4193 local private network range
     8 +acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines
     9 +acl localnet src 159.65.224.174
     10 +acl SSL_ports port 443
     11 +acl Safe_ports port 80 # http
     12 +acl Safe_ports port 21 # ftp
     13 +acl Safe_ports port 443 # https
     14 +acl Safe_ports port 70 # gopher
     15 +acl Safe_ports port 210 # wais
     16 +acl Safe_ports port 1025-65535 # unregistered ports
     17 +acl Safe_ports port 280 # http-mgmt
     18 +acl Safe_ports port 488 # gss-http
     19 +acl Safe_ports port 591 # filemaker
     20 +acl Safe_ports port 777 # multiling http
     21 +acl CONNECT method CONNECT
     22 + 
     23 +http_access deny !Safe_ports
     24 +http_access deny CONNECT !SSL_ports
     25 +http_access allow localhost manager
     26 +http_access deny manager
     27 +http_access allow localhost
     28 +http_access allow localnet
     29 +http_access deny all
     30 +http_port 3128
     31 +coredump_dir /var/spool/squid
     32 +refresh_pattern ^ftp: 1440 20% 10080
     33 +refresh_pattern ^gopher: 1440 0% 1440
     34 +refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
     35 +refresh_pattern \/(Packages|Sources)(|\.bz2|\.gz|\.xz)$ 0 0% 0 refresh-ims
     36 +refresh_pattern \/Release(|\.gpg)$ 0 0% 0 refresh-ims
     37 +refresh_pattern \/InRelease$ 0 0% 0 refresh-ims
     38 +refresh_pattern \/(Translation-.*)(|\.bz2|\.gz|\.xz)$ 0 0% 0 refresh-ims
     39 +refresh_pattern . 0 20% 4320
     40 +logfile_rotate 0
     41 + 
     42 + 
  • ■ ■ ■ ■ ■ ■
    changedetectionio/tests/proxy_list/test_multiple_proxy.py
     1 +#!/usr/bin/python3
     2 + 
     3 +import time
     4 +from flask import url_for
     5 +from ..util import live_server_setup, wait_for_all_checks, extract_UUID_from_client
     6 + 
     7 +def test_check_basic_change_detection_functionality(client, live_server):
     8 + time.sleep(1)
     9 + live_server_setup(live_server)
     10 + time.sleep(1)
     11 + res = client.post(
     12 + url_for("import_page"),
     13 + # Because a URL wont show in squid/proxy logs due it being SSLed
     14 + # Use plain HTTP or a specific domain-name here
     15 + data={"urls": "http://one.changedetection.io"},
     16 + follow_redirects=True
     17 + )
     18 + 
     19 + assert b"1 Imported" in res.data
     20 + time.sleep(2)
     21 + 
  • ■ ■ ■ ■ ■ ■
    changedetectionio/tests/proxy_list/test_proxy.py
     1 +#!/usr/bin/python3
     2 + 
     3 +import time
     4 +from flask import url_for
     5 +from ..util import live_server_setup, wait_for_all_checks, extract_UUID_from_client
     6 + 
     7 +# just make a request, we will grep in the docker logs to see it actually got called
     8 +def test_check_basic_change_detection_functionality(client, live_server):
     9 + live_server_setup(live_server)
     10 + res = client.post(
     11 + url_for("import_page"),
     12 + # Because a URL wont show in squid/proxy logs due it being SSLed
     13 + # Use plain HTTP or a specific domain-name here
     14 + data={"urls": "http://one.changedetection.io"},
     15 + follow_redirects=True
     16 + )
     17 + 
     18 + assert b"1 Imported" in res.data
     19 + time.sleep(3)
     20 + 
Please wait...
Page is in error, reload to recover