Files
glances/tests/test_web_list_ssl_verify.py
datrixlab ac741d299c Read web_x_ssl_verify as a boolean, not as a CA bundle path
GlancesWebList takes web_x_ssl_verify through config.get_value(), which
returns the raw string, and hands it to requests.head(verify=...).
Requests reads a string verify as the path to a CA bundle, so the value
from the configuration file is looked up as a file name:

    verify='false'            -> OSError: Could not find a suitable TLS CA
    verify='true'             -> OSError: ... invalid path: true
    verify=False / verify=True -> the request is actually made

ThreadScanner._web_scan catches everything and sets status='Error', so the
URL sits permanently red in the curses view and the WebUI, with only a
debug-level log line to explain it. Setting the key to true, which is what
a user does to turn verification back on explicitly, breaks the scan the
same way as false.

Read it with config.get_bool_value(), the helper the network and diskio
plugins already use for their switches, and keep a non-boolean value as a
string: a path to a CA bundle is a valid value for requests' verify, and
that is the one form that worked before.

The key was undocumented, which is probably how this survived; document it
next to the other web_x_ options in conf/glances.conf and docs/aoa/ports.rst.
2026-09-12 11:31:29 +07:00

61 lines
1.6 KiB
Python

#!/usr/bin/env python
#
# Glances - An eye on your system
#
# SPDX-FileCopyrightText: 2026 Nicolas Hennion <nicolas@nicolargo.com>
#
# SPDX-License-Identifier: LGPL-3.0-only
#
"""Tests for web_x_ssl_verify in the URL monitoring list."""
import pytest
from glances.config import Config
from glances.web_list import GlancesWebList
CONFIG = """
[ports]
refresh=30
timeout=3
port_default_gateway=False
web_1_url=https://example.com
web_1_ssl_verify=false
web_2_url=https://example.com
web_2_ssl_verify=true
web_3_url=https://example.com
web_3_ssl_verify=/etc/ssl/certs/ca-bundle.crt
web_4_url=https://example.com
"""
@pytest.fixture
def web_list(tmp_path):
conf_file = tmp_path / 'glances.conf'
conf_file.write_text(CONFIG)
return GlancesWebList(config=Config(config_dir=str(conf_file))).get_web_list()
def ssl_verify(web_list, indice):
return next(web['ssl_verify'] for web in web_list if web['indice'] == indice)
# Requests reads a string `verify` as the path to a CA bundle, so a boolean written
# in the configuration file has to reach it as a boolean: 'false' (and 'true') used
# to fail every scan of the URL with "Could not find a suitable TLS CA certificate
# bundle, invalid path: false".
def test_ssl_verify_false_is_a_boolean(web_list):
assert ssl_verify(web_list, 'web_1') is False
def test_ssl_verify_true_is_a_boolean(web_list):
assert ssl_verify(web_list, 'web_2') is True
def test_ssl_verify_keeps_a_ca_bundle_path(web_list):
assert ssl_verify(web_list, 'web_3') == '/etc/ssl/certs/ca-bundle.crt'
def test_ssl_verify_defaults_to_true(web_list):
assert ssl_verify(web_list, 'web_4') is True