Exemplo n.º 1
0
    def setUp(self):
        super(MultiRepackTest, self).setUp()
        self.pool_obj = mock.MagicMock()
        self.pool_patcher = mock.patch.object(multiprocessing,
                                              "Pool",
                                              return_value=self.pool_obj)
        self.mock_pool = self.pool_patcher.start()

        config_dir = temp.TempDirPath()
        self.label1_config = os.path.join(config_dir, "label1.yaml")
        self.label2_config = os.path.join(config_dir, "label2.yaml")
        open(self.label1_config, mode="wb").write("Client.labels: [label1]")
        open(self.label2_config, mode="wb").write("Client.labels: [label2]")
        self.template_dir = temp.TempDirPath()
        self.deb_template = os.path.join(self.template_dir,
                                         "grr_3.1.0.2_amd64.deb.zip")
        self.exe_template = os.path.join(self.template_dir,
                                         "GRR_3.1.0.2_i386.exe.zip")
        self.xar_template = os.path.join(self.template_dir,
                                         "grr_3.1.0.2_amd64.xar.zip")
        open(self.deb_template, mode="wb").write("linux")
        open(self.exe_template, mode="wb").write("windows")
        open(self.xar_template, mode="wb").write("darwin")

        self.output_dir = temp.TempDirPath()
Exemplo n.º 2
0
    def setUp(self):
        super(GRRBaseTest, self).setUp()

        self.temp_dir = temp.TempDirPath()
        config.CONFIG.SetWriteBack(
            os.path.join(self.temp_dir, "writeback.yaml"))

        logging.info("Starting test: %s.%s", self.__class__.__name__,
                     self._testMethodName)
        self.last_start_time = time.time()

        data_store.DB.ClearTestDB()
        # Each datastore is wrapped with DatabaseValidationWrapper, so we have
        # to access the delegate directly (assuming it's an InMemoryDB
        # implementation).
        data_store.REL_DB.delegate.ClearTestDB()

        aff4.FACTORY.Flush()

        # Create a Foreman and Filestores, they are used in many tests.
        aff4_grr.GRRAFF4Init().Run()
        filestore.FileStoreInit().Run()
        hunts_results.ResultQueueInitHook().Run()
        email_alerts.EmailAlerterInit().RunOnce()
        audit.AuditEventListener._created_logs.clear()

        # Stub out the email function
        self.emails_sent = []

        def SendEmailStub(to_user, from_user, subject, message,
                          **unused_kwargs):
            self.emails_sent.append((to_user, from_user, subject, message))

        self.mail_stubber = utils.MultiStubber(
            (email_alerts.EMAIL_ALERTER, "SendEmail", SendEmailStub),
            (email.utils, "make_msgid", lambda: "<message id stub>"))
        self.mail_stubber.Start()

        # We don't want to send actual email in our tests
        self.smtp_patcher = mock.patch("smtplib.SMTP")
        self.mock_smtp = self.smtp_patcher.start()

        def DisabledSet(*unused_args, **unused_kw):
            raise NotImplementedError(
                "Usage of Set() is disabled, please use a configoverrider in tests."
            )

        self.config_set_disable = utils.Stubber(config.CONFIG, "Set",
                                                DisabledSet)
        self.config_set_disable.Start()

        if self.use_relational_reads:
            self.relational_read_stubber = utils.Stubber(
                data_store, "RelationalDBReadEnabled", lambda: True)
            self.relational_read_stubber.Start()

        self._SetupFakeStatsContext()
Exemplo n.º 3
0
def InitGRRWithTestSources(artifacts_data):
  artifact_registry.REGISTRY.ClearSources()
  artifact_registry.REGISTRY.ClearRegistry()

  artifacts_temp_dir = temp.TempDirPath()
  with open(os.path.join(artifacts_temp_dir, "test_artifacts.yaml"), "w") as fd:
    fd.write(artifacts_data)

  artifact_registry.REGISTRY.AddDirSources([artifacts_temp_dir])

  def CleanUp():
    shutil.rmtree(artifacts_temp_dir)

  return CleanUp
Exemplo n.º 4
0
 def setUp(self):
     self.temp_dir = temp.TempDirPath()
Exemplo n.º 5
0
 def setUp(self):
     super(DirHierarchyTestMixin, self).setUp()
     self.tempdir = temp.TempDirPath()