コード例 #1
0
def test_check_ssl_expire_error(aggregator, http_check):
    with mock.patch('ssl.SSLSocket.getpeercert', side_effect=Exception()):
        # Run the check for the one instance configured with days left
        http_check = HTTPCheck('', {}, [CONFIG_EXPIRED_SSL['instances'][0]])
        http_check.check(CONFIG_EXPIRED_SSL['instances'][0])

    expired_cert_tags = ['url:https://valid.mock', 'instance:expired_cert']
    aggregator.assert_service_check(HTTPCheck.SC_STATUS, status=HTTPCheck.OK, tags=expired_cert_tags, count=1)
    aggregator.assert_service_check(HTTPCheck.SC_SSL_CERT, status=HTTPCheck.CRITICAL, tags=expired_cert_tags, count=1)
コード例 #2
0
def test_check_allow_redirects(aggregator):
    with mock.patch('datadog_checks.http_check.http_check.get_ca_certs_path', new=mock_get_ca_certs_path):
        http_check = HTTPCheck('http_check', {}, CONFIG_HTTP_NO_REDIRECTS["instances"])
        # Run the check for the one instance
        http_check.check(CONFIG_HTTP_NO_REDIRECTS['instances'][0])
        redirect_service_tags = ['url:https://valid.mock/301', 'instance:no_allow_redirect_service']
        aggregator.assert_service_check(HTTPCheck.SC_STATUS, status=HTTPCheck.OK, tags=redirect_service_tags, count=1)

        redirect_service_tags = ['url:https://valid.mock/301', 'instance:allow_redirect_service']
        http_check.check(CONFIG_HTTP_ALLOW_REDIRECTS['instances'][0])
        aggregator.assert_service_check(
            HTTPCheck.SC_STATUS, status=HTTPCheck.CRITICAL, tags=redirect_service_tags, count=1
        )
コード例 #3
0
def test_unexisting_ca_cert_should_throw_error(aggregator):
    instance = {
        'name': 'Test Web VM HTTPS SSL',
        'url': 'https://foo.bar.net/',
        'method': 'get',
        'tls_ca_cert': '/tmp/unexisting.crt',
        'check_certificate_expiration': 'false',
        'collect_response_time': 'false',
        'disable_ssl_validation': 'false',
        'skip_proxy': 'false',
    }

    check = HTTPCheck('http_check', {'ca_certs': 'foo'}, [instance])

    check.check(instance)
    aggregator.assert_service_check(HTTPCheck.SC_STATUS, status=AgentCheck.CRITICAL)
    assert 'invalid path: /tmp/unexisting.crt' in aggregator._service_checks[HTTPCheck.SC_STATUS][0].message
コード例 #4
0
def test_check_tsl_ca_cert(aggregator):
    instance = {
        'name': 'good_cert',
        'url': 'https://valid.mock:443',
        'timeout': 1,
        'tls_ca_cert': os.path.join(HERE, 'fixtures', 'cacert.pem'),
        'check_certificate_expiration': 'false',
        'collect_response_time': 'false',
        'disable_ssl_validation': 'false',
        'skip_proxy': 'false',
    }

    with mock.patch(
        'datadog_checks.http_check.http_check.get_ca_certs_path',
        new=lambda: os.path.join(HERE, 'fixtures', 'emptycert.pem'),
    ):
        check = HTTPCheck('http_check', {}, [instance])

    check.check(instance)
    good_cert_tags = ['url:https://valid.mock:443', 'instance:good_cert']
    aggregator.assert_service_check(HTTPCheck.SC_STATUS, status=HTTPCheck.OK, tags=good_cert_tags, count=1)