def extension_id(self):
     """Unique extension id of this extension."""
     if crx_id.HasPublicKey(self._path):
         # Calculate extension id from the public key.
         return crx_id.GetCRXAppID(os.path.realpath(self._path))
     else:
         # Calculate extension id based on the path on the presentation.device.
         return crx_id.GetCRXAppID(os.path.realpath(self._local_path),
                                   from_file_path=True,
                                   is_win_path=self._is_win)
 def testUnpackedHashAppId(self):
     """ Test the output generated for a canned, unpacked extension. """
     unpacked_test_manifest_path = os.path.join(self.CRX_ID_DIR,
                                                'manifest_with_key.json')
     temp_unpacked_crx = tempfile.mkdtemp()
     shutil.copy2(unpacked_test_manifest_path,
                  os.path.join(temp_unpacked_crx, 'manifest.json'))
     self.assertEqual(crx_id.GetCRXAppID(temp_unpacked_crx),
                      self.UNPACKED_APP_ID)
     self.assertEqual(crx_id.GetCRXHash(temp_unpacked_crx),
                      self.UNPACKED_HASH_BYTES)
     self.assertTrue(crx_id.HasPublicKey(temp_unpacked_crx))
     shutil.rmtree(temp_unpacked_crx)
Esempio n. 3
0
    def __init__(self, path, browser_type, is_component=False):
        if not os.path.isdir(path):
            raise ExtensionPathNonExistentException(
                'Extension path not a directory %s' % path)
        self._path = path
        self._local_path = path
        self._is_component = is_component
        if is_component and not crx_id.HasPublicKey(path):
            raise MissingPublicKeyException(
                'Component extension %s must have a public key' % path)

        # It is possible that we are running telemetry on Windows targeting
        # a remote CrOS or Android device. In this case, we need the
        # browser_type argument to determine how we should encode
        # the extension path.
        self._is_win = (os.name == 'nt'
                        and not (browser_type.startswith('android')
                                 or browser_type.startswith('cros')))