|
21 | 21 | end style test, it does not fit as a unittest. |
22 | 22 | """ |
23 | 23 |
|
| 24 | +import pytest |
24 | 25 | import webtest |
25 | 26 |
|
| 27 | +from newrelic.api.background_task import background_task |
| 28 | +from newrelic.api.external_trace import ExternalTrace |
26 | 29 | from newrelic.api.wsgi_application import wsgi_application |
27 | 30 |
|
28 | 31 | from testing_support.fixtures import (make_cross_agent_headers, |
@@ -72,3 +75,28 @@ def test_cat_insertion_disabled_on_304(): |
72 | 75 | headers = make_cross_agent_headers(payload, ENCODING_KEY, '1#1') |
73 | 76 | response = test_application.get('/304', headers=headers) |
74 | 77 | assert 'X-NewRelic-App-Data' not in response.headers |
| 78 | + |
| 79 | +_override_settings = { |
| 80 | + 'cross_application_tracing.enabled': True, |
| 81 | + 'distributed_tracing.enabled': False, |
| 82 | +} |
| 83 | +@override_application_settings(_override_settings) |
| 84 | +@pytest.mark.parametrize('fips_enabled', (False, True)) |
| 85 | +@background_task() |
| 86 | +def test_cat_fips_compliance(monkeypatch, fips_enabled): |
| 87 | + # Set md5 to raise a ValueError to simulate FIPS compliance issues. |
| 88 | + def md5_crash(*args, **kwargs): |
| 89 | + raise ValueError() |
| 90 | + |
| 91 | + if fips_enabled: |
| 92 | + # monkeypatch.setattr("hashlib.md5", md5_crash) |
| 93 | + import hashlib |
| 94 | + monkeypatch.setattr(hashlib, "md5", md5_crash) |
| 95 | + |
| 96 | + # Generate and send request using actual transaction api instead of fixture. |
| 97 | + # Otherwise the proper code paths are not exercised. |
| 98 | + with ExternalTrace("cat_test", "http://localhost/200") as tracer: |
| 99 | + headers = tracer.generate_request_headers(tracer.transaction) |
| 100 | + |
| 101 | + expected = not fips_enabled # Invert to make more human readable |
| 102 | + assert ('X-NewRelic-Transaction' in dict(headers)) == expected |
0 commit comments