comparison test/rest_common.py @ 6509:1fc765ef6379

Fix 204 responses, hangs and crashes with REST. Remove Content-Type and make sure no content is returned by OPTIONS request in REST interface. In write_html set the Content-Length when response is not encoded/compressed (fixes hang due to missing content-length with unencoded data). In REST interface do not raise UsageError for invalid api version. Return json error with proper message. Fixes crash.
author John Rouillard <rouilj@ieee.org>
date Sat, 16 Oct 2021 13:34:04 -0400
parents f2c31f5ec50b
children b54bb529d701
comparison
equal deleted inserted replaced
6507:bc95f7431efb 6509:1fc765ef6379
2270 # application/json is selected with invalid version 2270 # application/json is selected with invalid version
2271 self.server.client.request.headers.get=self.get_header 2271 self.server.client.request.headers.get=self.get_header
2272 headers={"accept": "application/json; version=99" 2272 headers={"accept": "application/json; version=99"
2273 } 2273 }
2274 self.headers=headers 2274 self.headers=headers
2275 with self.assertRaises(UsageError) as ctx: 2275 results = self.server.dispatch('GET',
2276 results = self.server.dispatch('GET', 2276 "/rest/data/status/1",
2277 "/rest/data/status/1", 2277 self.empty_form)
2278 self.empty_form)
2279 print(results) 2278 print(results)
2280 self.assertEqual(self.server.client.response_code, 200) 2279 json_dict = json.loads(b2s(results))
2281 self.assertEqual(ctx.exception.args[0], 2280 self.assertEqual(self.server.client.response_code, 400)
2281 self.assertEqual(self.server.client.additional_headers['Content-Type'],
2282 "application/json")
2283 self.assertEqual(json_dict['error']['msg'],
2282 "Unrecognized version: 99. See /rest without " 2284 "Unrecognized version: 99. See /rest without "
2283 "specifying version for supported versions.") 2285 "specifying version for supported versions.")
2284 2286
2285 def testMethodOverride(self): 2287 def testMethodOverride(self):
2286 # TEST #1 2288 # TEST #1

Roundup Issue Tracker: http://roundup-tracker.org/