1
1
import json
2
2
import logging
3
3
import urllib
4
+ import urllib .parse
4
5
5
6
import mock
6
7
import pytest
63
64
"/content/dist/rhel/server/7/7.9/file.ext" ,
64
65
"text/plain" ,
65
66
),
67
+ (
68
+ # encoded URI should be decoded
69
+ "/content/dist/rhel/rhui/server/7/7Server/some%5Efile" ,
70
+ "/content/dist/rhel/server/7/7.9/some^file" ,
71
+ "text/plain" ,
72
+ ),
73
+ (
74
+ # but it is also OK to not encode that character
75
+ "/content/dist/rhel/rhui/server/7/7Server/some^file" ,
76
+ "/content/dist/rhel/server/7/7.9/some^file" ,
77
+ "text/plain" ,
78
+ ),
79
+ (
80
+ # this tricky case is trying to ensure that, even for "special"
81
+ # paths like /listing, if the client encodes parts of the URI it
82
+ # still all works normally.
83
+ "/content/dist/rhel/rhui/server/7/li%73ting" ,
84
+ "/content/dist/rhel/rhui/server/7/listing" ,
85
+ "text/plain" ,
86
+ ),
66
87
],
67
88
ids = [
68
89
"/origin/rpm/" ,
74
95
"no alias keywords" ,
75
96
"releasever alias" ,
76
97
"layered rhui, releasever alias" ,
98
+ "encoded URI" ,
99
+ "reserved char no encoding" ,
100
+ "encoded listing" ,
77
101
],
78
102
)
79
103
@mock .patch ("boto3.client" )
@@ -110,7 +134,9 @@ def test_origin_request(
110
134
111
135
assert "Incoming request value for origin_request" in caplog .text
112
136
113
- if req_uri .endswith ("/listing" ):
137
+ req_uri_decoded = urllib .parse .unquote (req_uri )
138
+
139
+ if req_uri_decoded .endswith ("/listing" ):
114
140
assert "Handling listing request" in caplog .text
115
141
assert "Generated listing request response" in caplog .text
116
142
assert request ["body" ]
@@ -123,7 +149,7 @@ def test_origin_request(
123
149
),
124
150
"headers" : {
125
151
"exodus-original-uri" : [
126
- {"key" : "exodus-original-uri" , "value" : req_uri }
152
+ {"key" : "exodus-original-uri" , "value" : req_uri_decoded }
127
153
]
128
154
},
129
155
}
0 commit comments