Exemplo n.º 1
0
def test_offline_no_post(session_post, config_file_factory,
                         rhsm_config_file_factory):
    '''
    Verify that when the metrics client is set to offline, no POSTs are performed
    '''
    config_file = config_file_factory("")
    rhsm_config_file = rhsm_config_file_factory()
    m = MetricsHTTPClient(config_file=config_file.name,
                          rhsm_config_file=rhsm_config_file.name)
    m.offline = True

    m.post("test")
    session_post.assert_not_called()
Exemplo n.º 2
0
def test_metrics_post_event_no_proxy(post, config_file_factory, rhsm_config_file_factory):
    config_file = config_file_factory("")
    rhsm_config_file = rhsm_config_file_factory()
    metrics_client = MetricsHTTPClient(config_file=config_file.name, rhsm_config_file=rhsm_config_file.name)

    event = Mock()
    metrics_client.post(event)

    post.assert_called_once_with(
        "https://cert-api.access.redhat.com:443/redhat_access/r/insights/platform/module-update-router/v1/event",
        json=event,
        proxies=None,
    )
Exemplo n.º 3
0
def test_metrics_post_event_proxy(post, config_file_factory, rhsm_config_file_factory):
    config_file = config_file_factory("")
    rhsm_config_file = rhsm_config_file_factory(
        proxy_hostname="localhost", proxy_port=3128, proxy_user="******", proxy_password="******"
    )
    metrics_client = MetricsHTTPClient(config_file=config_file.name, rhsm_config_file=rhsm_config_file.name)

    event = Mock()
    metrics_client.post(event)

    post.assert_called_once_with(
        "https://cert-api.access.redhat.com:443/redhat_access/r/insights/platform/module-update-router/v1/event",
        json=event,
        proxies={"https": "http://*****:*****@localhost:3128"},
    )
Exemplo n.º 4
0
def test_http_client_init_proxies_auto_config_default(
        proxy_settings, config_file_factory, rhsm_config_file_factory):
    config_file = config_file_factory("")
    rhsm_config_file = rhsm_config_file_factory()
    metrics_client = MetricsHTTPClient(config_file=config_file.name,
                                       rhsm_config_file=rhsm_config_file.name)
    assert metrics_client.proxies is proxy_settings.return_value
    proxy_settings.assert_called_once()
Exemplo n.º 5
0
def test_http_client_init_proxies_rhsm_config(
    proxy_settings, config_parser, config_file_factory, rhsm_config_file_factory
):
    config_file = config_file_factory("")
    rhsm_config_file = rhsm_config_file_factory()
    MetricsHTTPClient(config_file=config_file.name, rhsm_config_file=rhsm_config_file.name)
    config_parser.assert_called_once()
    config_parser.return_value.read.assert_called_once_with(rhsm_config_file.name)
    proxy_settings.assert_called_once_with(config_parser.return_value)
Exemplo n.º 6
0
def test_metrics_post_event_no_proxy(post, config_file_factory,
                                     rhsm_config_file_factory):
    config_file = config_file_factory("")
    rhsm_config_file = rhsm_config_file_factory(
        hostname="satellite.example.com",
        repo_ca_cert="/path/to/cacert/cert.pem",
        consumerCertDir="/path/to/sat/certs")
    metrics_client = MetricsHTTPClient(config_file=config_file.name,
                                       rhsm_config_file=rhsm_config_file.name)

    event = Mock()
    metrics_client.post(event)

    post.assert_called_once_with(
        "https://satellite.example.com:443/redhat_access/r/insights/platform/module-update-router/v1/event",
        json=event,
        proxies=None,
    )
Exemplo n.º 7
0
def test_http_client_init_proxies_auto_config_false(proxy_settings,
                                                    config_file_factory,
                                                    rhsm_config_file_factory):
    config_file = config_file_factory("auto_config = False\n")
    rhsm_config_file = rhsm_config_file_factory()
    metrics_client = MetricsHTTPClient(config_file=config_file.name,
                                       rhsm_config_file=rhsm_config_file.name)
    assert metrics_client.proxies is None
    proxy_settings.assert_not_called()
Exemplo n.º 8
0
def test_offline_basic_auth_no_pass(_proxy_settings, config_file_factory,
                                    rhsm_config_file_factory):
    '''
    Verify that if no password is provided for BASIC auth, metrics are not sent (default to offline)
    '''
    config_file = config_file_factory("username=testuser\nauthmethod=BASIC")
    rhsm_config_file = rhsm_config_file_factory()
    metrics_client = MetricsHTTPClient(config_file=config_file.name,
                                       rhsm_config_file=rhsm_config_file.name)
    assert metrics_client.offline
Exemplo n.º 9
0
def test_offline_basic_auth_stripping(_proxy_settings, config_file_factory,
                                      rhsm_config_file_factory):
    '''
    Verify that usernames and passwords have whitespace stripped
    '''
    config_file = config_file_factory(
        "username=testuser  \npassword=testpass  \nauthmethod=BASIC")
    rhsm_config_file = rhsm_config_file_factory()
    metrics_client = MetricsHTTPClient(config_file=config_file.name,
                                       rhsm_config_file=rhsm_config_file.name)
    assert metrics_client.auth == ("testuser", "testpass")
Exemplo n.º 10
0
def test_http_client_init_missing_server_section(proxy_settings,
                                                 config_file_factory):
    '''
    Verify that when the "server" section is missing, RHSM configuration is ignored
    and insights-client configuration is preferred
    '''
    config_file = config_file_factory(
        "username=testuser\npassword=testpass\nauthmethod=BASIC")
    rhsm_config_file = _tempfile("[nonsense]\ntest=test")
    metrics_client = MetricsHTTPClient(config_file=config_file.name,
                                       rhsm_config_file=rhsm_config_file.name)
    assert metrics_client.auth == ("testuser", "testpass")
    assert not metrics_client.cert
    assert metrics_client.base_url == "cloud.redhat.com"
    assert metrics_client.api_prefix == "/api"
    assert metrics_client.verify is True
Exemplo n.º 11
0
def test_http_metrics_client_post_proxies(post, config_file_factory, rhsm_config_file_factory):
    config_file = config_file_factory("")
    rhsm_config_file = rhsm_config_file_factory()

    metrics_client = MetricsHTTPClient(config_file=config_file.name, rhsm_config_file=rhsm_config_file.name)
    metrics_client.base_url = "localhost"

    proxies = {"https": "http://*****:*****@localhost:3128"}
    metrics_client.proxies = proxies

    metrics_client.post({})
    post.assert_called_once_with(ANY, json=ANY, proxies=proxies)
Exemplo n.º 12
0
def test_http_client_init_default_cert_auth(proxy_settings,
                                            config_file_factory):
    '''
    Verify that when insights-client configuration is used, CERT auth is selected
    if no authmethod is defined in the configuration file
    '''
    config_file = config_file_factory("username=testuser\npassword=testpass")
    rhsm_config_file = _tempfile("[nonsense]\nauth=test")
    metrics_client = MetricsHTTPClient(config_file=config_file.name,
                                       rhsm_config_file=rhsm_config_file.name,
                                       cert_file="/path/to/test/cert.pem",
                                       key_file="/path/to/test/key.pem")
    assert not metrics_client.auth
    assert metrics_client.verify is True
    assert metrics_client.cert == ("/path/to/test/cert.pem",
                                   "/path/to/test/key.pem")
    assert metrics_client.base_url == "cert.cloud.redhat.com"
    assert metrics_client.api_prefix == "/api"
Exemplo n.º 13
0
def test_offline_no_init(_proxy_settings, config_file_factory,
                         rhsm_config_file_factory):
    '''
    Verify that when the metrics client is set to offline, no further initialization is done
    '''
    config_file = config_file_factory("")
    rhsm_config_file = rhsm_config_file_factory()
    m = MetricsHTTPClient(config_file=config_file.name,
                          rhsm_config_file=rhsm_config_file.name)
    assert m.offline
    assert not hasattr(m, 'base_url')
    assert not hasattr(m, 'port')
    assert not m.cert
    assert m.verify
    assert not hasattr(m, 'api_prefix')
    assert not m.auth
    assert not m.proxies
    _proxy_settings.assert_not_called()
Exemplo n.º 14
0
def test_http_client_init_is_not_satellite(proxy_settings, config_file_factory,
                                           rhsm_config_file_factory):
    '''
    Verify that when the configured RHSM hostname matches one of the Red Hat subscription URLs,
    it is determined to NOT be a Satellite-subscribed host
    '''
    config_file = config_file_factory("")
    rhsm_config_file = rhsm_config_file_factory(
        hostname="subscription.rhsm.redhat.com")
    metrics_client = MetricsHTTPClient(config_file=config_file.name,
                                       rhsm_config_file=rhsm_config_file.name,
                                       cert_file="/path/to/test/cert.pem",
                                       key_file="/path/to/test/key.pem")
    assert not metrics_client.auth
    assert metrics_client.verify is True
    assert metrics_client.cert == ("/path/to/test/cert.pem",
                                   "/path/to/test/key.pem")
    assert metrics_client.base_url == "cert.cloud.redhat.com"
    assert metrics_client.api_prefix == "/api"
Exemplo n.º 15
0
def test_http_client_init_is_satellite(proxy_settings, config_file_factory,
                                       rhsm_config_file_factory):
    '''
    Verify that when the configured RHSM hostname does NOT match one of the Red Hat subscription URLs,
    it is determined to be a Satellite-subscribed host
    '''
    config_file = config_file_factory("")
    rhsm_config_file = rhsm_config_file_factory(
        hostname="satellite.example.com",
        port="443",
        repo_ca_cert="/path/to/cacert/cert.pem",
        consumerCertDir="/path/to/sat/certs")
    metrics_client = MetricsHTTPClient(config_file=config_file.name,
                                       rhsm_config_file=rhsm_config_file.name)
    assert not metrics_client.auth
    assert metrics_client.cert == ("/path/to/sat/certs/cert.pem",
                                   "/path/to/sat/certs/key.pem")
    assert metrics_client.port == "443"
    assert metrics_client.base_url == "satellite.example.com"
    assert metrics_client.verify == "/path/to/cacert/cert.pem"
    assert metrics_client.api_prefix == "/redhat_access/r/insights/platform"