It("connects using invalid URL", func() {
			errMsg := "Invalid consumerProxyFunc URL"
			consumerProxyFunc = func(*http.Request) (*url.URL, error) {
				return nil, errors.New(errMsg)
			}

			perform()

			var err error
			Eventually(errorChan).Should(Receive(&err))
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring(errMsg))
		})

		It("connects to a consumerProxyFunc server rejecting CONNECT requests", func() {
			goProxyHandler.OnRequest().HandleConnect(goproxy.AlwaysReject)

			perform()

			var err error
			Eventually(errorChan).Should(Receive(&err))
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("Error dialing traffic controller server"))
		})

		It("connects to a non-consumerProxyFunc server", func() {
			nonProxyServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
				http.Error(w, "Go away, I am not a consumerProxyFunc!", http.StatusBadRequest)
			}))
			consumerProxyFunc = func(*http.Request) (*url.URL, error) {
				return url.Parse(nonProxyServer.URL)
Exemplo n.º 2
0
// ProxyBasic will force HTTP authentication before any request to the proxy is processed
func ProxyBasic(proxy *goproxy.ProxyHttpServer, realm string, f func(user, passwd string) bool) {
	proxy.OnRequest().Do(Basic(realm, f))
	proxy.OnRequest().HandleConnect(BasicConnect(realm, f))
}
		Context("with a message in the trafficcontroller", func() {
			BeforeEach(func() {
				messagesToSend <- marshalMessage(createMessage("hello", 0))
			})

			It("connects using valid URL to running proxy server", func() {
				message := <-incoming
				Expect(message.GetLogMessage().GetMessage()).To(Equal([]byte("hello")))
			})
		})

		Context("with an auth proxy server", func() {
			BeforeEach(func() {
				goProxyHandler.OnRequest().HandleConnect(auth.BasicConnect("my_realm", func(user, passwd string) bool {
					return user == "user" && passwd == "password"
				}))
				proxy = func(*http.Request) (*url.URL, error) {
					proxyURL, err := url.Parse(testProxyServer.URL)
					proxyURL.User = url.UserPassword("user", "password")
					if err != nil {
						return nil, err
					}

					return proxyURL, nil
				}
				messagesToSend <- marshalMessage(createMessage("hello", 0))
			})

			It("connects successfully", func() {
				message := <-incoming