5e212a6bf3
With the management tunnels work, we allow calls to our edge service using an access JWT provided by Tunnelstore. Given a connector ID, this request is then proxied to the appropriate Cloudflare Tunnel. This PR takes advantage of this flow and adds a new host_details endpoint. Calls to this endpoint will result in cloudflared gathering some details about the host: hostname (os.hostname()) and ip address (localAddr in a dial). Note that the mini spec lists 4 alternatives and this picks alternative 3 because: 1. Ease of implementation: This is quick and non-intrusive to any of our code path. We expect to change how connection tracking works and regardless of the direction we take, it may be easy to keep, morph or throw this away. 2. The cloudflared part of this round trip takes some time with a hostname call and a dial. But note that this is off the critical path and not an API that will be exercised often. |
||
---|---|---|
.. | ||
.gitignore | ||
README.md | ||
cli.py | ||
config.py | ||
config.yaml | ||
conftest.py | ||
constants.py | ||
requirements.txt | ||
setup.py | ||
test_config.py | ||
test_edge_discovery.py | ||
test_logging.py | ||
test_pq.py | ||
test_proxy_dns.py | ||
test_quicktunnels.py | ||
test_reconnect.py | ||
test_service.py | ||
test_termination.py | ||
test_token.py | ||
test_tunnel.py | ||
util.py |
README.md
Requirements
-
Python 3.7 or later with packages in the given
requirements.txt
- E.g. with conda:
conda create -n component-tests python=3.7
conda activate component-tests
pip3 install -r requirements.txt
-
Create a config yaml file, for example:
cloudflared_binary: "cloudflared"
tunnel: "3d539f97-cd3a-4d8e-c33b-65e9099c7a8d"
credentials_file: "/Users/tunnel/.cloudflared/3d539f97-cd3a-4d8e-c33b-65e9099c7a8d.json"
origincert: "/Users/tunnel/.cloudflared/cert.pem"
ingress:
- hostname: named-tunnel-component-tests.example.com
service: hello_world
- service: http_status:404
- Route hostname to the tunnel. For the example config above, we can do that via
cloudflared tunnel route dns 3d539f97-cd3a-4d8e-c33b-65e9099c7a8d named-tunnel-component-tests.example.com
-
Turn on linter If you are using Visual Studio, follow https://code.visualstudio.com/docs/python/linting to turn on linter.
-
Turn on formatter If you are using Visual Studio, follow https://code.visualstudio.com/docs/python/editing#_formatting to turn on formatter and https://marketplace.visualstudio.com/items?itemName=cbrevik.toggle-format-on-save to turn on format on save.
-
If you have cloudflared running as a service on your machine, you can either stop the service or ignore the service tests via
--ignore test_service.py
How to run
Specify path to config file via env var COMPONENT_TESTS_CONFIG
. This is required.
All tests
Run pytest
inside this(component-tests) folder
Specific files
Run pytest <file 1 name>.py <file 2 name>.py
Specific tests
Run pytest file.py -k <test 1 name> -k <test 2 name>
Live Logging
Running with -o log_cli=true
outputs logging to CLI as the tests are. By default the log level is WARN.
--log-cli-level
control logging level.
For example, to log at info level, run pytest -o log_cli=true --log-cli-level=INFO
.
See https://docs.pytest.org/en/latest/logging.html#live-logs for more documentation on logging.