예제 #1
0
 def testMakeGoogleUniqueID(self):
     google_cloud_instance = cloud.GoogleCloudInstance(
         instance_id="1771384456894610289",
         zone="projects/123456789733/zones/us-central1-a",
         project_id="myproject")
     self.assertEqual(cloud.MakeGoogleUniqueID(google_cloud_instance),
                      "us-central1-a/myproject/1771384456894610289")
예제 #2
0
    def testGetClientSummary(self):
        hostname = "test"
        system = "Linux"
        os_release = "12.02"
        kernel = "3.15-rc2"
        fqdn = "test.test.com"
        arch = "amd64"
        install_time = rdfvalue.RDFDatetime.Now()
        user = "******"
        userobj = rdf_client.User(username=user)
        interface = rdf_client.Interface(ifname="eth0")
        google_cloud_instance = cloud.GoogleCloudInstance(
            instance_id="1771384456894610289",
            zone="projects/123456789733/zones/us-central1-a",
            project_id="myproject",
            unique_id="us-central1-a/myproject/1771384456894610289")
        cloud_instance = cloud.CloudInstance(cloud_type="GOOGLE",
                                             google=google_cloud_instance)

        timestamp = 1
        with utils.Stubber(time, "time", lambda: timestamp):
            with aff4.FACTORY.Create("C.0000000000000000",
                                     aff4_grr.VFSGRRClient,
                                     mode="rw",
                                     token=self.token) as fd:
                kb = rdf_client.KnowledgeBase()
                kb.users.Append(userobj)
                empty_summary = fd.GetSummary()
                self.assertEqual(empty_summary.client_id, "C.0000000000000000")
                self.assertFalse(empty_summary.system_info.version)
                self.assertEqual(empty_summary.timestamp.AsSecondsFromEpoch(),
                                 1)

                # This will cause TYPE to be written with current time = 101 when the
                # object is closed
                timestamp += 100
                fd.Set(fd.Schema.HOSTNAME(hostname))
                fd.Set(fd.Schema.SYSTEM(system))
                fd.Set(fd.Schema.OS_RELEASE(os_release))
                fd.Set(fd.Schema.KERNEL(kernel))
                fd.Set(fd.Schema.FQDN(fqdn))
                fd.Set(fd.Schema.ARCH(arch))
                fd.Set(fd.Schema.INSTALL_DATE(install_time))
                fd.Set(fd.Schema.KNOWLEDGE_BASE(kb))
                fd.Set(fd.Schema.USERNAMES([user]))
                fd.Set(fd.Schema.INTERFACES([interface]))
                fd.Set(fd.Schema.CLOUD_INSTANCE(cloud_instance))

            with aff4.FACTORY.Open("C.0000000000000000",
                                   aff4_grr.VFSGRRClient,
                                   mode="rw",
                                   token=self.token) as fd:
                summary = fd.GetSummary()
                self.assertEqual(summary.system_info.node, hostname)
                self.assertEqual(summary.system_info.system, system)
                self.assertEqual(summary.system_info.release, os_release)
                self.assertEqual(summary.system_info.kernel, kernel)
                self.assertEqual(summary.system_info.fqdn, fqdn)
                self.assertEqual(summary.system_info.machine, arch)
                self.assertEqual(summary.system_info.install_date,
                                 install_time)
                self.assertItemsEqual(summary.users, [userobj])
                self.assertItemsEqual(summary.interfaces, [interface])
                self.assertFalse(summary.client_info)

                self.assertEqual(summary.timestamp.AsSecondsFromEpoch(), 101)
                self.assertEqual(summary.cloud_type, "GOOGLE")
                self.assertEqual(
                    summary.cloud_instance_id,
                    "us-central1-a/myproject/1771384456894610289")