예제 #1
0
 def test_prevent_control_characters_in_headers(self):
     apis = 'append', 'replace', '__setitem__', 'setdefault'
     masks = '{}test', 'test{}', 'te{}st'
     tests = '\n', '\r', '\n\r', '\0'
     for api, mask, test in itertools.product(apis, masks, tests):
         hd = bottle.HeaderDict()
         func = getattr(hd, api)
         value = mask.replace("{}", test)
         self.assertRaises(ValueError, func, value, "test-value")
         self.assertRaises(ValueError, func, "test-name", value)
예제 #2
0
    def test_prevent_control_characters_in_headers(self):
        masks = '{}test', 'test{}', 'te{}st'
        tests = '\n', '\r', '\n\r', '\0'

        # Test HeaderDict
        apis = 'append', 'replace', '__setitem__', 'setdefault'
        for api, mask, test in product(apis, masks, tests):
            hd = bottle.HeaderDict()
            func = getattr(hd, api)
            value = mask.replace("{}", test)
            self.assertRaises(ValueError, func, value, "test-value")
            self.assertRaises(ValueError, func, "test-name", value)

        # Test functions on BaseResponse
        apis = 'add_header', 'set_header', '__setitem__'
        for api, mask, test in product(apis, masks, tests):
            rs = bottle.BaseResponse()
            func = getattr(rs, api)
            value = mask.replace("{}", test)
            self.assertRaises(ValueError, func, value, "test-value")
            self.assertRaises(ValueError, func, "test-name", value)