Пример #1
0
  def testHexString(self):
    mock_client = mock.MagicMock()

    with mock.patch.object(magics_impl._state, 'client', mock_client):
      magics_impl.grr_fgrep_impl('ffac90', '/foo/bar', hex_string=True)

      mock_client.os.fgrep.assert_called_once_with('/foo/bar', b'\xff\xac\x90')
Пример #2
0
  def testRegistryPathType(self):
    mock_client = mock.MagicMock()

    with mock.patch.object(magics_impl._state, 'client', mock_client):
      magics_impl.grr_fgrep_impl(
          'foo bar', '/foo/bar', path_type=magics_impl.REGISTRY)

      mock_client.registry.fgrep.assert_called_once_with('/foo/bar', b'foo bar')
Пример #3
0
  def testNtfsPathType(self):
    mock_client = mock.MagicMock()

    with mock.patch.object(magics_impl._state, 'client', mock_client):
      magics_impl.grr_fgrep_impl(
          'foo bar', '/foo/bar', path_type=magics_impl.NTFS)

      mock_client.ntfs.fgrep.assert_called_once_with('/foo/bar', b'foo bar')
Пример #4
0
  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_fgrep_impl('foo bar', '/foo/bar')

        mock_client.os.fgrep.assert_called_once_with('/foo/bar', b'foo bar')
Пример #5
0
def grr_fgrep(line):
    """Greps for a given literal content of a specified file.

  Is the same as running: %grr_grep -F

  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_fgrep.parser.parse_args(shlex.split(line))
    return magics_impl.grr_fgrep_impl(args.literal, args.path)
Пример #6
0
 def testNoClientSelected(self):
     with self.assertRaises(magics_impl.NoClientSelectedError):
         magics_impl.grr_fgrep_impl('foo', 'bar')