-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
gh-103186: assert in tests that UnsafeMailcapInput warnings are provided #103217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
a18d5f0
f479570
f412f07
605d93f
12e8373
80d0ef7
8bd668d
820564d
bf5f22d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -127,7 +127,6 @@ def test_subst(self): | |||||||
(["", "audio/*", "foo.txt"], ""), | ||||||||
(["echo foo", "audio/*", "foo.txt"], "echo foo"), | ||||||||
(["echo %s", "audio/*", "foo.txt"], "echo foo.txt"), | ||||||||
(["echo %t", "audio/*", "foo.txt"], None), | ||||||||
(["echo %t", "audio/wav", "foo.txt"], "echo audio/wav"), | ||||||||
(["echo \\%t", "audio/*", "foo.txt"], "echo %t"), | ||||||||
(["echo foo", "audio/*", "foo.txt", plist], "echo foo"), | ||||||||
|
@@ -210,9 +209,6 @@ def test_findmatch(self): | |||||||
([c, "audio/basic"], | ||||||||
{"key": "description", "filename": fname}, | ||||||||
('"An audio fragment"', audio_basic_entry)), | ||||||||
([c, "audio/*"], | ||||||||
{"filename": fname}, | ||||||||
(None, None)), | ||||||||
([c, "audio/wav"], | ||||||||
{"filename": fname}, | ||||||||
("/usr/local/bin/showaudio audio/wav", audio_entry)), | ||||||||
|
@@ -245,6 +241,21 @@ def test_test(self): | |||||||
] | ||||||||
self._run_cases(cases) | ||||||||
|
||||||||
def test_unsafe_mailcap_input(self): | ||||||||
plist = ["total=*"] | ||||||||
with self.assertWarnsRegex(mailcap.UnsafeMailcapInput, | ||||||||
'Refusing to substitute parameter.*into a shell command'): | ||||||||
self.assertEqual(mailcap.subst("echo %{total}", "audio/wav", "foo.txt", plist), None) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is also > 80 chars |
||||||||
|
||||||||
with self.assertWarnsRegex(mailcap.UnsafeMailcapInput, | ||||||||
'Refusing to substitute MIME type.*into a shell'): | ||||||||
self.assertEqual(mailcap.subst("echo %t", "audio/*", "foo.txt"), None) | ||||||||
|
||||||||
with self.assertWarnsRegex(mailcap.UnsafeMailcapInput, | ||||||||
'Refusing to use mailcap with filename.*Use a safe temporary filename.'): | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
self.assertEqual(mailcap.findmatch(MAILCAPDICT, | ||||||||
"audio/wav", filename="foo*.txt"), (None, None)) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't want to break the first arg into two lines and then continue with the second arg on the same line. You can assign the return value of findmatch to a variable and then compare the variable to expected value. |
||||||||
|
||||||||
def _run_cases(self, cases): | ||||||||
for c in cases: | ||||||||
self.assertEqual(mailcap.findmatch(*c[0], **c[1]), c[2]) | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also only used in one place.