Ejemplo n.º 1
0
func wrapAuth(router httpRouter, credentials BrokerCredentials) http.Handler {
	return auth.NewWrapper(credentials.Username, credentials.Password).Wrap(router)
}
Ejemplo n.º 2
0
	}

	BeforeEach(func() {
		username = "******"
		password = "******"
		httpRecorder = httptest.NewRecorder()
	})

	Describe("wrapped handler", func() {
		var wrappedHandler http.Handler

		BeforeEach(func() {
			handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
				w.WriteHeader(http.StatusCreated)
			})
			wrappedHandler = auth.NewWrapper(username, password).Wrap(handler)
		})

		It("works when the credentials are correct", func() {
			request := newRequest(username, password)
			wrappedHandler.ServeHTTP(httpRecorder, request)
			Expect(httpRecorder.Code).To(Equal(http.StatusCreated))
		})

		It("fails when the username is empty", func() {
			request := newRequest("", password)
			wrappedHandler.ServeHTTP(httpRecorder, request)
			Expect(httpRecorder.Code).To(Equal(http.StatusUnauthorized))
		})

		It("fails when the password is empty", func() {