Deleted
Added
test_return.py (1434:7e6a2071f723) | test_return.py (1435:b7131bfeb438) |
---|---|
1import re 2import unittest 3from unit.applications.proto import TestApplicationProto 4 5 6class TestReturn(TestApplicationProto): 7 prerequisites = {} 8 --- 70 unchanged lines hidden (view full) --- 79 self.assertNotEqual(resp['body'], '') 80 81 self.assertIn('success', self.conf('999', 'routes/0/action/return')) 82 83 resp = self.get() 84 self.assertEqual(resp['status'], 999) 85 self.assertEqual(resp['body'], '') 86 | 1import re 2import unittest 3from unit.applications.proto import TestApplicationProto 4 5 6class TestReturn(TestApplicationProto): 7 prerequisites = {} 8 --- 70 unchanged lines hidden (view full) --- 79 self.assertNotEqual(resp['body'], '') 80 81 self.assertIn('success', self.conf('999', 'routes/0/action/return')) 82 83 resp = self.get() 84 self.assertEqual(resp['status'], 999) 85 self.assertEqual(resp['body'], '') 86 |
87 def test_return_location(self): 88 reserved = ":/?#[]@!$&'()*+,;=" 89 unreserved = ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" 90 "0123456789-._~") 91 unsafe = " \"%<>\\^`{|}" 92 unsafe_enc = "%20%22%25%3C%3E%5C%5E%60%7B%7C%7D" 93 94 def check_location(location, expect=None): 95 if expect is None: 96 expect = location 97 98 self.assertIn( 99 'success', 100 self.conf( 101 {"return": 301, "location": location}, 'routes/0/action' 102 ), 103 'configure location' 104 ) 105 106 self.assertEqual(self.get()['headers']['Location'], expect) 107 108 # FAIL: can't specify empty header value. 109 # check_location("") 110 111 check_location(reserved) 112 113 # After first "?" all other "?" encoded. 114 check_location("/?" + reserved, "/?:/%3F#[]@!$&'()*+,;=") 115 check_location("???", "?%3F%3F") 116 117 # After first "#" all other "?" or "#" encoded. 118 check_location("/#" + reserved, "/#:/%3F%23[]@!$&'()*+,;=") 119 check_location("##?#?", "#%23%3F%23%3F") 120 121 # After first "?" next "#" not encoded. 122 check_location("/?#" + reserved, "/?#:/%3F%23[]@!$&'()*+,;=") 123 check_location("??##", "?%3F#%23") 124 check_location("/?##?", "/?#%23%3F") 125 126 # Unreserved never encoded. 127 check_location(unreserved) 128 check_location("/" + unreserved + "?" + unreserved + "#" + unreserved) 129 130 # Unsafe always encoded. 131 check_location(unsafe, unsafe_enc) 132 check_location("?" + unsafe, "?" + unsafe_enc) 133 check_location("#" + unsafe, "#" + unsafe_enc) 134 135 # %00-%20 and %7F-%FF always encoded. 136 check_location(u"\u0000\u0018\u001F\u0020\u0021", "%00%18%1F%20!") 137 check_location(u"\u007F\u0080н\u20BD", "%7F%C2%80%D0%BD%E2%82%BD") 138 139 # Encoded string detection. If at least one char need to be encoded 140 # then whole string will be encoded. 141 check_location("%20") 142 check_location("/%20?%20#%20") 143 check_location(" %20", "%20%2520") 144 check_location("%20 ", "%2520%20") 145 check_location("/%20?%20#%20 ", "/%2520?%2520#%2520%20") 146 147 def test_return_location_edit(self): 148 self.assertIn( 149 'success', 150 self.conf( 151 {"return": 302, "location": "blah"}, 'routes/0/action' 152 ), 153 'configure init location' 154 ) 155 self.assertEqual(self.get()['headers']['Location'], 'blah') 156 157 self.assertIn( 158 'success', 159 self.conf_delete('routes/0/action/location'), 160 'location delete' 161 ) 162 self.assertNotIn('Location', self.get()['headers']) 163 164 self.assertIn( 165 'success', 166 self.conf('"blah"', 'routes/0/action/location'), 167 'location restore' 168 ) 169 self.assertEqual(self.get()['headers']['Location'], 'blah') 170 171 self.assertIn( 172 'error', 173 self.conf_post('"blah"', 'routes/0/action/location'), 174 'location method not allowed' 175 ) 176 self.assertEqual(self.get()['headers']['Location'], 'blah') 177 |
|
87 def test_return_invalid(self): 88 def check_error(conf): 89 self.assertIn('error', self.conf(conf, 'routes/0/action')) 90 91 check_error({"return": "200"}) 92 check_error({"return": []}) 93 check_error({"return": 80.}) 94 check_error({"return": 1000}) 95 check_error({"return": 200, "share": "/blah"}) 96 97 self.assertIn( 98 'error', self.conf('001', 'routes/0/action/return'), 'leading zero' 99 ) 100 | 178 def test_return_invalid(self): 179 def check_error(conf): 180 self.assertIn('error', self.conf(conf, 'routes/0/action')) 181 182 check_error({"return": "200"}) 183 check_error({"return": []}) 184 check_error({"return": 80.}) 185 check_error({"return": 1000}) 186 check_error({"return": 200, "share": "/blah"}) 187 188 self.assertIn( 189 'error', self.conf('001', 'routes/0/action/return'), 'leading zero' 190 ) 191 |
192 check_error({"return": 301, "location": 0}) 193 check_error({"return": 301, "location": []}) |
|
101 | 194 |
195 |
|
102if __name__ == '__main__': 103 TestReturn.main() | 196if __name__ == '__main__': 197 TestReturn.main() |