##// END OF EJS Templates
trust is stored in code_cell.metadata...
MinRK -
Show More
@@ -311,13 +311,13 b' class TestContentsManager(TestCase):'
311 cm.mark_trusted_cells(nb, name, path)
311 cm.mark_trusted_cells(nb, name, path)
312 for cell in nb.worksheets[0].cells:
312 for cell in nb.worksheets[0].cells:
313 if cell.cell_type == 'code':
313 if cell.cell_type == 'code':
314 assert not cell.trusted
314 assert not cell.metadata.trusted
315
315
316 cm.trust_notebook(name, path)
316 cm.trust_notebook(name, path)
317 nb = cm.get_model(name, path)['content']
317 nb = cm.get_model(name, path)['content']
318 for cell in nb.worksheets[0].cells:
318 for cell in nb.worksheets[0].cells:
319 if cell.cell_type == 'code':
319 if cell.cell_type == 'code':
320 assert cell.trusted
320 assert cell.metadata.trusted
321
321
322 def test_check_and_sign(self):
322 def test_check_and_sign(self):
323 cm = self.contents_manager
323 cm = self.contents_manager
@@ -472,7 +472,7 b' define(['
472 } else {
472 } else {
473 this.set_input_prompt();
473 this.set_input_prompt();
474 }
474 }
475 this.output_area.trusted = data.trusted || false;
475 this.output_area.trusted = data.metadata.trusted || false;
476 this.output_area.fromJSON(data.outputs);
476 this.output_area.fromJSON(data.outputs);
477 if (data.collapsed !== undefined) {
477 if (data.collapsed !== undefined) {
478 if (data.collapsed) {
478 if (data.collapsed) {
@@ -495,8 +495,8 b' define(['
495 var outputs = this.output_area.toJSON();
495 var outputs = this.output_area.toJSON();
496 data.outputs = outputs;
496 data.outputs = outputs;
497 data.language = 'python';
497 data.language = 'python';
498 data.trusted = this.output_area.trusted;
498 data.metadata.trusted = this.output_area.trusted;
499 data.collapsed = this.collapsed;
499 data.collapsed = this.output_area.collapsed;
500 return data;
500 return data;
501 };
501 };
502
502
@@ -1,14 +1,7 b''
1 """Functions for signing notebooks"""
1 """Functions for signing notebooks"""
2 #-----------------------------------------------------------------------------
3 # Copyright (C) 2014, The IPython Development Team
4 #
5 # Distributed under the terms of the BSD License. The full license is in
6 # the file COPYING, distributed as part of this software.
7 #-----------------------------------------------------------------------------
8
2
9 #-----------------------------------------------------------------------------
3 # Copyright (c) IPython Development Team.
10 # Imports
4 # Distributed under the terms of the Modified BSD License.
11 #-----------------------------------------------------------------------------
12
5
13 import base64
6 import base64
14 from contextlib import contextmanager
7 from contextlib import contextmanager
@@ -24,15 +17,14 b' from IPython.core.application import BaseIPythonApplication, base_flags'
24
17
25 from .current import read, write
18 from .current import read, write
26
19
27 #-----------------------------------------------------------------------------
20
28 # Code
29 #-----------------------------------------------------------------------------
30 try:
21 try:
31 # Python 3
22 # Python 3
32 algorithms = hashlib.algorithms_guaranteed
23 algorithms = hashlib.algorithms_guaranteed
33 except AttributeError:
24 except AttributeError:
34 algorithms = hashlib.algorithms
25 algorithms = hashlib.algorithms
35
26
27
36 def yield_everything(obj):
28 def yield_everything(obj):
37 """Yield every item in a container as bytes
29 """Yield every item in a container as bytes
38
30
@@ -184,7 +176,7 b' class NotebookNotary(LoggingConfigurable):'
184 def mark_cells(self, nb, trusted):
176 def mark_cells(self, nb, trusted):
185 """Mark cells as trusted if the notebook's signature can be verified
177 """Mark cells as trusted if the notebook's signature can be verified
186
178
187 Sets ``cell.trusted = True | False`` on all code cells,
179 Sets ``cell.metadata.trusted = True | False`` on all code cells,
188 depending on whether the stored signature can be verified.
180 depending on whether the stored signature can be verified.
189
181
190 This function is the inverse of check_cells
182 This function is the inverse of check_cells
@@ -194,7 +186,7 b' class NotebookNotary(LoggingConfigurable):'
194 return
186 return
195 for cell in nb['worksheets'][0]['cells']:
187 for cell in nb['worksheets'][0]['cells']:
196 if cell['cell_type'] == 'code':
188 if cell['cell_type'] == 'code':
197 cell['trusted'] = trusted
189 cell['metadata']['trusted'] = trusted
198
190
199 def _check_cell(self, cell):
191 def _check_cell(self, cell):
200 """Do we trust an individual cell?
192 """Do we trust an individual cell?
@@ -208,7 +200,7 b' class NotebookNotary(LoggingConfigurable):'
208 it will always be trusted.
200 it will always be trusted.
209 """
201 """
210 # explicitly trusted
202 # explicitly trusted
211 if cell.pop("trusted", False):
203 if cell['metadata'].pop("trusted", False):
212 return True
204 return True
213
205
214 # explicitly safe output
206 # explicitly safe output
@@ -243,6 +235,7 b' class NotebookNotary(LoggingConfigurable):'
243 # only distrust a cell if it actually has some output to distrust
235 # only distrust a cell if it actually has some output to distrust
244 if not self._check_cell(cell):
236 if not self._check_cell(cell):
245 trusted = False
237 trusted = False
238
246 return trusted
239 return trusted
247
240
248
241
@@ -83,21 +83,23 b' class TestNotary(TestsBase):'
83 cells = self.nb.worksheets[0].cells
83 cells = self.nb.worksheets[0].cells
84 self.notary.mark_cells(self.nb, False)
84 self.notary.mark_cells(self.nb, False)
85 for cell in cells:
85 for cell in cells:
86 self.assertNotIn('trusted', cell)
86 if cell.cell_type == 'code':
87 if cell.cell_type == 'code':
87 self.assertIn('trusted', cell)
88 self.assertIn('trusted', cell.metadata)
88 self.assertFalse(cell.trusted)
89 self.assertFalse(cell.metadata.trusted)
89 else:
90 else:
90 self.assertNotIn('trusted', cell)
91 self.assertNotIn('trusted', cell.metadata)
91
92
92 def test_mark_cells_trusted(self):
93 def test_mark_cells_trusted(self):
93 cells = self.nb.worksheets[0].cells
94 cells = self.nb.worksheets[0].cells
94 self.notary.mark_cells(self.nb, True)
95 self.notary.mark_cells(self.nb, True)
95 for cell in cells:
96 for cell in cells:
97 self.assertNotIn('trusted', cell)
96 if cell.cell_type == 'code':
98 if cell.cell_type == 'code':
97 self.assertIn('trusted', cell)
99 self.assertIn('trusted', cell.metadata)
98 self.assertTrue(cell.trusted)
100 self.assertTrue(cell.metadata.trusted)
99 else:
101 else:
100 self.assertNotIn('trusted', cell)
102 self.assertNotIn('trusted', cell.metadata)
101
103
102 def test_check_cells(self):
104 def test_check_cells(self):
103 nb = self.nb
105 nb = self.nb
General Comments 0
You need to be logged in to leave comments. Login now