Skip to content

fix: detect a local Appium server that uses a self-signed HTTPS certificate - #15

Draft
MattL1989 wants to merge 1 commit into
masterfrom
fix/service-listening-self-signed-https
Draft

MattL1989 wants to merge 1 commit into
masterfrom
fix/service-listening-self-signed-https

Conversation

@MattL1989

Copy link
Copy Markdown
Owner

Problem

When AppiumService.start() gets --ssl-cert-path and --ssl-key-path, it checks that the server is up by sending HEAD https://<address>:<port>/status through is_service_listening. That probe verifies the server certificate. The address defaults to 127.0.0.1, so the check fails whenever the certificate is self-signed or not issued for that address, which is the usual case for a local server:

service = AppiumService()
service.start(args=['--ssl-cert-path', 'cert.pem', '--ssl-key-path', 'key.pem'])
# AppiumServiceError: Appium server has started but is not listening on https://127.0.0.1:4723/status ...

The server is up, but start() stops it and raises. service.is_listening returns False for the same reason.

Fix

Only is_service_listening changes:

  • The probe's PoolManager is created with cert_reqs='CERT_NONE', so it does not verify the certificate.
  • urllib3 then emits InsecureRequestWarning for every probe request. The warning is ignored inside warnings.catch_warnings() around that one request only. The global warning filters are not changed.
  • Plain http:// urls are not affected, because urllib3 drops the TLS options for http connection pools.

This is safe because the probe only sends a HEAD request without a body or credentials to the status endpoint, and only reads the response status. Skipping verification here does not affect the WebDriver session: commands still go through Selenium's RemoteConnection with its own certificate settings. is_service_listening is a public function, so calling it directly with an https:// url also skips certificate verification. It still only sends that HEAD request and reads the status code.

Tests

  • New test/unit/webdriver/appium_service_https_test.py checks that:
    • the probe's PoolManager is created with cert_reqs='CERT_NONE';
    • an InsecureRequestWarning raised during the probe request does not reach the caller, while one raised after the probe still does.
  • Both tests fail without the fix: KeyError: 'cert_reqs', and the recorded warning list is not empty.
  • These tests mock urllib3.PoolManager, like the existing AppiumService tests, because the dev dependencies have no package to generate a certificate (cryptography or trustme).
  • I also checked by hand against a real local http.server using a self-signed certificate made with openssl, for a cert issued to localhost and probed on 127.0.0.1:
    • before the fix, is_service_listening('https://127.0.0.1:<port>/status') returns False;
    • after the fix, it returns True, and no warning is shown;
    • a plain HTTP server returns True before and after.
  • ruff check, ruff format --check, mypy appium and the full unit test suite pass.

🤖 Generated with Claude Code

…ficate

When AppiumService starts the server with --ssl-cert-path and
--ssl-key-path, it probes https://<address>:<port>/status to check that
the server is listening. is_service_listening verified the server
certificate, so the probe failed whenever the certificate was
self-signed or not issued for the probed address, which is the usual
case for a local server on 127.0.0.1. start() then stopped the server
and raised AppiumServiceError ("Appium server has started but is not
listening ..."), and is_listening returned False, although the server
was up.

Don't verify the certificate in this liveness probe, and ignore
urllib3's InsecureRequestWarning only while the probe request runs, so
the global warning filters are left as they were. The probe only sends
a HEAD request and reads the response status, so no data is exposed.
Plain HTTP urls are not affected: urllib3 drops the TLS options for
http pools.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant