|
17 | 17 | from ddtrace._trace.pin import Pin |
18 | 18 | from ddtrace.contrib.internal import trace_utils |
19 | 19 | from ddtrace.contrib.internal.trace_utils import _get_request_header_client_ip |
20 | | -from ddtrace.ext import SpanTypes |
21 | 20 | from ddtrace.ext import http |
22 | | -from ddtrace.ext import net |
23 | 21 | from ddtrace.internal.compat import ensure_text |
24 | 22 | from ddtrace.internal.settings._config import Config |
25 | 23 | from ddtrace.internal.settings.integration import IntegrationConfig |
|
28 | 26 | from ddtrace.propagation.http import HTTPPropagator |
29 | 27 | from ddtrace.trace import Context |
30 | 28 | from ddtrace.trace import Span |
31 | | -from tests.appsec.utils import asm_context |
32 | 29 | from tests.utils import override_global_config |
33 | 30 |
|
34 | 31 |
|
@@ -389,128 +386,6 @@ def test_set_http_meta_with_http_header_tags_config(): |
389 | 386 | assert response_span.get_tag("third-header") == "value3" |
390 | 387 |
|
391 | 388 |
|
392 | | -@pytest.mark.parametrize("appsec_enabled", [False, True]) |
393 | | -@pytest.mark.parametrize("span_type", [SpanTypes.WEB, SpanTypes.HTTP, None]) |
394 | | -@pytest.mark.parametrize( |
395 | | - "method,url,status_code,status_msg,query,request_headers,response_headers,uri,path_params,cookies,target_host", |
396 | | - [ |
397 | | - ("GET", "http://localhost/", 0, None, None, None, None, None, None, None, "localhost"), |
398 | | - ("GET", "http://localhost/", 200, "OK", None, None, None, None, None, None, "localhost"), |
399 | | - (None, None, None, None, None, None, None, None, None, None, None), |
400 | | - ( |
401 | | - "GET", |
402 | | - "http://localhost/", |
403 | | - 200, |
404 | | - "OK", |
405 | | - None, |
406 | | - {"my-header": "value1"}, |
407 | | - {"resp-header": "val"}, |
408 | | - "http://localhost/", |
409 | | - None, |
410 | | - None, |
411 | | - "localhost", |
412 | | - ), |
413 | | - ( |
414 | | - "GET", |
415 | | - "http://localhost/", |
416 | | - 200, |
417 | | - "OK", |
418 | | - "q=test+query&q2=val", |
419 | | - {"my-header": "value1"}, |
420 | | - {"resp-header": "val"}, |
421 | | - "http://localhost/search?q=test+query&q2=val", |
422 | | - {"id": "val", "name": "vlad"}, |
423 | | - None, |
424 | | - "localhost", |
425 | | - ), |
426 | | - ("GET", "http://user:pass@localhost/", 0, None, None, None, None, None, None, None, None), |
427 | | - ("GET", "http://user@localhost/", 0, None, None, None, None, None, None, None, None), |
428 | | - ("GET", "http://user:pass@localhost/api?q=test", 0, None, None, None, None, None, None, None, None), |
429 | | - ("GET", "http://localhost/api@test", 0, None, None, None, None, None, None, None, None), |
430 | | - ("GET", "http://localhost/?api@test", 0, None, None, None, None, None, None, None, None), |
431 | | - ], |
432 | | -) |
433 | | -def test_set_http_meta( |
434 | | - span, |
435 | | - int_config, |
436 | | - method, |
437 | | - url, |
438 | | - target_host, |
439 | | - status_code, |
440 | | - status_msg, |
441 | | - query, |
442 | | - request_headers, |
443 | | - response_headers, |
444 | | - uri, |
445 | | - path_params, |
446 | | - cookies, |
447 | | - appsec_enabled, |
448 | | - span_type, |
449 | | -): |
450 | | - int_config.myint.http.trace_headers(["my-header"]) |
451 | | - int_config.myint.http.trace_query_string = True |
452 | | - span.span_type = span_type |
453 | | - with asm_context(config={"_asm_enabled": appsec_enabled}): |
454 | | - trace_utils.set_http_meta( |
455 | | - span, |
456 | | - int_config.myint, |
457 | | - method=method, |
458 | | - url=url, |
459 | | - target_host=target_host, |
460 | | - status_code=status_code, |
461 | | - status_msg=status_msg, |
462 | | - query=query, |
463 | | - raw_uri=uri, |
464 | | - request_headers=request_headers, |
465 | | - response_headers=response_headers, |
466 | | - request_cookies=cookies, |
467 | | - request_path_params=path_params, |
468 | | - ) |
469 | | - if method is not None: |
470 | | - assert span.get_tag(http.METHOD) == method |
471 | | - else: |
472 | | - assert http.METHOD not in span.get_tags() |
473 | | - |
474 | | - if target_host is not None: |
475 | | - assert span.get_tag(net.TARGET_HOST) == target_host |
476 | | - else: |
477 | | - assert net.TARGET_HOST not in span.get_tags() |
478 | | - |
479 | | - if url is not None: |
480 | | - if url.startswith("http://user"): |
481 | | - # Remove any userinfo that may be in the original url |
482 | | - expected_url = url[: url.index(":")] + "://" + url[url.index("@") + 1 :] |
483 | | - else: |
484 | | - expected_url = url |
485 | | - |
486 | | - if query and int_config.myint.http.trace_query_string: |
487 | | - assert span.get_tag(http.URL) == str(expected_url + "?" + query) |
488 | | - else: |
489 | | - assert span.get_tag(http.URL) == str(expected_url) |
490 | | - else: |
491 | | - assert http.URL not in span.get_tags() |
492 | | - |
493 | | - if status_code is not None: |
494 | | - assert span.get_tag(http.STATUS_CODE) == str(status_code) |
495 | | - if 500 <= int(status_code) < 600: |
496 | | - assert span.error == 1 |
497 | | - else: |
498 | | - assert span.error == 0 |
499 | | - else: |
500 | | - assert http.STATUS_CODE not in span.get_tags() |
501 | | - |
502 | | - if status_msg is not None: |
503 | | - assert span.get_tag(http.STATUS_MSG) == str(status_msg) |
504 | | - |
505 | | - if query is not None and int_config.myint.http.trace_query_string: |
506 | | - assert span.get_tag(http.QUERY_STRING) == query |
507 | | - |
508 | | - if request_headers is not None: |
509 | | - for header, value in request_headers.items(): |
510 | | - tag = "http.request.headers." + header |
511 | | - assert span.get_tag(tag) == value |
512 | | - |
513 | | - |
514 | 389 | @mock.patch("ddtrace.internal.settings._config.log") |
515 | 390 | @pytest.mark.parametrize( |
516 | 391 | "error_codes,status_code,error,log_call", |
|
0 commit comments