예제 #1
0
func TestXMLMinifierWOHeader(t *testing.T) {
	RegisterTestingT(t)

	// body can be nil here, it's not reading it from request anyway
	req, err := http.NewRequest("GET", "http://example.com", nil)
	Expect(err).To(BeNil())

	// application/xml header is not set, shouldn't be equal
	fpOne := matching.GetRequestFingerprint(req, []byte(xmlBody), false)
	fpTwo := matching.GetRequestFingerprint(req, []byte(xmlBodyTwo), false)
	Expect(fpOne).ToNot(Equal(fpTwo))
}
예제 #2
0
func TestXMLMinifier(t *testing.T) {
	RegisterTestingT(t)

	// body can be nil here, it's not reading it from request anyway
	req, err := http.NewRequest("GET", "http://example.com", nil)
	Expect(err).To(BeNil())

	req.Header.Add("Content-Type", "application/xml")

	fpOne := matching.GetRequestFingerprint(req, []byte(xmlBody), false)
	fpTwo := matching.GetRequestFingerprint(req, []byte(xmlBodyTwo), false)
	Expect(fpOne).To(Equal(fpTwo))
}
예제 #3
0
// TestRequestBodyCaptured tests whether request body is recorded
func TestRequestBodyCaptured(t *testing.T) {
	RegisterTestingT(t)

	server, dbClient := testTools(200, `{'message': 'here'}`)
	defer server.Close()

	requestBody := []byte("fizz=buzz")

	body := ioutil.NopCloser(bytes.NewBuffer(requestBody))

	req, err := http.NewRequest("POST", "http://capture_body.com", body)
	Expect(err).To(BeNil())

	_, err = dbClient.captureRequest(req)
	Expect(err).To(BeNil())

	fp := matching.GetRequestFingerprint(req, requestBody, false)

	pairBytes, err := dbClient.RequestCache.Get([]byte(fp))
	Expect(err).To(BeNil())

	pair, err := models.NewRequestResponsePairFromBytes(pairBytes)
	Expect(err).To(BeNil())
	Expect(pair.Request.Body).To(Equal("fizz=buzz"))
}
예제 #4
0
func TestGetResponseCorruptedRequestResponsePair(t *testing.T) {
	RegisterTestingT(t)

	server, dbClient := testTools(200, `{'message': 'here'}`)
	defer server.Close()

	requestBody := []byte("fizz=buzz")

	body := ioutil.NopCloser(bytes.NewBuffer(requestBody))

	req, err := http.NewRequest("POST", "http://capture_body.com", body)
	Expect(err).To(BeNil())

	_, err = dbClient.captureRequest(req)
	Expect(err).To(BeNil())

	fp := matching.GetRequestFingerprint(req, requestBody, false)

	dbClient.RequestCache.Set([]byte(fp), []byte("you shall not decode me!"))

	// repeating process
	bodyNew := ioutil.NopCloser(bytes.NewBuffer(requestBody))

	reqNew, err := http.NewRequest("POST", "http://capture_body.com", bodyNew)
	Expect(err).To(BeNil())

	requestDetails, err := models.NewRequestDetailsFromHttpRequest(reqNew)
	Expect(err).To(BeNil())

	response, err := dbClient.getResponse(reqNew, requestDetails)
	Expect(err).ToNot(BeNil())

	Expect(response).To(BeNil())
}
예제 #5
0
func TestScheme(t *testing.T) {
	RegisterTestingT(t)

	req, err := http.NewRequest("GET", "http://example.com", nil)
	Expect(err).To(BeNil())

	originalFp := matching.GetRequestFingerprint(req, []byte(""), false)

	httpsReq, err := http.NewRequest("GET", "https://example.com", nil)
	Expect(err).To(BeNil())

	newFp := matching.GetRequestFingerprint(httpsReq, []byte(""), false)

	// fingerprint should be the same
	Expect(originalFp).To(Equal(newFp))
}
예제 #6
0
// TestRequestFingerprintBody tests where request body is also used to create unique request ID
func TestRequestFingerprintBody(t *testing.T) {
	RegisterTestingT(t)

	req, err := http.NewRequest("GET", "http://example.com", nil)
	Expect(err).To(BeNil())

	fp := matching.GetRequestFingerprint(req, []byte("some huge XML or JSON here"), false)

	Expect(fp).To(Equal("b3918a54eb6e42652e29e14c21ba8f81"))
}
예제 #7
0
// TestRequestFingerprint tests whether we get correct request ID
func TestRequestFingerprint(t *testing.T) {
	RegisterTestingT(t)

	req, err := http.NewRequest("GET", "http://example.com", nil)
	Expect(err).To(BeNil())

	fp := matching.GetRequestFingerprint(req, []byte(""), false)

	Expect(fp).To(Equal("92a65ed4ca2b7100037a4cba9afd15ea"))
}