File tree Expand file tree Collapse file tree 3 files changed +28
-5
lines changed Expand file tree Collapse file tree 3 files changed +28
-5
lines changed Original file line number Diff line number Diff line change 14
14
15
15
first_cap_re = re .compile ('(.)([A-Z][a-z]+)' )
16
16
all_cap_re = re .compile ('([a-z0-9])([A-Z])' )
17
+ UNKNOWN_HOSTNAME = "UNKNOWN HOST"
17
18
18
19
19
20
def inject_trace_header (headers , entity ):
@@ -126,9 +127,11 @@ def strip_url(url):
126
127
127
128
def get_hostname (url ):
128
129
if url is None :
129
- return None
130
+ return UNKNOWN_HOSTNAME
130
131
url_parse = urlparse (url )
131
132
hostname = url_parse .hostname
133
+ if hostname is None :
134
+ return UNKNOWN_HOSTNAME
132
135
return hostname if hostname else url # If hostname is none, we return the regular URL; indication of malformed url
133
136
134
137
Original file line number Diff line number Diff line change @@ -84,7 +84,7 @@ def test_fault():
84
84
assert http_meta ['response' ]['status' ] == status_code
85
85
86
86
87
- def test_invalid_url ():
87
+ def test_nonexistent_domain ():
88
88
try :
89
89
requests .get ('http://doesnt.exist' )
90
90
except Exception :
@@ -97,6 +97,24 @@ def test_invalid_url():
97
97
assert exception .type == 'ConnectionError'
98
98
99
99
100
+ def test_invalid_url ():
101
+ url = 'KLSDFJKLSDFJKLSDJF'
102
+ try :
103
+ requests .get (url )
104
+ except Exception :
105
+ # prevent uncatch exception from breaking test run
106
+ pass
107
+ subsegment = xray_recorder .current_segment ().subsegments [0 ]
108
+ assert subsegment .name == get_hostname (url )
109
+ assert subsegment .fault
110
+
111
+ http_meta = subsegment .http
112
+ assert http_meta ['request' ]['url' ] == strip_url (url )
113
+
114
+ exception = subsegment .cause ['exceptions' ][0 ]
115
+ assert exception .type == 'MissingSchema'
116
+
117
+
100
118
def test_name_uses_hostname ():
101
119
url1 = 'http://{}/fakepath/stuff/koo/lai/ahh' .format (BASE_URL )
102
120
requests .get (url1 )
Original file line number Diff line number Diff line change 1
1
from aws_xray_sdk .ext .util import to_snake_case , get_hostname , strip_url
2
2
3
+ UNKNOWN_HOST = "UNKNOWN HOST"
4
+
3
5
4
6
def test_to_snake_case ():
5
7
s1 = to_snake_case ('Bucket' )
@@ -29,13 +31,13 @@ def test_get_hostname():
29
31
assert s4 == "amazon.com"
30
32
31
33
s5 = get_hostname ("INVALID_URL" )
32
- assert s5 == "INVALID_URL"
34
+ assert s5 == UNKNOWN_HOST
33
35
34
36
s6 = get_hostname ("" )
35
- assert s6 == ""
37
+ assert s6 == UNKNOWN_HOST
36
38
37
39
s7 = get_hostname (None )
38
- assert not s7
40
+ assert s7 == UNKNOWN_HOST
39
41
40
42
41
43
def test_strip_url ():
You can’t perform that action at this time.
0 commit comments