コード例 #1
0
 def setUp(self):
     self._https_server_ok = self.StartHttpsServer(
         pyauto.HTTPSOptions.CERT_OK,
         os.path.relpath(os.path.join(self.DataDir(), 'ssl'),
                         pyauto_paths.GetSourceDir()))
     self._https_server_expired = self.StartHttpsServer(
         pyauto.HTTPSOptions.CERT_EXPIRED,
         os.path.relpath(os.path.join(self.DataDir(), 'ssl'),
                         pyauto_paths.GetSourceDir()))
     self._https_server_mismatched = self.StartHttpsServer(
         pyauto.HTTPSOptions.CERT_MISMATCHED_NAME,
         os.path.relpath(os.path.join(self.DataDir(), 'ssl'),
                         pyauto_paths.GetSourceDir()))
     pyauto.PyUITest.setUp(self)
コード例 #2
0
    def _SetUpLocal(self):
        """Starts the CNS server locally."""
        cmd = [
            sys.executable,
            os.path.join(pyauto_paths.GetSourceDir(), _CNS_PATH), '--port',
            str(self._port), '--interface', self._interface, '--www-root',
            self._www_root, '--expiry-time',
            str(self._expiry_time)
        ]

        if self._socket_timeout:
            cmd.extend(['--socket-timeout', str(self._socket_timeout)])
        if self._verbose:
            cmd.append('-v')
        logging.debug('Starting CNS server: %s ', ' '.join(cmd))

        self._cns_process = subprocess.Popen(cmd, stderr=subprocess.PIPE)
        ProcessLogger(self._cns_process)

        if self.WaitUntil(self._CanAccessServer,
                          retry_sleep=3,
                          timeout=30,
                          debug=False):
            pyauto.PyUITest.setUp(self)
        else:
            self.tearDown()
            self.fail('Failed to start CNS.')
コード例 #3
0
  def _StartPywebsocketServer(self):
    """Starts the pywebsocket server."""
    print 'Starting pywebsocket server.'

    # Pywebsocket source directory.
    path_pyws_dir = os.path.join(pyauto_paths.GetThirdPartyDir(), 'pywebsocket',
                                 'src')

    # Pywebsocket standalone server.
    path_to_pywebsocket= os.path.join(path_pyws_dir, 'mod_pywebsocket',
                                      'standalone.py')

    # Path to the data handler to handle data received by the server.
    path_to_handler = os.path.join(pyauto_paths.GetSourceDir(), 'chrome',
                                   'test', 'functional')

    # The python interpreter binary.
    python_interp = sys.executable

    # The pywebsocket start command - we could add --log-level=debug for debug.
    # -p stands for port, -d stands for root_directory (where the data handlers
    # are).
    start_cmd = [python_interp, path_to_pywebsocket,
                 '-p', _PYWEBSOCKET_PORT_NUMBER,
                 '-d', path_to_handler,]
    env = os.environ
    # Set PYTHONPATH to include the pywebsocket base directory.
    env['PYTHONPATH'] = (path_pyws_dir + os.path.pathsep +
                         env.get('PYTHONPATH', ''))

    # Start the pywebsocket server. The server will not start instantly, so the
    # code opening websockets to it should take this into account.
    self._pywebsocket_server = subprocess.Popen(start_cmd, env=env)
コード例 #4
0
  def setUp(self):
    """Starts the Constrained Network Server (CNS)."""
    cmd = [sys.executable, os.path.join(pyauto_paths.GetSourceDir(), _CNS_PATH),
           '--port', str(_CNS_PORT),
           '--interface', 'lo',
           '--www-root', os.path.join(
               self.DataDir(), 'pyauto_private', 'media'),
           '-v',
           '--expiry-time', '0']

    process = subprocess.Popen(cmd, stderr=subprocess.PIPE)

    # Wait for server to start up.
    line = True
    while line:
      line = process.stderr.readline()
      logging.debug(line.strip())
      if 'STARTED' in line:
        self._server_pid = process.pid
        pyauto.PyUITest.setUp(self)
        ProcessLogger(process)
        if self._CanAccessServer():
          return
        # Need to call teardown since the server has already started.
        self.tearDown()
    self.fail('Failed to start CNS.')
コード例 #5
0
ファイル: cns_test_base.py プロジェクト: rosas/chromium-1
    def setUp(self):
        """Starts the Constrained Network Server (CNS)."""
        cmd = [
            sys.executable,
            os.path.join(pyauto_paths.GetSourceDir(), _CNS_PATH), '--port',
            str(_CNS_PORT), '--interface', 'lo', '--www-root',
            os.path.join(self.DataDir(), 'pyauto_private', 'media'), '-v',
            '--expiry-time', '0'
        ]

        self._cns_process = subprocess.Popen(cmd, stderr=subprocess.PIPE)
        ProcessLogger(self._cns_process)

        if self.WaitUntil(self._CanAccessServer,
                          retry_sleep=3,
                          timeout=30,
                          debug=False):
            pyauto.PyUITest.setUp(self)
        else:
            self.tearDown()
            self.fail('Failed to start CNS.')
コード例 #6
0
  def setUp(self):
    """Sets up the platform for policy testing.

    On ChromeOS, part of the set up involves restarting the session_manager and
    logging in with the $default account.
    """
    if self.IsChromeOS():
      # Setup a temporary data dir and a TestServer serving files from there.
      # The TestServer makes its document root relative to the src dir.
      self._temp_data_dir = tempfile.mkdtemp(dir=pyauto_paths.GetSourceDir())
      relative_temp_data_dir = os.path.basename(self._temp_data_dir)
      self._http_server = self.StartHTTPServer(relative_temp_data_dir)

      # Setup empty policies, so that the TestServer can start replying.
      self._SetCloudPolicies()

      device_dmtoken = self._RegisterAndGetDMToken(device=True)
      policy = self._FetchPolicy(token=device_dmtoken, device=True)
      user_dmtoken = self._RegisterAndGetDMToken(device=False)

      # The device policy blob is only picked up by the session manager on
      # startup, and is overwritten on shutdown. So the blob has to be written
      # while the session manager is stopped.
      self.WaitForSessionManagerRestart(
          lambda: self._WriteDevicePolicyWithSessionManagerStopped(policy))
      logging.debug('Session manager restarted with device policy ready')

    pyauto.PyUITest.setUp(self)

    if self.IsChromeOS():
      logging.debug('Logging in')
      credentials = self.GetPrivateInfo()['prod_enterprise_test_user']
      self.Login(credentials['username'], credentials['password'])
      assert self.GetLoginInfo()['is_logged_in']

      self._WriteUserPolicyToken(user_dmtoken)
      # The browser has to be reloaded to make the user policy token cache
      # reload the file just written. The file can also be written only after
      # the cryptohome is mounted, after login.
      self.RestartBrowser(clear_profile=False)
コード例 #7
0
ファイル: policy_base.py プロジェクト: Devic1573/Chromium
    def setUp(self):
        """Sets up the platform for policy testing.

    On ChromeOS, part of the setup involves restarting the session manager to
    inject a device policy blob.
    """
        if self.IsChromeOS():
            # Set up a temporary data dir and a TestServer serving files from there.
            # The TestServer makes its document root relative to the src dir.
            source_dir = os.path.normpath(pyauto_paths.GetSourceDir())
            self._temp_data_dir = tempfile.mkdtemp(dir=source_dir)
            relative_temp_data_dir = os.path.basename(self._temp_data_dir)
            self._http_server = self.StartHTTPServer(relative_temp_data_dir)

            # Set up an empty user policy so that the TestServer can start replying.
            self._SetUserPolicyChromeOS()

            # Generate a key pair for signing device policy.
            self._private_key = tlslite.api.generateRSAKey(1024)
            algorithm = asn1der.Sequence([
                asn1der.Data(asn1der.OBJECT_IDENTIFIER, PKCS1_RSA_OID),
                asn1der.Data(asn1der.NULL, '')
            ])
            rsa_pubkey = asn1der.Sequence([
                asn1der.Integer(self._private_key.n),
                asn1der.Integer(self._private_key.e)
            ])
            self._public_key = asn1der.Sequence(
                [algorithm, asn1der.Bitstring(rsa_pubkey)])

            # Clear device policy. This also invokes pyauto.PyUITest.setUp(self).
            self.SetDevicePolicy()

            # Remove any existing vaults.
            self.RemoveAllCryptohomeVaultsOnChromeOS()
        else:
            pyauto.PyUITest.setUp(self)
コード例 #8
0
ファイル: policy_base.py プロジェクト: Havok380/chromium-test
    def _SetUpWithSessionManagerStopped(self):
        """Sets up the test environment after stopping the session manager."""
        assert self.IsChromeOS()
        logging.debug('Stopping session manager')
        cros_ui.stop(allow_fail=True)

        # Start mock GAIA server.
        self._auth_server = auth_server.GoogleAuthServer()
        self._auth_server.run()

        # Disable TPM if present.
        if os.path.exists(TPM_SYSFS_PATH):
            self._Call('mount -t tmpfs -o size=1k tmpfs %s' %
                       os.path.realpath(TPM_SYSFS_PATH),
                       check=True)
            self._WriteFile(TPM_SYSFS_ENABLED_FILE, '0')

        # Clear install attributes and restart cryptohomed to pick up the change.
        self._ClearInstallAttributesOnChromeOS()

        # Set install attributes to mock enterprise enrollment.
        bus = dbus.SystemBus()
        proxy = bus.get_object('org.chromium.Cryptohome',
                               '/org/chromium/Cryptohome')
        install_attributes = {
            'enterprise.device_id': self.device_id,
            'enterprise.domain': string.split(self.owner, '@')[-1],
            'enterprise.mode': self.mode,
            'enterprise.owned': 'true',
            'enterprise.user': self.owner
        }
        interface = dbus.Interface(proxy, 'org.chromium.CryptohomeInterface')
        for name, value in install_attributes.iteritems():
            interface.InstallAttributesSet(name, '%s\0' % value)
        interface.InstallAttributesFinalize()

        # Start mock DNS server that redirects all traffic to 127.0.0.1.
        self._dns_server = dns_server.LocalDns()
        self._dns_server.run()

        # Start mock DMServer.
        source_dir = os.path.normpath(pyauto_paths.GetSourceDir())
        self._temp_data_dir = tempfile.mkdtemp(dir=source_dir)
        logging.debug('TestServer input path: %s' % self._temp_data_dir)
        relative_temp_data_dir = os.path.basename(self._temp_data_dir)
        self._http_server = self.StartHTTPServer(relative_temp_data_dir)

        # Initialize the policy served.
        self._device_policy = {}
        self._user_policy = {}
        self._WritePolicyOnChromeOS()

        # Register with mock DMServer and retrieve initial device policy blob.
        dm_token = self._DMRegisterDevice()
        policy = self._DMFetchPolicy(dm_token)

        # Write the initial device policy blob.
        self._WriteFile(constants.OWNER_KEY_FILE, policy.new_public_key)
        self._WriteFile(constants.SIGNED_POLICY_FILE,
                        policy.SerializeToString())

        # Remove any existing vaults.
        self.RemoveAllCryptohomeVaultsOnChromeOS()

        # Restart session manager and Chrome.
        self._StartSessionManagerAndChrome()