grr/server/grr_response_server/flows/general/collectors_test.py
def testConditions(self):
    """Test we can get a GRR client artifact with conditions."""
    client_id = self.SetupClient(0, system="Linux")
    with utils.Stubber(psutil, "process_iter", ProcessIter):
      # Run with false condition.
      client_mock = action_mocks.ActionMock(standard.ListProcesses)
      coll1 = rdf_artifacts.ArtifactSource(
          type=rdf_artifacts.ArtifactSource.SourceType.GRR_CLIENT_ACTION,
          attributes={"client_action": standard.ListProcesses.__name__},
          conditions=["os == 'Windows'"])
      self.fakeartifact.sources.append(coll1)
      results = self._RunClientActionArtifact(client_id, client_mock,
                                              ["FakeArtifact"])
      self.assertEmpty(results)

      # Now run with matching or condition.
      coll1.conditions = ["os == 'Linux' or os == 'Windows'"]
      self.fakeartifact.sources = []
      self.fakeartifact.sources.append(coll1)
      results = self._RunClientActionArtifact(client_id, client_mock,
                                              ["FakeArtifact"])
      self.assertTrue(results)

      # Now run with impossible or condition.
      coll1.conditions.append("os == 'NotTrue'")
      self.fakeartifact.sources = []
      self.fakeartifact.sources.append(coll1)
      results = self._RunClientActionArtifact(client_id, client_mock,
                                              ["FakeArtifact"])
      self.assertLen(results, 0)
      self.assertEmpty(results)
Test we can get a GRR client artifact with conditions.
Test we can get a GRR client artifact with conditions.
Test we can get a GRR client artifact with conditions .
def testConditions(self):
    client_id = self.SetupClient(0, system="Linux")
    with utils.Stubber(psutil, "process_iter", ProcessIter):
      client_mock = action_mocks.ActionMock(standard.ListProcesses)
      coll1 = rdf_artifacts.ArtifactSource(
          type=rdf_artifacts.ArtifactSource.SourceType.GRR_CLIENT_ACTION,
          attributes={"client_action": standard.ListProcesses.__name__},
          conditions=["os == 'Windows'"])
      self.fakeartifact.sources.append(coll1)
      results = self._RunClientActionArtifact(client_id, client_mock,
                                              ["FakeArtifact"])
      self.assertEmpty(results)
      coll1.conditions = ["os == 'Linux' or os == 'Windows'"]
      self.fakeartifact.sources = []
      self.fakeartifact.sources.append(coll1)
      results = self._RunClientActionArtifact(client_id, client_mock,
                                              ["FakeArtifact"])
      self.assertTrue(results)
      coll1.conditions.append("os == 'NotTrue'")
      self.fakeartifact.sources = []
      self.fakeartifact.sources.append(coll1)
      results = self._RunClientActionArtifact(client_id, client_mock,
                                              ["FakeArtifact"])
      self.assertLen(results, 0)
      self.assertEmpty(results)
def testConditions ( self ) : client_id = self . SetupClient ( 0 , system = "Linux" ) with utils . Stubber ( psutil , "process_iter" , ProcessIter ) : client_mock = action_mocks . ActionMock ( standard . ListProcesses ) coll1 = rdf_artifacts . ArtifactSource ( type = rdf_artifacts . ArtifactSource . SourceType . GRR_CLIENT_ACTION , attributes = { "client_action" : standard . ListProcesses . __name__ } , conditions = [ "os == 'Windows'" ] ) self . fakeartifact . sources . append ( coll1 ) results = self . _RunClientActionArtifact ( client_id , client_mock , [ "FakeArtifact" ] ) self . assertEmpty ( results ) coll1 . conditions = [ "os == 'Linux' or os == 'Windows'" ] self . fakeartifact . sources = [ ] self . fakeartifact . sources . append ( coll1 ) results = self . _RunClientActionArtifact ( client_id , client_mock , [ "FakeArtifact" ] ) self . assertTrue ( results ) coll1 . conditions . append ( "os == 'NotTrue'" ) self . fakeartifact . sources = [ ] self . fakeartifact . sources . append ( coll1 ) results = self . _RunClientActionArtifact ( client_id , client_mock , [ "FakeArtifact" ] ) self . assertLen ( results , 0 ) self . assertEmpty ( results )
Test we can get a GRR client artifact with conditions.
Test we can get a GRR client artifact with conditions .
"""Test we can get a GRR client artifact with conditions.""" # Run with false condition. # Now run with matching or condition. # Now run with impossible or condition.
self