def testHexString(self): mock_client = mock.MagicMock() with mock.patch.object(magics_impl._state, 'client', mock_client): magics_impl.grr_grep_impl('ffac90', '/foo/bar', hex_string=True) mock_client.os.grep.assert_called_once_with('/foo/bar', b'\xff\xac\x90')
def testRegistryPathType(self): mock_client = mock.MagicMock() with mock.patch.object(magics_impl._state, 'client', mock_client): magics_impl.grr_grep_impl( 'foo bar', '/foo/bar', path_type=magics_impl.REGISTRY) mock_client.registry.grep.assert_called_once_with('/foo/bar', b'foo bar')
def testNtfsPathType(self): mock_client = mock.MagicMock() with mock.patch.object(magics_impl._state, 'client', mock_client): magics_impl.grr_grep_impl( 'foo bar', '/foo/bar', path_type=magics_impl.NTFS) mock_client.ntfs.grep.assert_called_once_with('/foo/bar', b'foo bar')
def testAbsolutePath(self): mock_client = mock.MagicMock() with mock.patch.object(magics_impl._state, 'client', mock_client): with mock.patch.object(magics_impl._state, 'cur_dir', '/quux'): magics_impl.grr_grep_impl('foo bar', '/foo/bar') mock_client.os.grep.assert_called_once_with('/foo/bar', b'foo bar')
def testFixedStrings(self): mock_client = mock.MagicMock() with mock.patch.object(magics_impl._state, 'client', mock_client): with mock.patch.object(magics_impl._state, 'cur_dir', '/quux'): magics_impl.grr_grep_impl('foo bar', '/foo/bar', fixed_strings=True) mock_client.os.fgrep.assert_called_once_with('/foo/bar', b'foo bar') self.assertFalse(mock_client.grep.called)
def grr_grep(line): """Greps for a given content of a specified file. Args: line: A string representing arguments passed to the magic command. Returns: A list of buffer references to the matched content. Raises: NoClientSelectedError: Client is not selected to perform this operation. """ args = grr_grep.parser.parse_args(shlex.split(line)) return magics_impl.grr_grep_impl(args.pattern, args.path, args.fixed_strings)
def testNoClientSelected(self): with self.assertRaises(magics_impl.NoClientSelectedError): magics_impl.grr_grep_impl('foo', 'bar')