Show More
@@ -1110,3 +1110,43 def test_set_custom_completer(): | |||
|
1110 | 1110 | |
|
1111 | 1111 | # clean up |
|
1112 | 1112 | 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" |
General Comments 0
You need to be logged in to leave comments.
Login now