Skip to content

Commit ecf62e6

Browse files
committed
adding test case for home templates in various incantations. Also added comment about possibly creating/raising PageTraversal exception. I don't think we need it since @@file doesn't do it but...
1 parent 1f1e211 commit ecf62e6

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/test_cgi.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,21 @@ def testTemplateSubdirectory(self):
11391139
# note that the extension is not included just the basename
11401140
self.assertEqual("user.item", t.selectTemplate("user", "item"))
11411141

1142+
1143+
# make sure home templates work
1144+
self.assertEqual("home", t.selectTemplate(None, ""))
1145+
self.assertEqual("home.classlist", t.selectTemplate(None, "classlist"))
1146+
1147+
# home.item doesn't exist should return _generic.item.
1148+
self.assertEqual("_generic.item", t.selectTemplate(None, "item"))
1149+
1150+
# test case where there is no view so generic template can't
1151+
# be determined.
1152+
with self.assertRaises(NoTemplate) as cm:
1153+
t.selectTemplate("user", "")
1154+
self.assertEqual(cm.exception.message,
1155+
'''Template "user" doesn't exist''')
1156+
11421157
# there is no html/subdir/user.item.{,xml,html} so it will
11431158
# raise NoTemplate.
11441159
self.assertRaises(NoTemplate,
@@ -1151,6 +1166,9 @@ def testTemplateSubdirectory(self):
11511166
# there is a self.directory + /html/subdir/user.item.html file,
11521167
# but it is a link to self.dir /user.item.html which is outside
11531168
# the html subdir so is rejected by the path traversal check.
1169+
# Prefer NoTemplate here, or should the code be changed to
1170+
# report a new PathTraversal exception? Could the PathTraversal
1171+
# exception leak useful info to an attacker??
11541172
self.assertRaises(NoTemplate,
11551173
t.selectTemplate, "user", "subdir/item")
11561174

0 commit comments

Comments
 (0)