grr/server/grr_response_server/flows/general/administrative_test.py
def testUpdateConfig(self):
    """Ensure we can retrieve and update the config."""

    # Write a client without a proper system so we don't need to
    # provide the os specific artifacts in the interrogate flow below.
    client_id = self.SetupClient(0, system="")

    # Only mock the pieces we care about.
    client_mock = action_mocks.ActionMock(admin.GetConfiguration,
                                          admin.UpdateConfiguration)

    loc = "http://www.example.com/"
    new_config = rdf_protodict.Dict({
        "Client.server_urls": [loc],
        "Client.foreman_check_frequency": 3600,
        "Client.poll_min": 1
    })

    # Setting config options is disallowed in tests so we need to temporarily
    # revert this.
    with utils.Stubber(config.CONFIG, "Set", config.CONFIG.Set.old_target):
      # Write the config.
      flow_test_lib.TestFlowHelper(
          administrative.UpdateConfiguration.__name__,
          client_mock,
          client_id=client_id,
          token=self.token,
          config=new_config)

    # Now retrieve it again to see if it got written.
    flow_test_lib.TestFlowHelper(
        discovery.Interrogate.__name__,
        client_mock,
        token=self.token,
        client_id=client_id)

    if data_store.RelationalDBReadEnabled():
      client = data_store.REL_DB.ReadClientSnapshot(client_id.Basename())
      config_dat = {item.key: item.value for item in client.grr_configuration}
      # The grr_configuration only contains strings.
      self.assertEqual(config_dat["Client.server_urls"],
                       "[u'http://www.example.com/']")
      self.assertEqual(config_dat["Client.poll_min"], "1.0")
    else:
      fd = aff4.FACTORY.Open(client_id, token=self.token)
      config_dat = fd.Get(fd.Schema.GRR_CONFIGURATION)
      self.assertEqual(config_dat["Client.server_urls"], [loc])
      self.assertEqual(config_dat["Client.poll_min"], 1)
Ensure we can retrieve and update the config.
Ensure we can retrieve and update the config.
Ensure we can retrieve and update the config .
def testUpdateConfig(self):
    client_id = self.SetupClient(0, system="")
    client_mock = action_mocks.ActionMock(admin.GetConfiguration,
                                          admin.UpdateConfiguration)
    loc = "http://www.example.com/"
    new_config = rdf_protodict.Dict({
        "Client.server_urls": [loc],
        "Client.foreman_check_frequency": 3600,
        "Client.poll_min": 1
    })
    with utils.Stubber(config.CONFIG, "Set", config.CONFIG.Set.old_target):
      flow_test_lib.TestFlowHelper(
          administrative.UpdateConfiguration.__name__,
          client_mock,
          client_id=client_id,
          token=self.token,
          config=new_config)
    flow_test_lib.TestFlowHelper(
        discovery.Interrogate.__name__,
        client_mock,
        token=self.token,
        client_id=client_id)
    if data_store.RelationalDBReadEnabled():
      client = data_store.REL_DB.ReadClientSnapshot(client_id.Basename())
      config_dat = {item.key: item.value for item in client.grr_configuration}
      self.assertEqual(config_dat["Client.server_urls"],
                       "[u'http://www.example.com/']")
      self.assertEqual(config_dat["Client.poll_min"], "1.0")
    else:
      fd = aff4.FACTORY.Open(client_id, token=self.token)
      config_dat = fd.Get(fd.Schema.GRR_CONFIGURATION)
      self.assertEqual(config_dat["Client.server_urls"], [loc])
      self.assertEqual(config_dat["Client.poll_min"], 1)
def testUpdateConfig ( self ) : client_id = self . SetupClient ( 0 , system = "" ) client_mock = action_mocks . ActionMock ( admin . GetConfiguration , admin . UpdateConfiguration ) loc = "http://www.example.com/" new_config = rdf_protodict . Dict ( { "Client.server_urls" : [ loc ] , "Client.foreman_check_frequency" : 3600 , "Client.poll_min" : 1 } ) with utils . Stubber ( config . CONFIG , "Set" , config . CONFIG . Set . old_target ) : flow_test_lib . TestFlowHelper ( administrative . UpdateConfiguration . __name__ , client_mock , client_id = client_id , token = self . token , config = new_config ) flow_test_lib . TestFlowHelper ( discovery . Interrogate . __name__ , client_mock , token = self . token , client_id = client_id ) if data_store . RelationalDBReadEnabled ( ) : client = data_store . REL_DB . ReadClientSnapshot ( client_id . Basename ( ) ) config_dat = { item . key : item . value for item in client . grr_configuration } self . assertEqual ( config_dat [ "Client.server_urls" ] , "[u'http://www.example.com/']" ) self . assertEqual ( config_dat [ "Client.poll_min" ] , "1.0" ) else : fd = aff4 . FACTORY . Open ( client_id , token = self . token ) config_dat = fd . Get ( fd . Schema . GRR_CONFIGURATION ) self . assertEqual ( config_dat [ "Client.server_urls" ] , [ loc ] ) self . assertEqual ( config_dat [ "Client.poll_min" ] , 1 )
Ensure we can retrieve and update the config.
Ensure we can retrieve and update the config .
"""Ensure we can retrieve and update the config.""" # Write a client without a proper system so we don't need to # provide the os specific artifacts in the interrogate flow below. # Only mock the pieces we care about. # Setting config options is disallowed in tests so we need to temporarily # revert this. # Write the config. # Now retrieve it again to see if it got written. # The grr_configuration only contains strings.
self