コード例 #1
0
  def setUp(self):
    super(HTTPApiEndToEndTestProgram, self).setUp()

    # Set up HTTP server
    port = portpicker.PickUnusedPort()
    HTTPApiEndToEndTestProgram.server_port = port
    logging.info("Picked free AdminUI port for HTTP %d.", port)

    self.trd = wsgiapp_testlib.ServerThread(port)
    self.trd.StartAndWaitUntilServing()
コード例 #2
0
    def setUp(self):
        super(SeleniumTestProgram, self).setUp()
        # Select a free port
        port = portpicker.PickUnusedPort()
        logging.info("Picked free AdminUI port %d.", port)

        # Start up a server in another thread
        self.trd = wsgiapp_testlib.ServerThread(port)
        self.trd.StartAndWaitUntilServing()
        self.SetupSelenium(port)
コード例 #3
0
    def setUp(self):
        super(ApiSSLE2ETest, self).setUp()

        key = rdf_crypto.RSAPrivateKey.GenerateKey()
        key_path = os.path.join(self.temp_dir, "key.pem")
        with open(key_path, "wb") as f:
            f.write(key.AsPEM())

        subject = issuer = x509.Name([
            x509.NameAttribute(oid.NameOID.COMMON_NAME, u"localhost"),
        ])

        cert = x509.CertificateBuilder().subject_name(subject).issuer_name(
            issuer).public_key(
                key.GetPublicKey().GetRawPublicKey()).serial_number(
                    x509.random_serial_number()).not_valid_before(
                        datetime.datetime.utcnow()).not_valid_after(
                            datetime.datetime.utcnow() +
                            datetime.timedelta(days=1)).add_extension(
                                x509.SubjectAlternativeName(
                                    [x509.DNSName(u"localhost")]),
                                critical=False,
                            ).sign(key.GetRawPrivateKey(), hashes.SHA256(),
                                   backends.default_backend())

        cert_path = os.path.join(self.temp_dir, "certificate.pem")
        with open(cert_path, "wb") as f:
            f.write(cert.public_bytes(serialization.Encoding.PEM))

        self.config_overrider = test_lib.ConfigOverrider({
            "AdminUI.enable_ssl":
            True,
            "AdminUI.ssl_key_file":
            key_path,
            "AdminUI.ssl_cert_file":
            cert_path,
        })
        self.config_overrider.Start()

        self.prev_environ = dict(os.environ)
        os.environ["REQUESTS_CA_BUNDLE"] = cert_path

        self.port = portpicker.PickUnusedPort()
        self.thread = wsgiapp_testlib.ServerThread(self.port)
        self.thread.StartAndWaitUntilServing()

        api_auth_manager.APIACLInit.InitApiAuthManager()
        self.token.username = "******"
        webauth.WEBAUTH_MANAGER.SetUserName(self.token.username)

        self.endpoint = "https://localhost:%s" % self.port
        self.api = grr_api.InitHttp(api_endpoint=self.endpoint)
コード例 #4
0
  def setUpClass(cls):
    super(ApiE2ETest, cls).setUpClass()
    with ApiE2ETest._api_set_up_lock:
      if not ApiE2ETest._api_set_up_done:

        # Set up HTTP server
        port = portpicker.PickUnusedPort()
        ApiE2ETest.server_port = port
        logging.info("Picked free AdminUI port for HTTP %d.", port)

        ApiE2ETest.trd = wsgiapp_testlib.ServerThread(port)
        ApiE2ETest.trd.StartAndWaitUntilServing()

        ApiE2ETest._api_set_up_done = True
コード例 #5
0
ファイル: gui_test_lib.py プロジェクト: lzbgt/grr
  def setUpClass(cls):
    super(GRRSeleniumTest, cls).setUpClass()
    with GRRSeleniumTest._selenium_set_up_lock:
      if not GRRSeleniumTest._selenium_set_up_done:

        port = portpicker.PickUnusedPort()
        logging.info("Picked free AdminUI port %d.", port)

        # Start up a server in another thread
        GRRSeleniumTest._server_trd = wsgiapp_testlib.ServerThread(port)
        GRRSeleniumTest._server_trd.StartAndWaitUntilServing()
        GRRSeleniumTest._SetUpSelenium(port)

        GRRSeleniumTest._selenium_set_up_done = True
コード例 #6
0
    def setUpClass(cls):  # pylint: disable=invalid-name
        if cls.api_version not in [1, 2]:
            raise ValueError("api_version may be 1 or 2 only")

        if not HttpApiRegressionTestMixinBase.endpoint:
            port = portpicker.PickUnusedPort()
            logging.info("Picked free AdminUI port %d.", port)

            # Force creation of new APIAuthorizationManager.
            api_auth_manager.APIACLInit.InitApiAuthManager()

            trd = wsgiapp_testlib.ServerThread(port)
            trd.StartAndWaitUntilServing()

            cls.endpoint = "http://localhost:%d" % port
コード例 #7
0
    def GetConnector(api_version):
        if api_version not in [1, 2]:
            raise ValueError("api_version may be 1 or 2 only")

        with _HTTP_ENDPOINTS_LOCK:
            if api_version not in _HTTP_ENDPOINTS:
                port = portpicker.PickUnusedPort()
                logging.info("Picked free AdminUI port %d.", port)

                # Force creation of new APIAuthorizationManager.
                api_auth_manager.APIACLInit.InitApiAuthManager()

                trd = wsgiapp_testlib.ServerThread(port)
                trd.StartAndWaitUntilServing()

                _HTTP_ENDPOINTS[api_version] = "http://localhost:%d" % port

            return http_connector.HttpConnector(
                api_endpoint=_HTTP_ENDPOINTS[api_version])