-
Notifications
You must be signed in to change notification settings - Fork 4
/
fuzzers.py
413 lines (300 loc) · 7.98 KB
/
fuzzers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
from django.core.exceptions import (
ValidationError,
SuspiciousFileOperation,
)
from django.utils import text
from django.utils.http import (
base36_to_int,
escape_leading_slashes,
int_to_base36,
url_has_allowed_host_and_scheme,
parse_etags,
parse_http_date,
quote_etag,
urlencode,
urlsafe_base64_decode,
urlsafe_base64_encode,
)
from django.utils.html import (
conditional_escape,
escape,
escapejs,
# format_html,
# html_safe,
json_script,
linebreaks,
smart_urlquote,
strip_spaces_between_tags,
strip_tags,
urlize,
)
from django.utils.ipv6 import clean_ipv6_address, is_valid_ipv6_address
import datetime
from django.utils import feedgenerator
from django.utils.encoding import (
DjangoUnicodeDecodeError,
escape_uri_path,
filepath_to_uri,
iri_to_uri,
smart_str,
uri_to_iri,
)
from django import forms
from django.conf import settings
import django
settings.configure()
django.setup()
def test_base36_to_int(inp):
try:
base36_to_int(inp)
except ValueError:
pass
def test_int_to_base64(inp):
try:
int_to_base36(inp)
except ValueError:
pass
def test_escape_leading_slashes(inp):
escape_leading_slashes(inp)
def test_url_has_allowed_host_and_scheme(inp):
url_has_allowed_host_and_scheme(inp, allowed_hosts={"a", "b"})
def test_parse_etags(inp):
parse_etags(inp)
def test_parse_http_date(inp):
try:
parse_http_date(inp)
except ValueError as e:
msg = str(e)
if (
"is not a valid date" not in msg
and "is not in a valid HTTP date format" not in msg
):
raise
def test_quote_etag(inp):
quote_etag(inp)
def test_urlencode(inp):
urlencode(inp)
def test_urlsafe_base64_decode(inp):
try:
urlsafe_base64_decode(inp)
except ValueError as e:
msg = str(e)
if (
"Invalid base64-encoded string" not in msg
and "Incorrect padding" not in msg
):
raise
def test_urlsafe_base64_encode(inp):
urlsafe_base64_encode(inp)
def test_conditional_escape(inp):
conditional_escape(inp)
def test_escape(inp):
escape(inp)
def test_escapejs(inp):
escapejs(inp)
def test_json_script(inp):
json_script(inp, "id")
def test_linebreaks(inp):
linebreaks(inp)
def test_smart_urlquote(inp):
smart_urlquote(inp)
def test_strip_spaces_between_tags(inp):
strip_spaces_between_tags(inp)
def test_strip_tags(inp):
try:
strip_tags(inp)
except NotImplementedError: # TODO: this should be fixed
pass
def test_urlize(inp):
urlize(inp)
def test_smart_split(inp):
text.smart_split(inp)
def test_Truncator(inp):
text.Truncator(inp).words(8, "...", html=True)
def test_wrap(inp):
text.wrap(inp, 8)
def test_normalize_newlines(inp):
text.normalize_newlines(inp)
def test_phone(inp):
text.phone2numeric(inp)
def test_unescape_string_literal(inp):
try:
text.unescape_string_literal(inp)
except ValueError as e:
if "Not a string literal: " not in str(e):
raise
def test_get_valid_filename(inp):
try:
text.get_valid_filename(inp)
except SuspiciousFileOperation:
pass
def test_is_valid_ipv6_address(inp):
is_valid_ipv6_address(inp)
def test_clean_ipv6_address(inp):
try:
clean_ipv6_address(inp)
except ValidationError:
pass
def test_slugify(inp):
text.slugify(inp)
def test_camel_case_to_spaces(inp):
text.camel_case_to_spaces(inp)
def test_get_tag_uri(inp):
try:
feedgenerator.get_tag_uri(inp, datetime.date(2004, 10, 25))
except ValueError: # TODO: Is this a wanted exception?
pass
def test_Atom1Feed(inp):
feedgenerator.Atom1Feed(inp, "link", "description")
def test_Rss201rev2Feed(inp):
feedgenerator.Rss201rev2Feed(inp, "link", "description")
def test_escape_uri_path(inp):
escape_uri_path(inp)
def test_filepath_to_uri(inp):
filepath_to_uri(inp)
def test_iri_to_uri(inp):
iri_to_uri(inp)
def test_uri_to_iri(inp):
uri_to_iri(inp)
def test_smart_str(inp):
try:
smart_str(inp)
except DjangoUnicodeDecodeError:
pass
def test_forms_BooleanField(inp):
try:
forms.BooleanField().clean(inp)
except ValidationError:
pass
def test_forms_NullBooleanField(inp):
try:
forms.NullBooleanField().clean(inp)
except ValidationError:
pass
def test_forms_CharField(inp):
try:
forms.CharField().clean(inp)
except ValidationError:
pass
def test_forms_DateField(inp):
try:
forms.DateField().clean(inp)
except ValidationError:
pass
def test_forms_DateTimeField(inp):
try:
forms.DateTimeField().clean(inp)
except ValidationError:
pass
def test_forms_DecimalField(inp):
try:
forms.DecimalField().clean(inp)
except ValidationError:
pass
def test_forms_DurationField(inp):
try:
forms.DurationField().clean(inp)
except ValidationError:
pass
def test_forms_EmailField(inp):
try:
forms.EmailField().clean(inp)
except ValidationError:
pass
def test_forms_Field(inp):
try:
forms.Field().clean(inp)
except ValidationError:
pass
def test_forms_FloatField(inp):
try:
forms.FloatField().clean(inp)
except ValidationError:
pass
def test_forms_GenericIPAddressField(inp):
try:
forms.GenericIPAddressField().clean(inp)
except ValidationError:
pass
def test_forms_IntegerField(inp):
try:
forms.IntegerField().clean(inp)
except ValidationError:
pass
def test_forms_SlugField(inp):
try:
forms.SlugField().clean(inp)
except ValidationError:
pass
def test_forms_TimeField(inp):
try:
forms.TimeField().clean(inp)
except ValidationError:
pass
def test_forms_URLField(inp):
try:
forms.URLField().clean(inp)
except ValidationError:
pass
def test_forms_UUIDField(inp):
try:
forms.UUIDField().clean(inp)
except ValidationError:
pass
tests = [
(test_base36_to_int, str),
(test_int_to_base64, int),
(test_escape_leading_slashes, str),
(test_url_has_allowed_host_and_scheme, str),
(test_parse_etags, str),
(test_parse_http_date, str),
(test_quote_etag, str),
# (test_urlencode, str), # TODO: Doesn't actually take a string
(test_urlsafe_base64_decode, str),
(test_urlsafe_base64_encode, bytes),
(test_conditional_escape, str),
(test_escape, str),
(test_escapejs, str),
(test_json_script, str),
(test_linebreaks, str),
(test_smart_urlquote, str),
(test_strip_spaces_between_tags, str),
(test_strip_tags, str),
(test_urlize, str),
(test_smart_split, str),
(test_Truncator, str),
(test_wrap, str),
(test_normalize_newlines, str),
(test_phone, str),
(test_unescape_string_literal, str),
(test_get_valid_filename, str),
(test_is_valid_ipv6_address, str),
(test_clean_ipv6_address, str),
(test_slugify, str),
(test_camel_case_to_spaces, str),
(test_get_tag_uri, str),
(test_Atom1Feed, str),
(test_Rss201rev2Feed, str),
(test_escape_uri_path, str),
(test_filepath_to_uri, str),
(test_iri_to_uri, str),
(test_uri_to_iri, str),
(test_smart_str, bytes),
(test_forms_BooleanField, str),
(test_forms_NullBooleanField, str),
(test_forms_CharField, str),
(test_forms_DateField, str),
(test_forms_DateTimeField, str),
(test_forms_DecimalField, str),
(test_forms_DurationField, str),
(test_forms_EmailField, str),
(test_forms_Field, str),
(test_forms_FloatField, str),
(test_forms_GenericIPAddressField, str),
(test_forms_IntegerField, str),
(test_forms_NullBooleanField, str),
(test_forms_SlugField, str),
(test_forms_TimeField, str),
(test_forms_URLField, str),
(test_forms_UUIDField, str),
]