Mercurial > p > roundup > code
diff test/test_cgi.py @ 8320:b07165add61b
fix(web): issue2551406 - dont crash when handed invalid @template=a|b|c
Only two template cases (ok and error) are handled. Presence of second
'|' caused crash. Discovered/patch provided by Christof Meerwald
(cmeerw).
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Mon, 02 Jun 2025 08:52:39 -0400 |
| parents | 669dfccca898 |
| children | 224ccb8b49ca |
line wrap: on
line diff
--- a/test/test_cgi.py Sun May 11 20:31:16 2025 -0400 +++ b/test/test_cgi.py Mon Jun 02 08:52:39 2025 -0400 @@ -2941,6 +2941,39 @@ sha1sum = '<!-- SHA: 952568414163cd12b2e89e91e59ef336da64fbbe -->' self.assertNotEqual(-1, result.index(sha1sum)) + def testRenderAltTemplatesError(self): + # check that an error is reported to user when rendering using + # @template=oktempl|errortmpl|oops|foo + + # template names can not include | + + # set up the client; + # run determine_context to set the required client attributes + # run renderContext(); check result for proper page + + # Test ok state template that uses user.forgotten.html + self.client.form=db_test_base.makeForm({"@template": "forgotten|item|oops|foo"}) + self.client.path = 'user' + self.client.determine_context() + self.client.session_api = MockNull(_sid="1234567890") + self.assertEqual( + (self.client.classname, self.client.template, self.client.nodeid), + ('user', 'forgotten|item|oops|foo', None)) + self.assertEqual(self.client._ok_message, []) + + result = self.client.renderContext() + print(result) + # sha1sum of classic tracker user.forgotten.template must be found + sha1sum = '<!-- SHA: f93570f95f861da40f9c45bbd2b049bb3a7c0fc5 -->' + self.assertNotEqual(-1, result.index(sha1sum)) + + # now set an error in the form to get error template user.item.html + self.client.form=db_test_base.makeForm({"@template": "forgotten|item|oops|foo", + "@error_message": "this is an error"}) + self.client.path = 'user' + self.client.determine_context() + result = self.client.renderContext() + self.assertEqual(result, '<strong>No template file exists for templating "user" with template "item|oops|foo" (neither "user.item|oops|foo" nor "_generic.item|oops|foo")</strong>') def testexamine_url(self): ''' test the examine_url function '''
