"github.com/cloudfoundry/noaa/consumer"
	"github.com/cloudfoundry/sonde-go/events"
	"github.com/elazarl/goproxy"
	"github.com/elazarl/goproxy/ext/auth"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Consumer connecting through a Proxy", func() {
	var (
		connection *consumer.Consumer

		messagesToSend chan []byte
		testServer     *httptest.Server
		endpoint       string
		proxy          func(*http.Request) (*url.URL, error)

		testProxyServer *httptest.Server
		goProxyHandler  *goproxy.ProxyHttpServer
	)

	BeforeEach(func() {
		messagesToSend = make(chan []byte, 256)
		testServer = httptest.NewServer(handlers.NewWebsocketHandler(messagesToSend, 100*time.Millisecond, loggertesthelper.Logger()))
		endpoint = "ws://" + testServer.Listener.Addr().String()

		goProxyHandler = goproxy.NewProxyHttpServer()
		goProxyHandler.Logger = log.New(bytes.NewBufferString(""), "", 0)
		testProxyServer = httptest.NewServer(goProxyHandler)
		proxy = func(*http.Request) (*url.URL, error) {
Esempio n. 2
0
type nullHandler chan struct{}

func (h nullHandler) ServeHTTP(http.ResponseWriter, *http.Request) {
	<-h
}

const (
	appGuid     = "fakeAppGuid"
	authToken   = "fakeAuthToken"
	testTimeout = 1 * time.Second
)

var (
	cnsmr       *consumer.Consumer
	testServer  *httptest.Server
	fakeHandler nullHandler
)

var _ = Describe("Timeout", func() {
	AfterSuite(func() {
		if testServer != nil {
			testServer.Close()
		}
	})

	BeforeEach(func() {
		internal.Timeout = testTimeout

		fakeHandler = make(nullHandler, 1)
		testServer = httptest.NewServer(fakeHandler)
Esempio n. 3
0
	"github.com/cloudfoundry/noaa/consumer"
	"github.com/cloudfoundry/noaa/test_helpers"
	"github.com/cloudfoundry/sonde-go/events"
	"github.com/gogo/protobuf/proto"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Consumer (Asynchronous)", func() {
	var (
		cnsmr                *consumer.Consumer
		trafficControllerURL string
		testServer           *httptest.Server
		fakeHandler          *test_helpers.FakeHandler
		tlsSettings          *tls.Config

		appGuid        string
		authToken      string
		messagesToSend chan []byte
	)

	BeforeEach(func() {
		trafficControllerURL = ""
		testServer = nil
		fakeHandler = nil
		tlsSettings = nil

		appGuid = ""
		authToken = ""
		messagesToSend = make(chan []byte, 256)
	"time"

	"github.com/cloudfoundry/loggregatorlib/loggertesthelper"
	"github.com/cloudfoundry/loggregatorlib/server/handlers"
	"github.com/cloudfoundry/noaa/consumer"

	. "github.com/apoydence/eachers"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("RefreshTokenFrom", func() {
	Context("Asynchronous", func() {
		var (
			cnsmr       *consumer.Consumer
			testHandler *errorRespondingHandler
			tcURL       string
			refresher   *mockTokenRefresher
		)

		BeforeEach(func() {
			testHandler = &errorRespondingHandler{
				subHandler:       handlers.NewWebsocketHandler(make(chan []byte), 100*time.Millisecond, loggertesthelper.Logger()),
				responseStatuses: make(chan int, 10),
			}
			server := httptest.NewServer(testHandler)
			tcURL = "ws://" + server.Listener.Addr().String()

			refresher = newMockTokenRefresher()
			cnsmr = consumer.New(tcURL, nil, nil)

			cnsmr.RefreshTokenFrom(refresher)
Esempio n. 5
0
			BeforeEach(func() {
				count = 100
			})

			JustBeforeEach(func() {
				for i := 0; i < count; i++ {
					time.Sleep(10 * time.Millisecond)
					helpers.EmitToMetron(buildValueMetric("mainValue", float64(i)))
				}
			})

			Context("single connection", func() {
				var (
					reader *consumer.Consumer
					msgs   <-chan *events.Envelope
					errs   <-chan error
				)

				JustBeforeEach(func() {
					go emitControlMessages()
					waitForControl(msgs)
				})

				BeforeEach(func() {
					reader, _ = helpers.SetUpConsumer()
					msgs, errs = reader.Firehose(generateSubID(), "")
					go readFromErrors(errs)
				})

				AfterEach(func() {
Esempio n. 6
0
	"github.com/cloudfoundry/noaa/consumer"
	"github.com/cloudfoundry/noaa/errors"
	"github.com/cloudfoundry/noaa/test_helpers"
	"github.com/cloudfoundry/sonde-go/events"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Consumer (Synchronous)", func() {
	var (
		cnsmr                *consumer.Consumer
		trafficControllerURL string
		testServer           *httptest.Server
		fakeHandler          *test_helpers.FakeHandler
		tlsSettings          *tls.Config

		appGuid        string
		authToken      string
		messagesToSend chan []byte
	)

	BeforeEach(func() {
		trafficControllerURL = ""
		testServer = nil
		fakeHandler = nil
		tlsSettings = nil

		appGuid = ""
		authToken = ""
		messagesToSend = make(chan []byte, 256)
		Expect(err).ToNot(HaveOccurred())
		Expect(testFile.Close()).To(Succeed())

		testContents = func() string {
			contents, err := ioutil.ReadFile(accessLogFile)
			Expect(err).ToNot(HaveOccurred())
			return string(contents)
		}
	})

	AfterEach(func() {
		Expect(os.Remove(accessLogFile)).To(Succeed())
	})

	Context("with modern endpoints", func() {
		var noaaConsumer *consumer.Consumer

		JustBeforeEach(func() {
			tcURL := fmt.Sprintf("ws://%s:%d", localIPAddress, TRAFFIC_CONTROLLER_DROPSONDE_PORT)
			noaaConsumer = consumer.New(tcURL, &tls.Config{}, nil)
		})

		AfterEach(func() {
			noaaConsumer.Close()
		})

		It("logs stream access", func() {
			noaaConsumer.Stream(APP_ID, AUTH_TOKEN)

			expected := fmt.Sprintf("CEF:0|cloud_foundry|loggregator_trafficcontroller|1.0|GET /apps/%s/stream|GET /apps/%[1]s/stream|0|", APP_ID)
			Eventually(testContents).Should(ContainSubstring(expected))
	var dropsondeEndpoint string

	BeforeEach(func() {
		fakeDoppler = fake_doppler.New()
		go fakeDoppler.Start()
		dropsondeEndpoint = fmt.Sprintf("ws://%s:%d", localIPAddress, TRAFFIC_CONTROLLER_DROPSONDE_PORT)
	})

	AfterEach(func() {
		fakeDoppler.Stop()
	})

	Context("Streaming", func() {
		var (
			client   *consumer.Consumer
			messages <-chan *events.Envelope
			errors   <-chan error
		)

		JustBeforeEach(func() {
			client = consumer.New(dropsondeEndpoint, &tls.Config{}, nil)
			messages, errors = client.StreamWithoutReconnect(APP_ID, AUTH_TOKEN)
		})

		It("passes messages through", func() {
			var request *http.Request
			Eventually(fakeDoppler.TrafficControllerConnected, 10).Should(Receive(&request))
			Expect(request.URL.Path).To(Equal("/apps/1234/stream"))

			currentTime := time.Now().UnixNano()
			dropsondeMessage := makeDropsondeMessage("Hello through NOAA", APP_ID, currentTime)