Changeset 1df7f11 in trunk
- Timestamp:
- 2012-10-25T00:01:25Z (13 years ago)
- Branches:
- master
- Children:
- b3bf207
- Parents:
- 05d0b8b
- Location:
- src/allmydata
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/allmydata/test/test_web.py ¶
r05d0b8b r1df7f11 7 7 from twisted.internet import defer, reactor 8 8 from twisted.internet.task import Clock 9 from twisted.web import client, error, http 9 from twisted.web import client, error, http, html 10 10 from twisted.python import failure, log 11 11 12 12 from foolscap.api import fireEventually, flushEventualQueue 13 13 14 from nevow.util import escapeToXML 14 15 from nevow import rend 15 16 … … 257 258 foo.set_uri(u"blockingfile", blocking_uri, blocking_uri) 258 259 260 # filenode to test for html encoding issues 261 self._htmlname_unicode = u"<&weirdly'named\"file>>>_<iframe />.txt" 262 self._htmlname_raw = self._htmlname_unicode.encode('utf-8') 263 self._htmlname_urlencoded = urllib.quote(self._htmlname_raw, '') 264 self._htmlname_escaped = escapeToXML(self._htmlname_raw) 265 self._htmlname_escaped_attr = html.escape(self._htmlname_raw) 266 self._htmlname_escaped_double = escapeToXML(html.escape(self._htmlname_raw)) 267 self.HTMLNAME_CONTENTS, n, self._htmlname_txt_uri = self.makefile(0) 268 foo.set_uri(self._htmlname_unicode, self._htmlname_txt_uri, self._htmlname_txt_uri) 269 259 270 unicode_filename = u"n\u00fc.txt" # n u-umlaut . t x t 260 271 # ok, unicode calls it LATIN SMALL LETTER U WITH DIAERESIS but I … … 281 292 # public/foo/quux.txt 282 293 # public/foo/blockingfile 294 # public/foo/<&weirdly'named\"file>>>_<iframe />.txt 283 295 # public/foo/empty/ 284 296 # public/foo/sub/ … … 366 378 kidnames = sorted([unicode(n) for n in data[1]["children"]]) 367 379 self.failUnlessEqual(kidnames, 368 [ u"bar.txt", u"baz.txt", u"blockingfile",369 u" empty", u"n\u00fc.txt", u"quux.txt", u"sub"])380 [self._htmlname_unicode, u"bar.txt", u"baz.txt", 381 u"blockingfile", u"empty", u"n\u00fc.txt", u"quux.txt", u"sub"]) 370 382 kids = dict( [(unicode(name),value) 371 383 for (name,value) … … 1342 1354 return d 1343 1355 1356 def test_GET_DIRECTORY_html_filenode_encoding(self): 1357 d = self.GET(self.public_url + "/foo", followRedirect=True) 1358 def _check(html): 1359 # Check if encoded entries are there 1360 self.failUnlessIn('@@named=/' + self._htmlname_urlencoded + '">' 1361 + self._htmlname_escaped + '</a>', html) 1362 self.failUnlessIn('value="' + self._htmlname_escaped_attr + '"', html) 1363 self.failIfIn(self._htmlname_escaped_double, html) 1364 # Make sure that Nevow escaping actually works by checking for unsafe characters 1365 # and that '&' is escaped. 1366 for entity in '<>': 1367 self.failUnlessIn(entity, self._htmlname_raw) 1368 self.failIfIn(entity, self._htmlname_escaped) 1369 self.failUnlessIn('&', re.sub(r'&(amp|lt|gt|quot|apos);', '', self._htmlname_raw)) 1370 self.failIfIn('&', re.sub(r'&(amp|lt|gt|quot|apos);', '', self._htmlname_escaped)) 1371 d.addCallback(_check) 1372 return d 1373 1344 1374 def test_GET_root_html(self): 1345 1375 d = self.GET("/") … … 1564 1594 d.addCallback(self.get_operation_results, "127", "json") 1565 1595 def _got_json(stats): 1566 expected = {"count-immutable-files": 3,1596 expected = {"count-immutable-files": 4, 1567 1597 "count-mutable-files": 2, 1568 1598 "count-literal-files": 0, 1569 "count-files": 5,1599 "count-files": 6, 1570 1600 "count-directories": 3, 1571 "size-immutable-files": 57,1601 "size-immutable-files": 76, 1572 1602 "size-literal-files": 0, 1573 1603 #"size-directories": 1912, # varies 1574 1604 #"largest-directory": 1590, 1575 "largest-directory-children": 7,1605 "largest-directory-children": 8, 1576 1606 "largest-immutable-file": 19, 1577 1607 } … … 1581 1611 (k, stats[k], v)) 1582 1612 self.failUnlessReallyEqual(stats["size-files-histogram"], 1583 [ [11, 31, 3] ])1613 [ [11, 31, 4] ]) 1584 1614 d.addCallback(_got_json) 1585 1615 return d … … 1590 1620 self.failUnless(res.endswith("\n")) 1591 1621 units = [simplejson.loads(t) for t in res[:-1].split("\n")] 1592 self.failUnlessReallyEqual(len(units), 9)1622 self.failUnlessReallyEqual(len(units), 10) 1593 1623 self.failUnlessEqual(units[-1]["type"], "stats") 1594 1624 first = units[0] … … 2435 2465 d.addCallback(lambda res: 2436 2466 self.failUnlessNodeKeysAre(self._foo_node, 2437 [u"bar.txt", u"baz.txt", u"blockingfile", 2467 [self._htmlname_unicode, 2468 u"bar.txt", u"baz.txt", u"blockingfile", 2438 2469 u"empty", u"n\u00fc.txt", u"quux.txt", 2439 2470 u"sub"])) … … 2627 2658 def _check_json(data): 2628 2659 self.failUnlessReallyEqual(data["finished"], True) 2629 self.failUnlessReallyEqual(data["count-objects-checked"], 1 0)2630 self.failUnlessReallyEqual(data["count-objects-healthy"], 1 0)2660 self.failUnlessReallyEqual(data["count-objects-checked"], 11) 2661 self.failUnlessReallyEqual(data["count-objects-healthy"], 11) 2631 2662 d.addCallback(_check_json) 2632 2663 d.addCallback(self.get_operation_results, "123", "html") 2633 2664 def _check_html(res): 2634 self.failUnlessIn("Objects Checked: <span>1 0</span>", res)2635 self.failUnlessIn("Objects Healthy: <span>1 0</span>", res)2665 self.failUnlessIn("Objects Checked: <span>11</span>", res) 2666 self.failUnlessIn("Objects Healthy: <span>11</span>", res) 2636 2667 self.failUnlessIn(FAVICON_MARKUP, res) 2637 2668 d.addCallback(_check_html) … … 2663 2694 def _check_json(data): 2664 2695 self.failUnlessReallyEqual(data["finished"], True) 2665 self.failUnlessReallyEqual(data["count-objects-checked"], 1 0)2666 self.failUnlessReallyEqual(data["count-objects-healthy-pre-repair"], 1 0)2696 self.failUnlessReallyEqual(data["count-objects-checked"], 11) 2697 self.failUnlessReallyEqual(data["count-objects-healthy-pre-repair"], 11) 2667 2698 self.failUnlessReallyEqual(data["count-objects-unhealthy-pre-repair"], 0) 2668 2699 self.failUnlessReallyEqual(data["count-corrupt-shares-pre-repair"], 0) … … 2670 2701 self.failUnlessReallyEqual(data["count-repairs-successful"], 0) 2671 2702 self.failUnlessReallyEqual(data["count-repairs-unsuccessful"], 0) 2672 self.failUnlessReallyEqual(data["count-objects-healthy-post-repair"], 1 0)2703 self.failUnlessReallyEqual(data["count-objects-healthy-post-repair"], 11) 2673 2704 self.failUnlessReallyEqual(data["count-objects-unhealthy-post-repair"], 0) 2674 2705 self.failUnlessReallyEqual(data["count-corrupt-shares-post-repair"], 0) … … 2676 2707 d.addCallback(self.get_operation_results, "124", "html") 2677 2708 def _check_html(res): 2678 self.failUnlessIn("Objects Checked: <span>1 0</span>", res)2679 2680 self.failUnlessIn("Objects Healthy (before repair): <span>1 0</span>", res)2709 self.failUnlessIn("Objects Checked: <span>11</span>", res) 2710 2711 self.failUnlessIn("Objects Healthy (before repair): <span>11</span>", res) 2681 2712 self.failUnlessIn("Objects Unhealthy (before repair): <span>0</span>", res) 2682 2713 self.failUnlessIn("Corrupt Shares (before repair): <span>0</span>", res) … … 2686 2717 self.failUnlessIn("Repairs Unsuccessful: <span>0</span>", res) 2687 2718 2688 self.failUnlessIn("Objects Healthy (after repair): <span>1 0</span>", res)2719 self.failUnlessIn("Objects Healthy (after repair): <span>11</span>", res) 2689 2720 self.failUnlessIn("Objects Unhealthy (after repair): <span>0</span>", res) 2690 2721 self.failUnlessIn("Corrupt Shares (after repair): <span>0</span>", res) … … 3679 3710 3680 3711 def test_PUT_NEWFILEURL_bad_format(self): 3681 new_contents = self.NEWFILE_CONTENTS * 3000003682 return self.shouldHTTPError("PUT_NEWFILEURL_bad_format",3683 400, "Bad Request", "Unknown format: foo",3684 self.PUT, self.public_url + \3685 "/foo/foo.txt?format=foo",3686 new_contents)3712 new_contents = self.NEWFILE_CONTENTS * 300000 3713 return self.shouldHTTPError("PUT_NEWFILEURL_bad_format", 3714 400, "Bad Request", "Unknown format: foo", 3715 self.PUT, self.public_url + \ 3716 "/foo/foo.txt?format=foo", 3717 new_contents) 3687 3718 3688 3719 def test_PUT_NEWFILEURL_uri_replace(self): -
TabularUnified src/allmydata/web/directory.py ¶
r05d0b8b r1df7f11 7 7 from twisted.internet.interfaces import IPushProducer 8 8 from twisted.python.failure import Failure 9 from twisted.web import http , html9 from twisted.web import http 10 10 from nevow import url, rend, inevow, tags as T 11 11 from nevow.inevow import IRequest … … 751 751 dlurl = "%s/file/%s/@@named=/%s" % (root, quoted_uri, nameurl) 752 752 753 ctx.fillSlots("filename", 754 T.a(href=dlurl)[html.escape(name)]) 753 ctx.fillSlots("filename", T.a(href=dlurl)[name]) 755 754 ctx.fillSlots("type", "SSK") 756 755 … … 762 761 dlurl = "%s/file/%s/@@named=/%s" % (root, quoted_uri, nameurl) 763 762 764 ctx.fillSlots("filename", 765 T.a(href=dlurl)[html.escape(name)]) 763 ctx.fillSlots("filename", T.a(href=dlurl)[name]) 766 764 ctx.fillSlots("type", "FILE") 767 765 … … 773 771 # directory 774 772 uri_link = "%s/uri/%s/" % (root, urllib.quote(target_uri)) 775 ctx.fillSlots("filename", 776 T.a(href=uri_link)[html.escape(name)]) 773 ctx.fillSlots("filename", T.a(href=uri_link)[name]) 777 774 if not target.is_mutable(): 778 775 dirtype = "DIR-IMM" … … 798 795 else: 799 796 # unknown 800 ctx.fillSlots("filename", html.escape(name))797 ctx.fillSlots("filename", name) 801 798 if target.get_write_uri() is not None: 802 799 unknowntype = "?"
Note: See TracChangeset
for help on using the changeset viewer.