|
| 1 | +# (C) Datadog, Inc. 2026-present |
| 2 | +# All rights reserved |
| 3 | +# Licensed under a 3-clause BSD style license (see LICENSE) |
| 4 | +import pytest |
| 5 | + |
| 6 | +from datadog_checks.clickhouse import ClickhouseCheck |
| 7 | + |
| 8 | +from . import common |
| 9 | + |
| 10 | +pytestmark = [pytest.mark.integration, pytest.mark.usefixtures('dd_environment')] |
| 11 | + |
| 12 | + |
| 13 | +def test_connect_with_verify_false(aggregator, tls_instance, dd_run_check): |
| 14 | + """Regression: verify: false must allow connection to a self-signed cert. |
| 15 | +
|
| 16 | + Integration-level proof that the pool manager fix works end-to-end: the shared |
| 17 | + pool must be created with verify=False so clickhouse-connect doesn't override it |
| 18 | + with a cert_reqs=CERT_REQUIRED pool when pool_mgr is pre-supplied. |
| 19 | + """ |
| 20 | + tls_instance['verify'] = False |
| 21 | + check = ClickhouseCheck('clickhouse', {}, [tls_instance]) |
| 22 | + dd_run_check(check) |
| 23 | + aggregator.assert_service_check('clickhouse.can_connect', status=ClickhouseCheck.OK) |
| 24 | + |
| 25 | + |
| 26 | +def test_connect_ssl_verify_true_fails(tls_instance, dd_run_check): |
| 27 | + """Sanity: verify=True (default) must reject a self-signed cert. |
| 28 | +
|
| 29 | + Confirms TLS is actually active — without this passing, test_connect_with_verify_false |
| 30 | + would be vacuous (the server might just be accepting plain HTTP). |
| 31 | + """ |
| 32 | + tls_instance['verify'] = True |
| 33 | + check = ClickhouseCheck('clickhouse', {}, [tls_instance]) |
| 34 | + with pytest.raises(Exception): |
| 35 | + dd_run_check(check) |
| 36 | + |
| 37 | + |
| 38 | +def test_connect_verify_true_with_ca_cert(aggregator, tls_instance, dd_run_check): |
| 39 | + """Production path: verify=True + tls_ca_cert pointing at a trusted CA must succeed. |
| 40 | +
|
| 41 | + Most TLS-using DBM customers configure the integration this way — TLS on, cert |
| 42 | + validation on, with a custom CA bundle that trusts the server's cert. Pins that |
| 43 | + path against the self-signed server so the ca_cert plumbing in the shared pool |
| 44 | + manager doesn't silently regress. |
| 45 | + """ |
| 46 | + tls_instance['verify'] = True |
| 47 | + tls_instance['tls_ca_cert'] = common.SERVER_CERT_PATH |
| 48 | + check = ClickhouseCheck('clickhouse', {}, [tls_instance]) |
| 49 | + dd_run_check(check) |
| 50 | + aggregator.assert_service_check('clickhouse.can_connect', status=ClickhouseCheck.OK) |
0 commit comments