Fix error getting remote address in getRequestRemote
This commit is contained in:
@@ -70,7 +70,7 @@ func getRequestPath(w http.ResponseWriter, r *http.Request, h *model.Handler) {
|
||||
|
||||
func getRequestRemote(w http.ResponseWriter, r *http.Request, h *model.Handler) {
|
||||
w.Header().Add("Content-Type", "application/octet-stream")
|
||||
_, _ = w.Write([]byte(r.RemoteAddr))
|
||||
_, _ = w.Write([]byte(h.Request.RemoteAddr))
|
||||
}
|
||||
|
||||
func getRequestMatches(w http.ResponseWriter, r *http.Request, h *model.Handler) {
|
||||
|
||||
@@ -26,7 +26,6 @@ import (
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -388,22 +387,18 @@ func TestGetRequestRemoteReturnsTheCorrectRemote(t *testing.T) {
|
||||
Request: httptest.NewRequest("POST", "http://www.foo.bar:8080/", nil),
|
||||
Writer: httptest.NewRecorder(),
|
||||
}
|
||||
h.Request.RemoteAddr = "1.2.3.4:12345"
|
||||
r := httptest.NewRequest("GET", "/not-important-here", nil)
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
getRequestRemote(w, r, &h)
|
||||
|
||||
res := w.Result()
|
||||
body, _ := ioutil.ReadAll(res.Body)
|
||||
rem := body[:bytes.Index(body, []byte(":"))]
|
||||
re, _ := regexp.Compile(`^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$`)
|
||||
if found := re.Match(rem); !found {
|
||||
t.Errorf("Version mismatch. Expected %v, got %v", `^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$`, string(rem))
|
||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != h.Request.RemoteAddr {
|
||||
t.Errorf("Version mismatch. Expected %q, got %q", h.Request.RemoteAddr, string(body))
|
||||
}
|
||||
}
|
||||
|
||||
// DOING #113: /request/ssl/client/i/dn
|
||||
|
||||
func createMuxRequest(pattern, url, method string, content io.Reader) (req *http.Request) {
|
||||
m := mux.NewRouter()
|
||||
m.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) { req = r })
|
||||
@@ -1139,6 +1134,8 @@ func TestGetRequestFileContent500sWhenHandlerRequestErrors(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// DOING #113: /request/ssl/client/i/dn
|
||||
|
||||
func TestGetRouteId200sOnHappyPath(t *testing.T) {
|
||||
h := model.Handler{
|
||||
Request: httptest.NewRequest("POST", "/", nil),
|
||||
|
||||
Reference in New Issue
Block a user