Fix the TLS settings check for a payments client
Your task
Asked to fix connection errors to a payments API, an AI turned off certificate and hostname verification in the client, and the errors went away. You are adding a review rule that flags TLS client settings like that before they merge.
An assistant wrote review_tls_settings(settings). It is in the editor. It has a bug. Find it and fix it.
Input and output:
settings: the client's TLS settings, one"key=value"string each.- Return the findings as a list of strings.
Rules the tests check:
- Skip a line with no
=. Otherwise split it at the first=. - Trim spaces from the key and the value, and compare both without regard to case.
- The findings are:
"hostname_check_disabled": keycheck_hostnamewith valuefalse."cert_verification_disabled": keyverify_modewith valuecert_none."missing_ca_bundle": keyca_bundlewith an empty value."weak_tls_version": keymin_tls_versionwith value1.0,1.1orssl3.
- Any other key or value is not a finding.
- Return each finding once, sorted in ascending order.
Examples
review_tls_settings(settings: list[str]) -> list[str]Example 1
Input
review_tls_settings(["check_hostname=false", "verify_mode=CERT_NONE", "ca_bundle=/etc/ssl/certs/ca.pem", "min_tls_version=1.2"])Output
["cert_verification_disabled", "hostname_check_disabled"]Example 2
Input
review_tls_settings(["check_hostname=true", "verify_mode=CERT_REQUIRED", "ca_bundle=/etc/ssl/certs/ca.pem", "min_tls_version=1.3"])Output
[]Example 3
Input
review_tls_settings(["min_tls_version=1.0", "ca_bundle="])Output
["missing_ca_bundle", "weak_tls_version"]