Exemplo n.º 1
0
func shouldEcho(input string, expected string) {
	ln := registerHandler(r, "encoding", func(x *test_util.HttpConn) {
		x.CheckLine("GET " + expected + " HTTP/1.1")
		resp := test_util.NewResponse(http.StatusOK)
		x.WriteResponse(resp)
		x.Close()
	})
	defer ln.Close()

	x := dialProxy(proxyServer)

	req := test_util.NewRequest("GET", "encoding", input, nil)
	x.WriteRequest(req)
	resp, _ := x.ReadResponse()

	Expect(resp.StatusCode).To(Equal(http.StatusOK))
}
Exemplo n.º 2
0
			conf.RouteServiceEnabled = false
			conf.SkipSSLValidation = true
			routeServiceHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
				Fail("Should not get here into Route Service")
			})
		})

		It("return 502 Bad Gateway", func() {
			ln := registerHandlerWithRouteService(r, "my_host.com", "https://"+routeServiceListener.Addr().String(), func(conn *test_util.HttpConn) {
				Fail("Should not get here into the app")
			})
			defer ln.Close()

			conn := dialProxy(proxyServer)

			req := test_util.NewRequest("GET", "my_host.com", "/", nil)

			conn.WriteRequest(req)

			res, body := conn.ReadResponse()
			Expect(res.StatusCode).To(Equal(http.StatusBadGateway))
			Expect(body).To(ContainSubstring("Support for route services is disabled."))
		})
	})

	Context("with Route Services enabled", func() {
		BeforeEach(func() {
			conf.RouteServiceEnabled = true
			conf.SkipSSLValidation = true
		})
Exemplo n.º 3
0
		handler      negroni.Handler
		headersToLog *[]string
		logger       lager.Logger
		resp         http.ResponseWriter
		req          *http.Request
		nextCalled   bool
	)

	nextHandler := http.HandlerFunc(func(http.ResponseWriter, *http.Request) {
		nextCalled = true
	})

	BeforeEach(func() {
		headersToLog = &[]string{}
		logger = lagertest.NewTestLogger("zipkin")
		req = test_util.NewRequest("GET", "example.com", "/", nil)
		resp = httptest.NewRecorder()
		nextCalled = false
	})

	AfterEach(func() {
		Expect(nextCalled).To(BeTrue(), "Expected the next handler to be called.")
	})

	Context("with Zipkin enabled", func() {
		BeforeEach(func() {
			handler = handlers.NewZipkin(true, headersToLog, logger)
		})

		It("sets zipkin headers", func() {
			handler.ServeHTTP(resp, req, nextHandler)
		var (
			proxyRoundTripper http.RoundTripper
			endpointIterator  *routefakes.FakeEndpointIterator
			transport         *roundtripperfakes.FakeRoundTripper
			logger            lager.Logger
			req               *http.Request
			resp              *proxyfakes.FakeProxyResponseWriter
			dialError         = &net.OpError{
				Err: errors.New("error"),
				Op:  "dial",
			}
		)

		BeforeEach(func() {
			endpointIterator = &routefakes.FakeEndpointIterator{}
			req = test_util.NewRequest("GET", "myapp.com", "/", nil)
			req.URL.Scheme = "http"
			resp = &proxyfakes.FakeProxyResponseWriter{}

			logger = lagertest.NewTestLogger("test")
			transport = &roundtripperfakes.FakeRoundTripper{}
		})

		Context("backend", func() {
			BeforeEach(func() {
				endpoint := &route.Endpoint{
					Tags: map[string]string{},
				}

				endpointIterator.NextReturns(endpoint)
Exemplo n.º 5
0
				SecureCookies:        conf.SecureCookies,
				TLSConfig:            tlsConfig,
				RouteServiceEnabled:  conf.RouteServiceEnabled,
				RouteServiceTimeout:  conf.RouteServiceTimeout,
				Crypto:               crypto,
				CryptoPrev:           cryptoPrev,
				HealthCheckUserAgent: "HTTP-Monitor/1.1",
			})

			r.Register(route.Uri("some-app"), &route.Endpoint{})
		})

		Context("when backend fails to respond", func() {
			It("logs the error and associated endpoint", func() {
				body := []byte("some body")
				req := test_util.NewRequest("GET", "some-app", "/", bytes.NewReader(body))
				resp := httptest.NewRecorder()

				proxyObj.ServeHTTP(resp, req)

				Eventually(logger).Should(Say("error"))
				Eventually(logger).Should(Say("route-endpoint"))
			})
		})

		Context("Log response time", func() {
			It("logs response time for HTTP connections", func() {
				body := []byte("some body")
				req := test_util.NewRequest("GET", "some-app", "/", bytes.NewReader(body))
				resp := httptest.NewRecorder()
			Value:   "xxx",
			MaxAge:  1,
			Expires: time.Now(),
		}
	})

	Context("context paths", func() {
		Context("when two requests have the same context paths", func() {
			It("responds with the same instance id", func() {
				ln := registerHandlerWithInstanceId(r, "app.com/path1", "", responseWithJSessionID, "instance-id-1")
				defer ln.Close()
				ln2 := registerHandlerWithInstanceId(r, "app.com/path2/context/path", "", responseWithJSessionID, "instance-id-2")
				defer ln2.Close()

				conn := dialProxy(proxyServer)
				req := test_util.NewRequest("GET", "app.com", "/path1/some/sub/path/index.html", nil)
				conn.WriteRequest(req)

				Eventually(done).Should(Receive())

				resp, _ := conn.ReadResponse()
				cookie := getCookie(proxy.VcapCookieId, resp.Cookies())
				Expect(cookie).ToNot(BeNil())
				Expect(cookie.Path).To(Equal("/path1"))
				Expect(cookie.Value).To(Equal("instance-id-1"))

				req2 := test_util.NewRequest("GET", "app.com", "/path1/other/sub/path/index.html", nil)
				conn.WriteRequest(req2)

				Eventually(done).Should(Receive())
Exemplo n.º 7
0
			localIP, err = localip.LocalIP()
			Expect(err).ToNot(HaveOccurred())

			statusPort = test_util.NextAvailPort()
			proxyPort = test_util.NextAvailPort()

			cfgFile = filepath.Join(tmpdir, "config.yml")
			config = createConfig(cfgFile, statusPort, proxyPort, defaultPruneInterval, defaultPruneThreshold, 1, false, natsPort)
		})

		JustBeforeEach(func() {
			gorouterSession = startGorouterSession(cfgFile)
		})

		It("responds to healthcheck", func() {
			req := test_util.NewRequest("GET", "", "/", nil)
			req.Header.Set("User-Agent", "HTTP-Monitor/1.1")
			conn, err := net.Dial("tcp", fmt.Sprintf("localhost:%d", proxyPort))
			Expect(err).ToNot(HaveOccurred())
			http_conn := test_util.NewHttpConn(conn)
			http_conn.WriteRequest(req)
			resp, body := http_conn.ReadResponse()
			Expect(resp.Status).To(Equal("200 OK"))
			Expect(body).To(Equal("ok\n"))
		})

		It("waits for all requests to finish", func() {
			mbusClient, err := newMessageBus(config)
			Expect(err).ToNot(HaveOccurred())

			requestMade := make(chan bool)
Exemplo n.º 8
0
		})

		app.Listen()
		go app.RegisterRepeatedly(1 * time.Second)

		Eventually(func() bool {
			return appRegistered(registry, app)
		}).Should(BeTrue())

		conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", config.Ip, config.Port))
		Expect(err).NotTo(HaveOccurred())
		defer conn.Close()

		httpConn := test_util.NewHttpConn(conn)

		req := test_util.NewRequest("GET", "foo.vcap.me", "/", nil)
		req.Header.Add(router_http.VcapRequestIdHeader, "A-BOGUS-REQUEST-ID")

		httpConn.WriteRequest(req)

		var answer string
		Eventually(done).Should(Receive(&answer))
		Expect(answer).ToNot(Equal("A-BOGUS-REQUEST-ID"))
		Expect(answer).To(MatchRegexp(uuid_regex))
		Expect(logger).To(gbytes.Say("vcap-request-id-header-set"))

		resp, _ := httpConn.ReadResponse()
		Expect(resp.StatusCode).To(Equal(http.StatusOK))
	})

	It("handles a /routes request", func() {
Exemplo n.º 9
0
			conn.WriteResponse(test_util.NewResponse(http.StatusOK))
		})
		defer lnWithoutSlash.Close()

		lnWithSlash := registerHandler(r, "test/another-path/your_path/", func(conn *test_util.HttpConn) {
			conn.CheckLine("GET /another-path/your_path HTTP/1.1")

			conn.WriteResponse(test_util.NewResponse(http.StatusOK))
		})
		defer lnWithSlash.Close()

		conn := dialProxy(proxyServer)
		y := dialProxy(proxyServer)

		req := test_util.NewRequest("GET", "test", "/my%20path/your_path/", nil)
		conn.WriteRequest(req)

		resp, _ := conn.ReadResponse()
		Expect(resp.StatusCode).To(Equal(http.StatusOK))

		req = test_util.NewRequest("GET", "test", "/another-path/your_path", nil)
		y.WriteRequest(req)

		resp, _ = y.ReadResponse()
		Expect(resp.StatusCode).To(Equal(http.StatusOK))
	})

	It("Content-type is not set by proxy", func() {
		ln := registerHandler(r, "content-test", func(x *test_util.HttpConn) {
			_, err := http.ReadRequest(x.Reader)