Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/curl/tests/http/test_15_tracing.py
2654 views
1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
#***************************************************************************
4
# _ _ ____ _
5
# Project ___| | | | _ \| |
6
# / __| | | | |_) | |
7
# | (__| |_| | _ <| |___
8
# \___|\___/|_| \_\_____|
9
#
10
# Copyright (C) Daniel Stenberg, <[email protected]>, et al.
11
#
12
# This software is licensed as described in the file COPYING, which
13
# you should have received as part of this distribution. The terms
14
# are also available at https://curl.se/docs/copyright.html.
15
#
16
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
# copies of the Software, and permit persons to whom the Software is
18
# furnished to do so, under the terms of the COPYING file.
19
#
20
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
# KIND, either express or implied.
22
#
23
# SPDX-License-Identifier: curl
24
#
25
###########################################################################
26
#
27
import logging
28
import re
29
import pytest
30
31
from testenv import Env
32
from testenv import CurlClient
33
34
35
log = logging.getLogger(__name__)
36
37
38
@pytest.mark.skipif(condition=not Env.curl_is_debug(), reason="needs curl debug")
39
class TestTracing:
40
41
# default verbose output
42
def test_15_01_trace_defaults(self, env: Env, httpd):
43
curl = CurlClient(env=env)
44
url = f'http://{env.domain1}:{env.http_port}/data.json'
45
r = curl.http_get(url=url, def_tracing=False, extra_args=[
46
'-v'
47
])
48
r.check_response(http_status=200)
49
trace = r.trace_lines
50
assert len(trace) > 0
51
52
# trace ids
53
def test_15_02_trace_ids(self, env: Env, httpd):
54
curl = CurlClient(env=env)
55
url = f'http://{env.domain1}:{env.http_port}/data.json'
56
r = curl.http_get(url=url, def_tracing=False, extra_args=[
57
'-v', '--trace-config', 'ids'
58
])
59
r.check_response(http_status=200)
60
for line in r.trace_lines:
61
m = re.match(r'^\[0-[0x]] .+', line)
62
if m is None:
63
assert False, f'no match: {line}'
64
65
# trace ids+time
66
def test_15_03_trace_ids_time(self, env: Env, httpd):
67
curl = CurlClient(env=env)
68
url = f'http://{env.domain1}:{env.http_port}/data.json'
69
r = curl.http_get(url=url, def_tracing=False, extra_args=[
70
'-v', '--trace-config', 'ids,time'
71
])
72
r.check_response(http_status=200)
73
for line in r.trace_lines:
74
m = re.match(r'^([0-9:.]+) \[0-[0x]] .+', line)
75
if m is None:
76
assert False, f'no match: {line}'
77
78
# trace all
79
def test_15_04_trace_all(self, env: Env, httpd):
80
if not env.curl_is_verbose():
81
pytest.skip('only works for curl with verbose strings')
82
curl = CurlClient(env=env)
83
url = f'http://{env.domain1}:{env.http_port}/data.json'
84
r = curl.http_get(url=url, def_tracing=False, extra_args=[
85
'-v', '--trace-config', 'all'
86
])
87
r.check_response(http_status=200)
88
found_tcp = False
89
for line in r.trace_lines:
90
m = re.match(r'^([0-9:.]+) \[0-[0x]] .+', line)
91
if m is None:
92
assert False, f'no match: {line}'
93
m = re.match(r'^([0-9:.]+) \[0-[0x]] .+ \[TCP].+', line)
94
if m is not None:
95
found_tcp = True
96
assert found_tcp, f'TCP filter does not appear in trace "all": {r.stderr}'
97
98
# trace all, no TCP, no time
99
def test_15_05_trace_all(self, env: Env, httpd):
100
curl = CurlClient(env=env)
101
url = f'http://{env.domain1}:{env.http_port}/data.json'
102
r = curl.http_get(url=url, def_tracing=False, extra_args=[
103
'-v', '--trace-config', 'all,-tcp,-time'
104
])
105
r.check_response(http_status=200)
106
found_tcp = False
107
for line in r.trace_lines:
108
m = re.match(r'^\[0-[0x]] .+', line)
109
if m is None:
110
assert False, f'no match: {line}'
111
m = re.match(r'^\[0-[0x]] . \[TCP].+', line)
112
if m is not None:
113
found_tcp = True
114
if found_tcp:
115
assert False, f'TCP filter appears in trace "all,-tcp": {r.stderr}'
116
117