Exemple #1
0
 def testGenClientConfig_ignoreBuilderContext(self):
     with test_lib.PreserveConfig():
         # Define a secondary config with special values for the ClientBuilder
         # context.
         str_override = """
     Test Context:
       Client.labels: [label0, label1]
       ClientBuilder Context:
         Client.labels: [build-label0, build-label1]
   """
         override = config_lib.YamlParser(data=str_override).RawData()
         config.CONFIG.MergeData(override)
         # Sanity-check that the secondary config was merged into the global
         # config.
         self.assertEqual(config.CONFIG["Client.labels"],
                          ["label0", "label1"])
         repacker = build.ClientRepacker()
         context = [
             "Test Context", "ClientBuilder Context", "Client Context"
         ]
         str_client_config = repacker.GetClientConfig(context)
         client_config = config_lib.YamlParser(
             data=str_client_config).RawData()
         # Settings particular to the ClientBuilder context should not carry over
         # into the generated client config.
         self.assertEqual(client_config["Client.labels"],
                          ["label0", "label1"])
Exemple #2
0
    def testRepackerDummyClientConfig(self):
        """Ensure our dummy client config can pass validation.

    This config is used to exercise repacking code in integration testing, here
    we just make sure it will pass validation.
    """
        new_config = config.CONFIG.MakeNewConfig()
        new_config.Initialize()
        new_config.LoadSecondaryConfig(
            os.path.join(config.CONFIG["Test.data_dir"], "dummyconfig.yaml"))
        build.ClientRepacker().ValidateEndConfig(new_config)
Exemple #3
0
    def testGenClientConfig(self):
        with test_lib.ConfigOverrider({"Client.build_environment":
                                       "test_env"}):

            deployer = build.ClientRepacker()
            data = deployer.GetClientConfig(["Client Context"], validate=True)

            parser = config_lib.YamlParser(data=data)
            raw_data = parser.RawData()

            self.assertIn("Client.deploy_time", raw_data)
Exemple #4
0
    def testRepackAll(self):
        """Test repacking all binaries."""
        self.executables_dir = config_lib.Resource().Filter("executables")
        with utils.TempDirectory() as tmp_dir:
            new_dir = os.path.join(tmp_dir, "grr", "executables")
            os.makedirs(new_dir)

            # Copy unzipsfx so it can be used in repacking/
            shutil.copy(
                os.path.join(self.executables_dir,
                             "windows/templates/unzipsfx/unzipsfx-i386.exe"),
                new_dir)
            shutil.copy(
                os.path.join(self.executables_dir,
                             "windows/templates/unzipsfx/unzipsfx-amd64.exe"),
                new_dir)

            with test_lib.ConfigOverrider({
                    "ClientBuilder.executables_dir":
                    new_dir,
                    "ClientBuilder.unzipsfx_stub_dir":
                    new_dir
            }):
                repacking.TemplateRepacker().RepackAllTemplates()

            self.assertEqual(
                len(glob.glob(os.path.join(new_dir, "installers/*.deb"))), 2)
            self.assertEqual(
                len(glob.glob(os.path.join(new_dir, "installers/*.rpm"))), 2)
            self.assertEqual(
                len(glob.glob(os.path.join(new_dir, "installers/*.exe"))), 4)
            self.assertEqual(
                len(glob.glob(os.path.join(new_dir, "installers/*.pkg"))), 1)

            # Validate the config appended to the OS X package.
            zf = zipfile.ZipFile(glob.glob(
                os.path.join(new_dir, "installers/*.pkg")).pop(),
                                 mode="r")
            fd = zf.open("config.yaml")

            # We can't load the included build.yaml because the package hasn't been
            # installed.
            loaded = yaml.safe_load(fd)
            loaded.pop("Config.includes")

            packaged_config = config.CONFIG.MakeNewConfig()
            packaged_config.Initialize(parser=config_lib.YamlParser,
                                       data=yaml.safe_dump(loaded))
            packaged_config.Validate(
                sections=build.ClientRepacker.CONFIG_SECTIONS)
            repacker = build.ClientRepacker()
            repacker.ValidateEndConfig(packaged_config)
Exemple #5
0
Fichier : osx.py Projet : qsdj/grr
  def WriteClientConfig(self):
    repacker = build.ClientRepacker(context=self.context)
    repacker.context = self.context

    # Generate a config file.
    with open(
        os.path.join(self.target_binary_dir,
                     config.CONFIG.Get(
                         "ClientBuilder.config_filename",
                         context=self.context)), "wb") as fd:
      fd.write(
          repacker.GetClientConfig(
              ["Client Context"] + self.context, validate=False))
Exemple #6
0
def GetClientConfig(filename):
    """Write client config to filename."""
    config_lib.SetPlatformArchContext()
    config_lib.ParseConfigCommandLine()
    context = list(grr_config.CONFIG.context)
    context.append("Client Context")
    deployer = build.ClientRepacker()
    # Disable timestamping so we can get a reproducible and cachable config file.
    config_data = deployer.GetClientConfig(context,
                                           validate=True,
                                           deploy_timestamp=False)
    builder = build.ClientBuilder()
    with open(filename, "w") as fd:
        fd.write(config_data)
        builder.WriteBuildYaml(fd, build_timestamp=False)