|
14 | 14 | from datetime import datetime |
15 | 15 | import io |
16 | 16 | import os.path |
17 | | -import textwrap |
18 | 17 | import unittest |
19 | 18 |
|
20 | 19 | from trac import perm |
@@ -533,21 +532,21 @@ def test_non_strict_qs(self): |
533 | 532 |
|
534 | 533 | def test_post_with_unnamed_value(self): |
535 | 534 | boundary = '_BOUNDARY_' |
536 | | - form_data = textwrap.dedent("""\ |
537 | | - --%(boundary)s\r\n\ |
538 | | - Content-Disposition: form-data; name="foo"\r\n\ |
539 | | - \r\n\ |
540 | | - named value\r\n\ |
541 | | - --%(boundary)s\r\n\ |
542 | | - Content-Disposition: form-data; name=""\r\n\ |
543 | | - \r\n\ |
544 | | - name is empty\r\n\ |
545 | | - --%(boundary)s\r\n\ |
546 | | - Content-Disposition: form-data\r\n\ |
547 | | - \r\n\ |
548 | | - unnamed value\r\n\ |
549 | | - --%(boundary)s--\r\n\ |
550 | | - """) |
| 535 | + form_data = ( |
| 536 | + '--%(boundary)s\r\n' |
| 537 | + 'Content-Disposition: form-data; name="foo"\r\n' |
| 538 | + '\r\n' |
| 539 | + 'named value\r\n' |
| 540 | + '--%(boundary)s\r\n' |
| 541 | + 'Content-Disposition: form-data; name=""\r\n' |
| 542 | + '\r\n' |
| 543 | + 'name is empty\r\n' |
| 544 | + '--%(boundary)s\r\n' |
| 545 | + 'Content-Disposition: form-data\r\n' |
| 546 | + '\r\n' |
| 547 | + 'unnamed value\r\n' |
| 548 | + '--%(boundary)s--\r\n' |
| 549 | + ) |
551 | 550 | form_data = (form_data % {'boundary': boundary}).encode('utf-8') |
552 | 551 | content_type = 'multipart/form-data; boundary="%s"' % boundary |
553 | 552 | environ = _make_environ(method='POST', **{ |
@@ -584,39 +583,39 @@ def _test_post_with_null_bytes(self, form_data): |
584 | 583 | self.fail("HTTPBadRequest not raised.") |
585 | 584 |
|
586 | 585 | def test_post_with_null_bytes_for_filename(self): |
587 | | - form_data = textwrap.dedent("""\ |
588 | | - --%(boundary)s\r\n\ |
589 | | - Content-Disposition: form-data; name="attachment"; \ |
590 | | - filename="thefi\x00le.txt"\r\n\ |
591 | | - Content-Type: text/plain\r\n\ |
592 | | - \r\n\ |
593 | | - The file content.\r\n\ |
594 | | - --%(boundary)s\r\n\ |
595 | | - Content-Disposition: form-data; name="action"\r\n\ |
596 | | - \r\n\ |
597 | | - new\r\n\ |
598 | | - --%(boundary)s--\r\n\ |
599 | | - """) |
| 586 | + form_data = ( |
| 587 | + '--%(boundary)s\r\n' |
| 588 | + 'Content-Disposition: form-data; name="attachment"; ' |
| 589 | + 'filename="thefi\x00le.txt"\r\n' |
| 590 | + 'Content-Type: text/plain\r\n' |
| 591 | + '\r\n' |
| 592 | + 'The file content.\r\n' |
| 593 | + '--%(boundary)s\r\n' |
| 594 | + 'Content-Disposition: form-data; name="action"\r\n' |
| 595 | + '\r\n' |
| 596 | + 'new\r\n' |
| 597 | + '--%(boundary)s--\r\n' |
| 598 | + ) |
600 | 599 | self._test_post_with_null_bytes(form_data) |
601 | 600 |
|
602 | 601 | def test_post_with_null_bytes_for_name(self): |
603 | | - form_data = textwrap.dedent("""\ |
604 | | - --%(boundary)s\r\n\ |
605 | | - Content-Disposition: form-data; name="acti\x00n"\r\n\ |
606 | | - \r\n\ |
607 | | - new\r\n\ |
608 | | - --%(boundary)s--\r\n\ |
609 | | - """) |
| 602 | + form_data = ( |
| 603 | + '--%(boundary)s\r\n' |
| 604 | + 'Content-Disposition: form-data; name="acti\x00n"\r\n' |
| 605 | + '\r\n' |
| 606 | + 'new\r\n' |
| 607 | + '--%(boundary)s--\r\n' |
| 608 | + ) |
610 | 609 | self._test_post_with_null_bytes(form_data) |
611 | 610 |
|
612 | 611 | def test_post_with_null_bytes_for_value(self): |
613 | | - form_data = textwrap.dedent("""\ |
614 | | - --%(boundary)s\r\n\ |
615 | | - Content-Disposition: form-data; name="action"\r\n\ |
616 | | - \r\n\ |
617 | | - ne\x00w\r\n\ |
618 | | - --%(boundary)s--\r\n\ |
619 | | - """) |
| 612 | + form_data = ( |
| 613 | + '--%(boundary)s\r\n' |
| 614 | + 'Content-Disposition: form-data; name="action"\r\n' |
| 615 | + '\r\n' |
| 616 | + 'ne\x00w\r\n' |
| 617 | + '--%(boundary)s--\r\n' |
| 618 | + ) |
620 | 619 | self._test_post_with_null_bytes(form_data) |
621 | 620 |
|
622 | 621 | def test_qs_on_post(self): |
|
0 commit comments