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) {
|
func getRequestRemote(w http.ResponseWriter, r *http.Request, h *model.Handler) {
|
||||||
w.Header().Add("Content-Type", "application/octet-stream")
|
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) {
|
func getRequestMatches(w http.ResponseWriter, r *http.Request, h *model.Handler) {
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import (
|
|||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -388,22 +387,18 @@ func TestGetRequestRemoteReturnsTheCorrectRemote(t *testing.T) {
|
|||||||
Request: httptest.NewRequest("POST", "http://www.foo.bar:8080/", nil),
|
Request: httptest.NewRequest("POST", "http://www.foo.bar:8080/", nil),
|
||||||
Writer: httptest.NewRecorder(),
|
Writer: httptest.NewRecorder(),
|
||||||
}
|
}
|
||||||
|
h.Request.RemoteAddr = "1.2.3.4:12345"
|
||||||
r := httptest.NewRequest("GET", "/not-important-here", nil)
|
r := httptest.NewRequest("GET", "/not-important-here", nil)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
getRequestRemote(w, r, &h)
|
getRequestRemote(w, r, &h)
|
||||||
|
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
body, _ := ioutil.ReadAll(res.Body)
|
if body, _ := ioutil.ReadAll(res.Body); string(body) != h.Request.RemoteAddr {
|
||||||
rem := body[:bytes.Index(body, []byte(":"))]
|
t.Errorf("Version mismatch. Expected %q, got %q", h.Request.RemoteAddr, string(body))
|
||||||
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))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DOING #113: /request/ssl/client/i/dn
|
|
||||||
|
|
||||||
func createMuxRequest(pattern, url, method string, content io.Reader) (req *http.Request) {
|
func createMuxRequest(pattern, url, method string, content io.Reader) (req *http.Request) {
|
||||||
m := mux.NewRouter()
|
m := mux.NewRouter()
|
||||||
m.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) { req = r })
|
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) {
|
func TestGetRouteId200sOnHappyPath(t *testing.T) {
|
||||||
h := model.Handler{
|
h := model.Handler{
|
||||||
Request: httptest.NewRequest("POST", "/", nil),
|
Request: httptest.NewRequest("POST", "/", nil),
|
||||||
|
|||||||
Reference in New Issue
Block a user