Merge pull request #77 from pivotal-cf-experimental/basic-auth
Ensure basic auth headers are provided
diff --git a/ghttp/handlers.go b/ghttp/handlers.go
index d27ad80..8c1668a 100644
--- a/ghttp/handlers.go
+++ b/ghttp/handlers.go
@@ -6,6 +6,7 @@
"fmt"
"io/ioutil"
"net/http"
+
. "github.com/onsi/gomega"
"github.com/onsi/gomega/types"
)
@@ -53,6 +54,8 @@
func VerifyBasicAuth(username string, password string) http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
auth := req.Header.Get("Authorization")
+ Ω(auth).ShouldNot(Equal(""), "Authorization header must be specified")
+
decoded, err := base64.StdEncoding.DecodeString(auth[6:])
Ω(err).ShouldNot(HaveOccurred())
diff --git a/ghttp/test_server_test.go b/ghttp/test_server_test.go
index 68ff0d4..793ca4a 100644
--- a/ghttp/test_server_test.go
+++ b/ghttp/test_server_test.go
@@ -290,6 +290,15 @@
Ω(failures).Should(HaveLen(1))
})
+ It("should require basic auth header", func() {
+ req, err := http.NewRequest("GET", s.URL()+"/foo", nil)
+ Ω(err).ShouldNot(HaveOccurred())
+
+ failures := InterceptGomegaFailures(func() {
+ http.DefaultClient.Do(req)
+ })
+ Ω(failures).Should(HaveLen(1))
+ })
})
Describe("VerifyHeader", func() {