def fetch():
        headers = make_cross_agent_headers(inbound_payload, ENCODING_KEY,
                                           cat_id)
        resp = yield from aiohttp_app.client.request(method,
                                                     uri,
                                                     headers=headers)

        if _raw_headers:
            raw_headers = _raw_headers
        else:
            raw_headers = {
                k.decode('utf-8'): v.decode('utf-8')
                for k, v in resp.raw_headers
            }

        if expected_intrinsics:
            # test valid CAT response header
            assert 'X-NewRelic-App-Data' in raw_headers

            app_data = json.loads(
                deobfuscate(raw_headers['X-NewRelic-App-Data'], ENCODING_KEY))
            assert app_data[0] == cat_id
            assert app_data[1] == ('WebTransaction/Function/%s' % metric_name)
        else:
            assert 'X-NewRelic-App-Data' not in resp.headers
def test_transaction_error_cross_agent():
    test_environ = {
        "err_message": ERR_MESSAGE,
    }
    settings = application_settings()
    transaction_data = [7, 1, 77, "/path-hash"]
    headers = make_cross_agent_headers(transaction_data, settings.encoding_key, settings.cross_process_id)
    response = fully_featured_application.get("/", headers=headers, extra_environ=test_environ)
def test_cat_response_custom_header(app):
    inbound_payload = [
        'b854df4feb2b1f06', False, '7e249074f277923d', '5d2957be'
    ]
    cat_id = '1#1'
    custom_header_value = b'my-custom-header-value'
    cat_headers = make_cross_agent_headers(inbound_payload, ENCODING_KEY,
                                           cat_id)

    response = app.fetch('get',
                         '/custom-header/%s/%s' %
                         ('X-NewRelic-App-Data', custom_header_value),
                         headers=dict(cat_headers))
    assert custom_header_value in raw_headers(response), raw_headers(response)
Example #4
0
def test_cat_headers_not_inserted(app):
    payload = (
        u'1#1', u'WebTransaction/Function/app:beep',
        0, 1.23, -1,
        'dd4a810b7cb7f937', False
    )
    headers = make_cross_agent_headers(payload, ENCODING_KEY, '1#1')

    client_cross_process_id = headers['X-NewRelic-ID']
    txn_header = headers['X-NewRelic-Transaction']

    response = app.fetch('/304-cat-response/%s/%s' %
            (client_cross_process_id, txn_header))
    assert response.code == 304
    assert 'X-NewRelic-App-Data' not in list(response.headers.keys())
Example #5
0
def test_response_to_inbound_cat(app, manual_flush):
    payload = (
        u'1#1', u'WebTransaction/Function/app:beep',
        0, 1.23, -1,
        'dd4a810b7cb7f937', False
    )
    headers = make_cross_agent_headers(payload, ENCODING_KEY, '1#1')

    client_cross_process_id = headers['X-NewRelic-ID']
    txn_header = headers['X-NewRelic-Transaction']

    response = app.fetch('/force-cat-response/%s/%s/%s' %
            (client_cross_process_id, txn_header, manual_flush))
    assert response.code == 200
    assert 'X-NewRelic-App-Data' in list(response.headers.keys())
    def _test():
        cat_headers = make_cross_agent_headers(inbound_payload, ENCODING_KEY,
                                               cat_id)
        response = app.fetch('get', url, headers=dict(cat_headers))
        if expected_intrinsics:
            # test valid CAT response header
            assert b'X-NewRelic-App-Data' in raw_headers(response)
            cat_response_header = response.headers.get("X-NewRelic-App-Data",
                                                       None)

            app_data = json.loads(
                deobfuscate(cat_response_header, ENCODING_KEY))
            assert app_data[0] == cat_id
            assert app_data[1] == ('WebTransaction/Function/%s' % metric_name)
        else:
            assert b'X-NewRelic-App-Data' not in raw_headers(response)
Example #7
0
    def run_cat_test():

        if six.PY2:
            txn_name = transactionName.encode('UTF-8')
            guid = transactionGuid.encode('UTF-8')
        else:
            txn_name = transactionName
            guid = transactionGuid

        # Only generate old cat style headers. This will test to make sure we
        # are properly ignoring these headers when the agent is using better
        # cat.

        headers = make_cross_agent_headers(inboundPayload, ENCODING_KEY, '1#1')
        response = target_application.get('/',
                                          headers=headers,
                                          extra_environ={
                                              'txn':
                                              txn_name,
                                              'guid':
                                              guid,
                                              'old_cat':
                                              str(old_cat),
                                              'server_url':
                                              'http://localhost:%d' %
                                              server.port
                                          })

        # Validation of analytic data happens in the decorator.

        assert response.status == '200 OK'

        content = response.html.html.body.p.string

        # Validate actual body content as sansity check.

        assert content == 'RESPONSE'
Example #8
0
def test_cat_insertion_disabled_on_304():
    headers = make_cross_agent_headers(payload, ENCODING_KEY, '1#1')
    response = test_application.get('/304', headers=headers)
    assert 'X-NewRelic-App-Data' not in response.headers
Example #9
0
def test_cat_disabled_browser_monitoring():
    headers = make_cross_agent_headers(payload, ENCODING_KEY, '1#1')
    response = test_application.get('/200', headers=headers)
    assert 'X-NewRelic-App-Data' in response.headers
Example #10
0
def test_inbound_cat_metrics_and_intrinsics(app):
    payload = ['b854df4feb2b1f06', False, '7e249074f277923d', '5d2957be']
    headers = make_cross_agent_headers(payload, ENCODING_KEY, '1#1')

    response = app.fetch('/simple', headers=headers)
    assert response.code == 200
def test_cat_insertion_disabled_on_304():
    headers = make_cross_agent_headers(payload, ENCODING_KEY, "1#1")
    response = test_application.get("/304", headers=headers)
    assert "X-NewRelic-App-Data" not in response.headers