func HTTPResponseShouldContainExpectedHTTPStatusCode(inputs *HTTPExampleInputs, expectedStatusCode int) {
	It(fmt.Sprint("returns HTTP ", expectedStatusCode), func() {
		code, _ := integration.ExecuteAuthenticatedHTTPRequest(inputs.Method, inputs.URI, brokerConfig.AuthConfiguration.Username, brokerConfig.AuthConfiguration.Password)

		Ω(code).To(Equal(expectedStatusCode))
	})
}
func getDebugInfo() debug.Info {
	_, bodyBytes := integration.ExecuteAuthenticatedHTTPRequest("GET", "http://localhost:3000/debug", brokerConfig.AuthConfiguration.Username, brokerConfig.AuthConfiguration.Password)
	debugInfo := debug.Info{}

	err := json.Unmarshal(bodyBytes, &debugInfo)
	Ω(err).ShouldNot(HaveOccurred())

	return debugInfo
}
func HTTPResponseBodyShouldBeEmptyJSON(inputs *HTTPExampleInputs) {
	It("returns empty JSON", func() {
		_, body := integration.ExecuteAuthenticatedHTTPRequest(inputs.Method, inputs.URI, brokerConfig.AuthConfiguration.Username, brokerConfig.AuthConfiguration.Password)

		var parsedJSON map[string][]interface{}
		json.Unmarshal(body, &parsedJSON)

		Ω(parsedJSON).To(Equal(map[string][]interface{}{}))
	})
}
func HTTPResponseShouldContainBrokerErrorMessage(inputs *HTTPExampleInputs, expectedErrorMessage string) {
	It("returns the expected error message", func() {
		_, body := integration.ExecuteAuthenticatedHTTPRequest(inputs.Method, inputs.URI, brokerConfig.AuthConfiguration.Username, brokerConfig.AuthConfiguration.Password)

		var parsedJSON map[string]interface{}
		json.Unmarshal(body, &parsedJSON)

		errorMessage := parsedJSON["description"].(string)
		Ω(errorMessage).Should(Equal(expectedErrorMessage))
	})
}
Exemplo n.º 5
0
var _ = Describe("Agent Security", func() {
	var session *gexec.Session

	BeforeEach(func() {
		session = startAgent()
	})

	AfterEach(func() {
		stopAgent(session)
	})

	Describe("Basic HTTP Authentication", func() {
		Context("With expected username and password", func() {
			It("returns HTTP code 200", func() {
				code, _ := integration.ExecuteAuthenticatedHTTPRequest("GET", "http://localhost:9876", "admin", "supersecretpassword")
				Ω(code).To(Equal(200))
			})
		})

		Context("With unexpected username and password", func() {
			It("returns HTTP code 401", func() {
				req, err := http.NewRequest("GET", "http://localhost:9876", nil)
				Ω(err).ToNot(HaveOccurred())

				req.SetBasicAuth("admin", "badpassword")
				resp, err := http.DefaultClient.Do(req)
				Ω(err).ToNot(HaveOccurred())

				Ω(resp.StatusCode).To(Equal(401))
			})
Exemplo n.º 6
0
package brokerintegration_test

import (
	"io/ioutil"
	"net/http"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/pivotal-cf/cf-redis-broker/integration"
)

var _ = Describe("Debug", func() {
	Context("when basic auth credentials are correct", func() {
		It("returns HTTP 200", func() {
			code, _ := integration.ExecuteAuthenticatedHTTPRequest("GET", "http://localhost:3000/debug", brokerConfig.AuthConfiguration.Username, brokerConfig.AuthConfiguration.Password)
			Ω(code).To(Equal(http.StatusOK))
		})

		It("returns JSON representing the  debug information", func() {
			debugInfo := getDebugInfo()

			Ω(debugInfo.Pool.Count).Should(Equal(3))
			Ω(debugInfo.Pool.Clusters).Should(ContainElement([]string{"server1.127.0.0.1.xip.io"}))
			Ω(debugInfo.Pool.Clusters).Should(ContainElement([]string{"server2.127.0.0.1.xip.io"}))
			Ω(debugInfo.Pool.Clusters).Should(ContainElement([]string{"server3.127.0.0.1.xip.io"}))
			Ω(len(debugInfo.Pool.Clusters)).Should(Equal(3))
		})

		Context("recycling instances", func() {
			var host string