-
Notifications
You must be signed in to change notification settings - Fork 41
/
test_path_encoding.py
121 lines (91 loc) · 3.32 KB
/
test_path_encoding.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# coding=utf-8
import unittest
from six.moves import urllib
from bugsnag.notification import Notification
from bugsnag.configuration import (Configuration, RequestConfiguration)
class PathEncodingTest(unittest.TestCase):
environ = {
'SCRIPT_NAME': '',
'SERVER_NAME': 'localhost',
'SERVER_PORT': '80',
'wsgi.url_scheme': 'http',
}
def test_path_supports_ascii_characters(self):
import bugsnag.wsgi.middleware
environ = self.environ.copy()
environ['PATH_INFO'] = '/hello/world'
bugsnag.configure_request(wsgi_environ=environ)
config = Configuration()
notification = Notification(
Exception("oops"),
config,
RequestConfiguration.get_instance()
)
bugsnag.wsgi.middleware.add_wsgi_request_data_to_notification(
notification
)
self.assertEqual(
'http://localhost/hello/world',
notification.meta_data['request']['url']
)
def test_wrongly_encoded_url_should_not_raise(self):
import bugsnag.wsgi.middleware
environ = self.environ.copy()
environ['PATH_INFO'] = '/%83'
bugsnag.configure_request(wsgi_environ=environ)
config = Configuration()
notification = Notification(
Exception("oops"),
config,
RequestConfiguration.get_instance()
)
bugsnag.wsgi.middleware.add_wsgi_request_data_to_notification(
notification
)
# We have to use "urllib.parse.quote" here because the exact output
# differs on different Python versions because of how they handle
# invalid encoding sequences
self.assertEqual(
'http://localhost/%s' % urllib.parse.quote('%83'),
notification.meta_data['request']['url']
)
def test_path_supports_emoji(self):
import bugsnag.wsgi.middleware
environ = self.environ.copy()
environ['PATH_INFO'] = '/😇'
config = Configuration()
notification = Notification(
Exception("oops"),
config,
RequestConfiguration.get_instance()
)
bugsnag.configure_request(wsgi_environ=environ)
bugsnag.wsgi.middleware.add_wsgi_request_data_to_notification(
notification
)
# You can validate this by using "encodeURIComponent" in a browser.
self.assertEqual(
'http://localhost/%F0%9F%98%87',
notification.meta_data['request']['url']
)
def test_path_supports_non_ascii_characters(self):
import bugsnag.wsgi.middleware
environ = self.environ.copy()
environ['PATH_INFO'] = '/ôßłガ'
config = Configuration()
notification = Notification(
Exception("oops"),
config,
RequestConfiguration.get_instance()
)
bugsnag.configure_request(wsgi_environ=environ)
bugsnag.wsgi.middleware.add_wsgi_request_data_to_notification(
notification
)
# You can validate this by using "encodeURIComponent" in a browser.
self.assertEqual(
'http://localhost/%C3%B4%C3%9F%C5%82%E3%82%AC',
notification.meta_data['request']['url']
)
if __name__ == '__main__':
unittest.main()