func (s *ProxySuite) TestLogsRequest(c *C) {
	var fakeFile = new(test_util.FakeFile)
	accessLog := access_log.NewFileAndLoggregatorAccessLogger(fakeFile, "localhost:9843", "secret", 42)
	s.p.AccessLogger = accessLog
	go accessLog.Run()

	s.RegisterHandler(c, "test", func(x *httpConn) {
		x.CheckLine("GET / HTTP/1.1")

		x.WriteLines([]string{
			"HTTP/1.1 200 OK",
			"Content-Length: 0",
		})
	})

	x := s.DialProxy(c)

	x.WriteLines([]string{
		"GET / HTTP/1.0",
		"Host: test",
	})

	x.CheckLine("HTTP/1.0 200 OK")

	c.Assert(string(fakeFile.Payload), Matches, "^test.*\n")
	//make sure the record includes all the data
	//since the building of the log record happens throughout the life of the request
	c.Assert(string(fakeFile.Payload), Matches, ".*200.*\n")
}
示例#2
0
func (s *ProxySuite) SetUpTest(c *C) {
	s.conf = config.DefaultConfig()
	s.conf.TraceKey = "my_trace_key"
	s.conf.EndpointTimeout = 500 * time.Millisecond

	mbus := fakeyagnats.New()

	s.r = registry.NewCFRegistry(s.conf, mbus)
	fmt.Printf("Config: %#v", s.conf)

	s.accessLogFile = new(test_util.FakeFile)
	accessLog := access_log.NewFileAndLoggregatorAccessLogger(s.accessLogFile, "localhost:9843", "secret", 42)
	go accessLog.Run()

	s.p = NewProxy(ProxyArgs{
		EndpointTimeout: s.conf.EndpointTimeout,
		Ip:              s.conf.Ip,
		TraceKey:        s.conf.TraceKey,
		Registry:        s.r,
		Reporter:        nullVarz{},
		Logger:          accessLog,
	})

	ln, err := net.Listen("tcp", "127.0.0.1:0")
	if err != nil {
		panic(err)
	}

	server := server.Server{Handler: s.p}
	go server.Serve(ln)

	s.proxyServer = ln
}
func (s *ProxySuite) TestLogsRequestWhenExitsEarly(c *C) {
	var fakeFile = new(test_util.FakeFile)
	accessLog := access_log.NewFileAndLoggregatorAccessLogger(fakeFile, "localhost:9843", "secret", 42)
	s.p.AccessLogger = accessLog
	go accessLog.Run()

	x := s.DialProxy(c)

	x.WriteLines([]string{
		"GET / HTTP/0.9",
		"Host: test",
	})

	x.CheckLine("HTTP/1.0 400 Bad Request")

	c.Assert(string(fakeFile.Payload), Matches, "^test.*\n")
}
	conf = config.DefaultConfig()
	conf.TraceKey = "my_trace_key"
	conf.EndpointTimeout = 500 * time.Millisecond
})

var _ = JustBeforeEach(func() {
	var err error
	mbus := fakeyagnats.Connect()
	r = registry.NewRouteRegistry(logger, conf, mbus, new(fakes.FakeRouteRegistryReporter))

	fakeEmitter := fake.NewFakeEventEmitter("fake")
	dropsonde.InitializeWithEmitter(fakeEmitter)

	accessLogFile = new(test_util.FakeFile)
	accessLog = access_log.NewFileAndLoggregatorAccessLogger(logger, "", accessLogFile)
	go accessLog.Run()

	conf.EnableSSL = true
	conf.CipherSuites = []uint16{tls.TLS_RSA_WITH_AES_256_CBC_SHA}

	tlsConfig := &tls.Config{
		CipherSuites:       conf.CipherSuites,
		InsecureSkipVerify: conf.SSLSkipValidation,
	}

	p = proxy.NewProxy(proxy.ProxyArgs{
		EndpointTimeout:     conf.EndpointTimeout,
		Ip:                  conf.Ip,
		TraceKey:            conf.TraceKey,
		Logger:              logger,
	var conf *config.Config
	var proxyServer net.Listener
	var accessLog access_log.AccessLogger
	var accessLogFile *test_util.FakeFile

	BeforeEach(func() {
		conf = config.DefaultConfig()
		conf.TraceKey = "my_trace_key"
		conf.EndpointTimeout = 500 * time.Millisecond

		mbus := fakeyagnats.New()

		r = registry.NewRouteRegistry(conf, mbus)

		accessLogFile = new(test_util.FakeFile)
		accessLog = access_log.NewFileAndLoggregatorAccessLogger(accessLogFile, nil)
		go accessLog.Run()

		p = NewProxy(ProxyArgs{
			EndpointTimeout: conf.EndpointTimeout,
			Ip:              conf.Ip,
			TraceKey:        conf.TraceKey,
			Registry:        r,
			Reporter:        nullVarz{},
			AccessLogger:    accessLog,
		})

		ln, err := net.Listen("tcp", "127.0.0.1:0")
		Ω(err).NotTo(HaveOccurred())

		server := http.Server{Handler: p}