def test_json_sanitization_with_array(self): json_with_array = { "name": "name", "algorithm": "AES", "payload_content_type": "text/plain", "mode": "CBC", "bit_length": 256, "payload": "not-encrypted", "an-array": [{ "name": " item 1" }, { "name": "item2 " }] } self.assertTrue(json_with_array['an-array'][0]['name'].startswith(' '), "whitespace should be there") self.assertTrue(json_with_array['an-array'][1]['name'].endswith(' '), "whitespace should be there") api.strip_whitespace(json_with_array) self.assertFalse( json_with_array['an-array'][0]['name'].startswith(' '), "whitespace should be gone") self.assertFalse(json_with_array['an-array'][1]['name'].endswith(' '), "whitespace should be gone")
def test_json_sanitization_without_array(self): json_without_array = {"name": "name", "algorithm": "AES", "payload_content_type": " text/plain ", "mode": "CBC", "bit_length": 256, "payload": "not-encrypted"} self.assertTrue(json_without_array['payload_content_type'] .startswith(' '), "whitespace should be there") self.assertTrue(json_without_array['payload_content_type'] .endswith(' '), "whitespace should be there") api.strip_whitespace(json_without_array) self.assertFalse(json_without_array['payload_content_type'] .startswith(' '), "whitespace should be gone") self.assertFalse(json_without_array['payload_content_type'] .endswith(' '), "whitespace should be gone")
def test_json_sanitization_with_array(self): json_with_array = { "name": "name", "algorithm": "AES", "payload_content_type": "text/plain", "mode": "CBC", "bit_length": 256, "payload": "not-encrypted", "an-array": [{"name": " item 1"}, {"name": "item2 "}], } self.assertTrue(json_with_array["an-array"][0]["name"].startswith(" "), "whitespace should be there") self.assertTrue(json_with_array["an-array"][1]["name"].endswith(" "), "whitespace should be there") api.strip_whitespace(json_with_array) self.assertFalse(json_with_array["an-array"][0]["name"].startswith(" "), "whitespace should be gone") self.assertFalse(json_with_array["an-array"][1]["name"].endswith(" "), "whitespace should be gone")