8000 Add some regression tests for this change · ipython/ipython@c7a9470 · GitHub
[go: up one dir, main page]

Skip to content

Commit c7a9470

Browse files
committed
Add some regression tests for this change
1 parent fd34cf5 commit c7a9470

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

IPython/core/tests/test_interactiveshell.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,3 +1110,43 @@ def foo(*args, **kwargs):
11101110

11111111
# clean up
11121112
ip.Completer.custom_matchers.pop()
1113+
1114+
1115+
class TestShowTracebacksAttack(unittest.TestCase):
1116+
"""Test that the interactive shell is resilient against the client attack of
1117+
manipulating the showtracebacks method. These attacks shouldn't result in an
1118+
unhandled exception in the kernel."""
1119+
1120+
def test_set_show_tracebacks_none(self):
1121+
"""Test the case of the client setting showtracebacks to None"""
1122+
1123+
result = ip.run_cell(
1124+
"""
1125+
import IPython.core.interactiveshell
1126+
IPython.core.interactiveshell.InteractiveShell.showtraceback = None
1127+
1128+
assert False, "This should not raise an exception"
1129+
"""
1130+
)
1131+
print(result)
1132+
1133+
assert result.result is None
1134+
assert isinstance(result.error_in_exec, TypeError)
1135+
assert str(result.error_in_exec) == "'NoneType' object is not callable"
1136+
1137+
def test_set_show_tracebacks_noop(self):
1138+
"""Test the case of the client setting showtracebacks to a no op lambda"""
1139+
1140+
result = ip.run_cell(
1141+
"""
1142+
import IPython.core.interactiveshell
1143+
IPython.core.interactiveshell.InteractiveShell.showtraceback = lambda *args, **kwargs: None
1144+
1145+
assert False, "This should not raise an exception"
1146+
"""
1147+
)
1148+
print(result)
1149+
1150+
assert result.result is None
1151+
assert isinstance(result.error_in_exec, AssertionError)
1152+
assert str(result.error_in_exec) == "This should not raise an exception"

0 commit comments

Comments
 (0)
0