def test_bug_will_use_top_trashdir_even_with_not_sticky(self): self.fs.mock_add_spec(['isdir', 'islink', 'has_sticky_bit', 'move', 'atomic_write', 'remove_file', 'ensure_dir']) self.fs.isdir.return_value = True self.fs.islink.return_value = False self.fs.has_sticky_bit.return_value = False result = TrashResult(False) self.file_trasher.trash_file('sandbox/foo', None, None, result, self.logger, self.reporter) assert self.fs.mock_calls == [ call.isdir('.Trash'), call.islink('.Trash'), call.has_sticky_bit('.Trash'), call.ensure_dir('.Trash-123/files', 448), call.ensure_dir('.Trash-123/info', 448), call.atomic_write('.Trash-123/info/foo.trashinfo', ANY), call.move('sandbox/foo', '.Trash-123/files/foo') ]
def test_is_valid(self): fs = Mock(spec=['isdir', 'islink', 'has_sticky_bit']) fs.isdir.return_value = True fs.islink.return_value = False fs.has_sticky_bit.return_value = True secure, messages = self.rules.check_trash_dir_is_secure( '/parent/trash-dir', fs) assert [ call.isdir('/parent'), call.islink('/parent'), call.has_sticky_bit('/parent') ] == fs.mock_calls assert secure == True assert messages == []
def test_not_valid_parent_should_be_sticky(self): fs = Mock(spec=['isdir', 'islink', 'has_sticky_bit']) fs.isdir.return_value = True fs.islink.return_value = False fs.has_sticky_bit.return_value = False secure, messages = self.rules.check_trash_dir_is_secure( '/parent/trash-dir', fs) assert [ call.isdir('/parent'), call.islink('/parent'), call.has_sticky_bit('/parent') ] == fs.mock_calls assert False == secure assert messages == [ 'found unsecure .Trash dir (should be sticky): /parent' ]
def test_bug_will_use_top_trashdir_even_with_not_sticky(self): self.fs.mock_add_spec(['isdir', 'islink', 'has_sticky_bit', 'move', 'atomic_write', 'remove_file', 'ensure_dir']) self.fs.isdir.return_value = True self.fs.islink.return_value = False self.fs.has_sticky_bit.return_value = False self.trashcan.trash('sandbox/foo') assert_equal([ call.isdir('.Trash'), call.islink('.Trash'), call.has_sticky_bit('.Trash'), call.ensure_dir('.Trash-123/info', 448), call.atomic_write('.Trash-123/info/foo.trashinfo', ANY), call.ensure_dir('.Trash-123/files', 448), call.move('sandbox/foo', '.Trash-123/files/foo') ], self.fs.mock_calls, self.fs.mock_calls)
def test_bug_will_use_top_trashdir_even_with_not_sticky(self): self.fs.mock_add_spec(['isdir', 'islink', 'has_sticky_bit', 'move', 'atomic_write', 'remove_file', 'ensure_dir']) self.fs.isdir.return_value = True self.fs.islink.return_value = False self.fs.has_sticky_bit.return_value = False self.trashcan.trash('sandbox/foo') assert_equals([ call.isdir('.Trash'), call.islink('.Trash'), call.has_sticky_bit('.Trash'), call.ensure_dir('.Trash-123/info', 448), call.atomic_write('.Trash-123/info/foo.trashinfo', ANY), call.ensure_dir('.Trash-123/files', 448), call.move('sandbox/foo', '.Trash-123/files/foo') ], self.fs.mock_calls, self.fs.mock_calls)
def test_use_of_top_trash_dir_when_sticky(self): self.fs.mock_add_spec([ 'isdir', 'islink', 'has_sticky_bit', 'move', 'atomic_write', 'remove_file', 'ensure_dir' ]) self.fs.isdir.return_value = True self.fs.islink.return_value = False self.fs.has_sticky_bit.return_value = True self.trashcan.trash('sandbox/foo') assert [ call.isdir('.Trash'), call.islink('.Trash'), call.has_sticky_bit('.Trash'), call.ensure_dir('.Trash/123/info', 448), call.atomic_write('.Trash/123/info/foo.trashinfo', ANY), call.ensure_dir('.Trash/123/files', 448), call.move('sandbox/foo', '.Trash/123/files/foo') ] == self.fs.mock_calls