Beispiel #1
0
import (
	"net/http"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/robdimsdale/garagepi/middleware"
	"github.com/robdimsdale/garagepi/middleware/fakes"
)

var _ = Describe("Logger", func() {

	var dummyRequest *http.Request
	var err error

	var fakeResponseWriter http.ResponseWriter
	var fakeHandler *fakes.FakeHandler
	var fakeLogger *fakes.FakeLogger

	BeforeEach(func() {
		dummyRequest, err = http.NewRequest("GET", "/some-url", nil)
		Expect(err).NotTo(HaveOccurred())
		dummyRequest.Header.Add("Authorization", "some auth")

		fakeResponseWriter = &fakes.FakeResponseWriter{}
		fakeHandler = &fakes.FakeHandler{}
		fakeLogger = &fakes.FakeLogger{}
	})

	It("should not log credentials", func() {
		loggerMiddleware := middleware.NewLogger(fakeLogger)
		loggerHandler := loggerMiddleware.Wrap(fakeHandler)
	"net/http"
	"net/http/httptest"

	"github.com/robdimsdale/garagepi/middleware"
	"github.com/robdimsdale/garagepi/middleware/fakes"

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

var _ = Describe("HttpsEnforcer", func() {
	const httpsPort = uint(34567)

	var (
		request           *http.Request
		writer            *httptest.ResponseRecorder
		fakeHandler       *fakes.FakeHandler
		wrappedMiddleware http.Handler
	)

	BeforeEach(func() {
		fakeHandler = &fakes.FakeHandler{}
		writer = httptest.NewRecorder()
		enforcer := middleware.NewHTTPSEnforcer(httpsPort)

		wrappedMiddleware = enforcer.Wrap(fakeHandler)
	})

	Context("when the URL is valid", func() {
		BeforeEach(func() {
			var err error
			request, err = http.NewRequest("GET", "http://localhost/foo/bar", nil)