Ejemplo n.º 1
0
 def testMakeGoogleUniqueID(self):
     google_cloud_instance = rdf_cloud.GoogleCloudInstance(
         instance_id="1771384456894610289",
         zone="projects/123456789733/zones/us-central1-a",
         project_id="myproject")
     self.assertEqual(rdf_cloud.MakeGoogleUniqueID(google_cloud_instance),
                      "us-central1-a/myproject/1771384456894610289")
Ejemplo n.º 2
0
    def testGetMetadataWithGoogleCloudInstanceID(self):
        fixture_test_lib.ClientFixture(self.client_id)
        snapshot = data_store.REL_DB.ReadClientSnapshot(self.client_id)
        snapshot.cloud_instance = rdf_cloud.CloudInstance(
            cloud_type=rdf_cloud.CloudInstance.InstanceType.GOOGLE,
            google=rdf_cloud.GoogleCloudInstance(unique_id="foo/bar"))
        data_store.REL_DB.WriteClientSnapshot(snapshot)

        metadata = export.GetMetadata(
            self.client_id,
            data_store.REL_DB.ReadClientFullInfo(self.client_id))
        self.assertEqual(metadata.cloud_instance_type,
                         metadata.CloudInstanceType.GOOGLE)
        self.assertEqual(metadata.cloud_instance_id, "foo/bar")
Ejemplo n.º 3
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 = rdf_cloud.GoogleCloudInstance(
            instance_id="1771384456894610289",
            zone="projects/123456789733/zones/us-central1-a",
            project_id="myproject",
            unique_id="us-central1-a/myproject/1771384456894610289")
        cloud_instance = rdf_cloud.CloudInstance(cloud_type="GOOGLE",
                                                 google=google_cloud_instance)

        serial_number = "DSD33679FZ"
        system_manufacturer = "Foobar Inc."
        system_uuid = "C31292AD-6Z4F-55D8-28AC-EC1100E42222"
        hwinfo = rdf_client.HardwareInfo(
            serial_number=serial_number,
            system_manufacturer=system_manufacturer,
            system_uuid=system_uuid)

        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.AsSecondsSinceEpoch(),
                                 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.HARDWARE_INFO(hwinfo))
                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.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.AsSecondsSinceEpoch(), 101)
                self.assertEqual(summary.cloud_type, "GOOGLE")
                self.assertEqual(
                    summary.cloud_instance_id,
                    "us-central1-a/myproject/1771384456894610289")

                self.assertEqual(summary.serial_number, serial_number)
                self.assertEqual(summary.system_manufacturer,
                                 system_manufacturer)
                self.assertEqual(summary.system_uuid, system_uuid)