Merge pull request #270 from testwill/ioutil
chore: remove refs to deprecated io/ioutil
This commit is contained in:
@@ -17,7 +17,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/BBVA/kapow/internal/client"
|
"github.com/BBVA/kapow/internal/client"
|
||||||
@@ -62,9 +62,9 @@ func init() {
|
|||||||
var buf []byte
|
var buf []byte
|
||||||
var err error
|
var err error
|
||||||
if commandFile == "-" {
|
if commandFile == "-" {
|
||||||
buf, err = ioutil.ReadAll(os.Stdin)
|
buf, err = io.ReadAll(os.Stdin)
|
||||||
} else {
|
} else {
|
||||||
buf, err = ioutil.ReadFile(commandFile)
|
buf, err = os.ReadFile(commandFile)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.L.Fatal(err)
|
logger.L.Fatal(err)
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ package http
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/BBVA/kapow/internal/server/httperror"
|
"github.com/BBVA/kapow/internal/server/httperror"
|
||||||
@@ -28,7 +28,7 @@ import (
|
|||||||
// Reason returns the reason phrase embedded within the JSON error
|
// Reason returns the reason phrase embedded within the JSON error
|
||||||
// body, or an error if no reason can be extracted
|
// body, or an error if no reason can be extracted
|
||||||
func Reason(r *http.Response) (string, error) {
|
func Reason(r *http.Response) (string, error) {
|
||||||
body, err := ioutil.ReadAll(r.Body)
|
body, err := io.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errors.New("error reading response's body")
|
return "", errors.New("error reading response's body")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
package http
|
package http
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io"
|
||||||
nethttp "net/http"
|
nethttp "net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -26,7 +26,7 @@ import (
|
|||||||
func TestReasonExtractsReasonFromJSON(t *testing.T) {
|
func TestReasonExtractsReasonFromJSON(t *testing.T) {
|
||||||
r := &nethttp.Response{
|
r := &nethttp.Response{
|
||||||
Status: "200 OK",
|
Status: "200 OK",
|
||||||
Body: ioutil.NopCloser(
|
Body: io.NopCloser(
|
||||||
strings.NewReader(
|
strings.NewReader(
|
||||||
`{"reason": "Because reasons", "foo": "bar"}`,
|
`{"reason": "Because reasons", "foo": "bar"}`,
|
||||||
),
|
),
|
||||||
@@ -43,7 +43,7 @@ func TestReasonExtractsReasonFromJSON(t *testing.T) {
|
|||||||
func TestReasonErrorsOnJSONWithNoReason(t *testing.T) {
|
func TestReasonErrorsOnJSONWithNoReason(t *testing.T) {
|
||||||
r := &nethttp.Response{
|
r := &nethttp.Response{
|
||||||
Status: "200 OK",
|
Status: "200 OK",
|
||||||
Body: ioutil.NopCloser(
|
Body: io.NopCloser(
|
||||||
strings.NewReader(
|
strings.NewReader(
|
||||||
`{"madness": "Because madness", "foo": "bar"}`,
|
`{"madness": "Because madness", "foo": "bar"}`,
|
||||||
),
|
),
|
||||||
@@ -59,7 +59,7 @@ func TestReasonErrorsOnJSONWithNoReason(t *testing.T) {
|
|||||||
|
|
||||||
func TestReasonErrorsOnJSONWithEmptyReason(t *testing.T) {
|
func TestReasonErrorsOnJSONWithEmptyReason(t *testing.T) {
|
||||||
r := &nethttp.Response{
|
r := &nethttp.Response{
|
||||||
Body: ioutil.NopCloser(
|
Body: io.NopCloser(
|
||||||
strings.NewReader(
|
strings.NewReader(
|
||||||
`{"reason": "", "foo": "bar"}`,
|
`{"reason": "", "foo": "bar"}`,
|
||||||
),
|
),
|
||||||
@@ -75,7 +75,7 @@ func TestReasonErrorsOnJSONWithEmptyReason(t *testing.T) {
|
|||||||
|
|
||||||
func TestReasonErrorsOnNoJSON(t *testing.T) {
|
func TestReasonErrorsOnNoJSON(t *testing.T) {
|
||||||
r := &nethttp.Response{
|
r := &nethttp.Response{
|
||||||
Body: ioutil.NopCloser(
|
Body: io.NopCloser(
|
||||||
strings.NewReader(""),
|
strings.NewReader(""),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,7 @@ func TestReasonErrorsOnNoJSON(t *testing.T) {
|
|||||||
|
|
||||||
func TestReasonErrorsOnInvalidJSON(t *testing.T) {
|
func TestReasonErrorsOnInvalidJSON(t *testing.T) {
|
||||||
r := &nethttp.Response{
|
r := &nethttp.Response{
|
||||||
Body: ioutil.NopCloser(
|
Body: io.NopCloser(
|
||||||
strings.NewReader(
|
strings.NewReader(
|
||||||
`{"reason": "Because reasons", "cliffhanger...`,
|
`{"reason": "Because reasons", "cliffhanger...`,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import (
|
|||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
@@ -54,7 +53,7 @@ func Delete(url string, r io.Reader, w io.Writer, clientGenerator func() *http.C
|
|||||||
return Request("DELETE", url, r, w, clientGenerator, reqTuner...)
|
return Request("DELETE", url, r, w, clientGenerator, reqTuner...)
|
||||||
}
|
}
|
||||||
|
|
||||||
var devnull = ioutil.Discard
|
var devnull = io.Discard
|
||||||
|
|
||||||
// Request will perform the request to the given url and method sending the
|
// Request will perform the request to the given url and method sending the
|
||||||
// content of the given reader as the body and writing all the contents
|
// content of the given reader as the body and writing all the contents
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ package control
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
@@ -103,7 +103,7 @@ var pathValidator func(string) error = func(path string) error {
|
|||||||
func addRoute(res http.ResponseWriter, req *http.Request) {
|
func addRoute(res http.ResponseWriter, req *http.Request) {
|
||||||
var route model.Route
|
var route model.Route
|
||||||
|
|
||||||
payload, _ := ioutil.ReadAll(req.Body)
|
payload, _ := io.ReadAll(req.Body)
|
||||||
err := json.Unmarshal(payload, &route)
|
err := json.Unmarshal(payload, &route)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httperror.ErrorJSON(res, "Malformed JSON", http.StatusBadRequest)
|
httperror.ErrorJSON(res, "Malformed JSON", http.StatusBadRequest)
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"reflect"
|
"reflect"
|
||||||
@@ -47,7 +47,7 @@ func checkErrorResponse(r *http.Response, expectedErrcode int, expectedReason st
|
|||||||
}
|
}
|
||||||
|
|
||||||
errMsg := httperror.ServerErrMessage{}
|
errMsg := httperror.ServerErrMessage{}
|
||||||
if bodyBytes, err := ioutil.ReadAll(r.Body); err != nil {
|
if bodyBytes, err := io.ReadAll(r.Body); err != nil {
|
||||||
errList = append(errList, fmt.Errorf("Unexpected error reading response body: %v", err))
|
errList = append(errList, fmt.Errorf("Unexpected error reading response body: %v", err))
|
||||||
} else if err := json.Unmarshal(bodyBytes, &errMsg); err != nil {
|
} else if err := json.Unmarshal(bodyBytes, &errMsg); err != nil {
|
||||||
errList = append(errList, fmt.Errorf("Response body contains invalid JSON entity: %v", err))
|
errList = append(errList, fmt.Errorf("Response body contains invalid JSON entity: %v", err))
|
||||||
@@ -434,7 +434,7 @@ func TestGetRouteReturnsTheRequestedRoute(t *testing.T) {
|
|||||||
t.Errorf("HTTP status mismatch. Expected: %d, got: %d", http.StatusOK, resp.StatusCode)
|
t.Errorf("HTTP status mismatch. Expected: %d, got: %d", http.StatusOK, resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
bBytes, _ := ioutil.ReadAll(resp.Body)
|
bBytes, _ := io.ReadAll(resp.Body)
|
||||||
if err := json.Unmarshal(bBytes, &respJson); err != nil {
|
if err := json.Unmarshal(bBytes, &respJson); err != nil {
|
||||||
t.Errorf("Invalid JSON response. %s", string(bBytes))
|
t.Errorf("Invalid JSON response. %s", string(bBytes))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,11 +18,10 @@ package data
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/textproto"
|
"net/textproto"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/BBVA/kapow/internal/logger"
|
"github.com/BBVA/kapow/internal/logger"
|
||||||
"github.com/BBVA/kapow/internal/server/httperror"
|
"github.com/BBVA/kapow/internal/server/httperror"
|
||||||
@@ -183,7 +182,7 @@ func getRouteId(w http.ResponseWriter, r *http.Request, h *model.Handler) {
|
|||||||
// FIXME: Allow any HTTP status code. Now we are limited by WriteHeader
|
// FIXME: Allow any HTTP status code. Now we are limited by WriteHeader
|
||||||
// capabilities
|
// capabilities
|
||||||
func setResponseStatus(w http.ResponseWriter, r *http.Request, h *model.Handler) {
|
func setResponseStatus(w http.ResponseWriter, r *http.Request, h *model.Handler) {
|
||||||
sb, err := ioutil.ReadAll(r.Body)
|
sb, err := io.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httperror.ErrorJSON(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
httperror.ErrorJSON(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
@@ -200,7 +199,7 @@ func setResponseStatus(w http.ResponseWriter, r *http.Request, h *model.Handler)
|
|||||||
|
|
||||||
func setResponseHeaders(w http.ResponseWriter, r *http.Request, h *model.Handler) {
|
func setResponseHeaders(w http.ResponseWriter, r *http.Request, h *model.Handler) {
|
||||||
name := mux.Vars(r)["name"]
|
name := mux.Vars(r)["name"]
|
||||||
vb, err := ioutil.ReadAll(r.Body)
|
vb, err := io.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httperror.ErrorJSON(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
httperror.ErrorJSON(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
@@ -212,7 +211,7 @@ func setResponseHeaders(w http.ResponseWriter, r *http.Request, h *model.Handler
|
|||||||
|
|
||||||
func setResponseCookies(w http.ResponseWriter, r *http.Request, h *model.Handler) {
|
func setResponseCookies(w http.ResponseWriter, r *http.Request, h *model.Handler) {
|
||||||
name := mux.Vars(r)["name"]
|
name := mux.Vars(r)["name"]
|
||||||
vb, err := ioutil.ReadAll(r.Body)
|
vb, err := io.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httperror.ErrorJSON(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
httperror.ErrorJSON(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
@@ -242,7 +241,7 @@ func setResponseBody(w http.ResponseWriter, r *http.Request, h *model.Handler) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setServerLog(w http.ResponseWriter, r *http.Request, h *model.Handler) {
|
func setServerLog(w http.ResponseWriter, r *http.Request, h *model.Handler) {
|
||||||
msg, err := ioutil.ReadAll(r.Body)
|
msg, err := io.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httperror.ErrorJSON(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
httperror.ErrorJSON(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -24,11 +24,11 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -110,7 +110,7 @@ func TestGetRequestBodyWritesHandlerRequestBodyToResponseWriter(t *testing.T) {
|
|||||||
getRequestBody(w, r, &h)
|
getRequestBody(w, r, &h)
|
||||||
|
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "BAR" {
|
if body, _ := io.ReadAll(res.Body); string(body) != "BAR" {
|
||||||
t.Error("Body mismatch")
|
t.Error("Body mismatch")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -189,7 +189,7 @@ func TestGetRequestMethodReturnsTheCorrectMethod(t *testing.T) {
|
|||||||
getRequestMethod(w, r, &h)
|
getRequestMethod(w, r, &h)
|
||||||
|
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "FOO" {
|
if body, _ := io.ReadAll(res.Body); string(body) != "FOO" {
|
||||||
t.Error("Body mismatch")
|
t.Error("Body mismatch")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -237,7 +237,7 @@ func TestGetRequestHostReturnsTheCorrectHostname(t *testing.T) {
|
|||||||
getRequestHost(w, r, &h)
|
getRequestHost(w, r, &h)
|
||||||
|
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "www.foo.bar:8080" {
|
if body, _ := io.ReadAll(res.Body); string(body) != "www.foo.bar:8080" {
|
||||||
t.Error("Body mismatch")
|
t.Error("Body mismatch")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -288,7 +288,7 @@ func TestGetRequestVersionReturnsTheCorrectHttpVersion(t *testing.T) {
|
|||||||
getRequestVersion(w, r, &h)
|
getRequestVersion(w, r, &h)
|
||||||
|
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != h.Request.Proto {
|
if body, _ := io.ReadAll(res.Body); string(body) != h.Request.Proto {
|
||||||
t.Errorf("Version mismatch. Expected %q, got %q", h.Request.Proto, string(body))
|
t.Errorf("Version mismatch. Expected %q, got %q", h.Request.Proto, string(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -336,7 +336,7 @@ func TestGetRequestPathReturnsPath(t *testing.T) {
|
|||||||
getRequestPath(w, r, &h)
|
getRequestPath(w, r, &h)
|
||||||
|
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "/foo" {
|
if body, _ := io.ReadAll(res.Body); string(body) != "/foo" {
|
||||||
t.Error("Body mismatch")
|
t.Error("Body mismatch")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -352,7 +352,7 @@ func TestGetRequestPathDoesntReturnQueryStringParams(t *testing.T) {
|
|||||||
getRequestPath(w, r, &h)
|
getRequestPath(w, r, &h)
|
||||||
|
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "/foo" {
|
if body, _ := io.ReadAll(res.Body); string(body) != "/foo" {
|
||||||
t.Errorf("Body mismatch. Expected: /foo. Got: %v", string(body))
|
t.Errorf("Body mismatch. Expected: /foo. Got: %v", string(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -401,7 +401,7 @@ func TestGetRequestRemoteReturnsTheCorrectRemote(t *testing.T) {
|
|||||||
getRequestRemote(w, r, &h)
|
getRequestRemote(w, r, &h)
|
||||||
|
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != h.Request.RemoteAddr {
|
if body, _ := io.ReadAll(res.Body); string(body) != h.Request.RemoteAddr {
|
||||||
t.Errorf("Version mismatch. Expected %q, got %q", h.Request.RemoteAddr, string(body))
|
t.Errorf("Version mismatch. Expected %q, got %q", h.Request.RemoteAddr, string(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -456,7 +456,7 @@ func TestGetRequestMatchesReturnsTheCorrectMatchValue(t *testing.T) {
|
|||||||
getRequestMatches(w, r, &h)
|
getRequestMatches(w, r, &h)
|
||||||
|
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "BAZ" {
|
if body, _ := io.ReadAll(res.Body); string(body) != "BAZ" {
|
||||||
t.Errorf("Body mismatch. Expected: BAZ. Got: %v", string(body))
|
t.Errorf("Body mismatch. Expected: BAZ. Got: %v", string(body))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -521,7 +521,7 @@ func TestGetRequestParamsReturnsTheCorrectMatchValue(t *testing.T) {
|
|||||||
getRequestParams(w, r, &h)
|
getRequestParams(w, r, &h)
|
||||||
|
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "BAZ" {
|
if body, _ := io.ReadAll(res.Body); string(body) != "BAZ" {
|
||||||
t.Errorf("Body mismatch. Expected: BAZ. Got: %v", string(body))
|
t.Errorf("Body mismatch. Expected: BAZ. Got: %v", string(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -553,7 +553,7 @@ func TestGetRequestParamsReturnsTheFirstCorrectMatchValue(t *testing.T) {
|
|||||||
getRequestParams(w, r, &h)
|
getRequestParams(w, r, &h)
|
||||||
|
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "BAZ" {
|
if body, _ := io.ReadAll(res.Body); string(body) != "BAZ" {
|
||||||
t.Errorf("Body mismatch. Expected: BAZ. Got: %v", string(body))
|
t.Errorf("Body mismatch. Expected: BAZ. Got: %v", string(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -604,7 +604,7 @@ func TestGetRequestHeadersReturnsTheCorrectMatchValue(t *testing.T) {
|
|||||||
getRequestHeaders(w, r, &h)
|
getRequestHeaders(w, r, &h)
|
||||||
|
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "BAZ" {
|
if body, _ := io.ReadAll(res.Body); string(body) != "BAZ" {
|
||||||
t.Errorf("Body mismatch. Expected: BAZ. Got: %v", string(body))
|
t.Errorf("Body mismatch. Expected: BAZ. Got: %v", string(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -638,7 +638,7 @@ func TestGetRequestHeadersReturnsEmptyBodyWhenHeaderIsEmptyString(t *testing.T)
|
|||||||
getRequestHeaders(w, r, &h)
|
getRequestHeaders(w, r, &h)
|
||||||
|
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "" {
|
if body, _ := io.ReadAll(res.Body); string(body) != "" {
|
||||||
t.Errorf(`Body mismatch. Expected "". Got: %q`, string(body))
|
t.Errorf(`Body mismatch. Expected "". Got: %q`, string(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -655,7 +655,7 @@ func TestGetRequestHeadersReturnsTheCorrectInsensitiveMatchValue(t *testing.T) {
|
|||||||
getRequestHeaders(w, r, &h)
|
getRequestHeaders(w, r, &h)
|
||||||
|
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "BAZ" {
|
if body, _ := io.ReadAll(res.Body); string(body) != "BAZ" {
|
||||||
t.Errorf("Body mismatch. Expected: BAZ. Got: %v", string(body))
|
t.Errorf("Body mismatch. Expected: BAZ. Got: %v", string(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -688,7 +688,7 @@ func TestGetRequestHeadersReturnsTheFirstCorrectMatchValue(t *testing.T) {
|
|||||||
getRequestHeaders(w, r, &h)
|
getRequestHeaders(w, r, &h)
|
||||||
|
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "BAZ" {
|
if body, _ := io.ReadAll(res.Body); string(body) != "BAZ" {
|
||||||
t.Errorf("Body mismatch. Expected: BAZ. Got: %v", string(body))
|
t.Errorf("Body mismatch. Expected: BAZ. Got: %v", string(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -720,7 +720,7 @@ func TestGetRequestHeadersReturnsTheCorrectValueForHostHeader(t *testing.T) {
|
|||||||
getRequestHeaders(w, r, &h)
|
getRequestHeaders(w, r, &h)
|
||||||
|
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "www.foo.bar:8080" {
|
if body, _ := io.ReadAll(res.Body); string(body) != "www.foo.bar:8080" {
|
||||||
t.Errorf("Body mismatch. Expected: %q. Got: %q", "www.foo.bar:8080", string(body))
|
t.Errorf("Body mismatch. Expected: %q. Got: %q", "www.foo.bar:8080", string(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -771,7 +771,7 @@ func TestGetRequestCookiesReturnsMatchedCookieValue(t *testing.T) {
|
|||||||
getRequestCookies(w, r, &h)
|
getRequestCookies(w, r, &h)
|
||||||
|
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "BAZ" {
|
if body, _ := io.ReadAll(res.Body); string(body) != "BAZ" {
|
||||||
t.Errorf("Body mismatch. Expected: BAZ. Got: %v", string(body))
|
t.Errorf("Body mismatch. Expected: BAZ. Got: %v", string(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -804,7 +804,7 @@ func TestGetRequestCookiesReturnsTheFirstCorrectMatchValue(t *testing.T) {
|
|||||||
getRequestCookies(w, r, &h)
|
getRequestCookies(w, r, &h)
|
||||||
|
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "BAZ" {
|
if body, _ := io.ReadAll(res.Body); string(body) != "BAZ" {
|
||||||
t.Errorf("Body mismatch. Expected: BAZ. Got: %v", string(body))
|
t.Errorf("Body mismatch. Expected: BAZ. Got: %v", string(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -869,7 +869,7 @@ func TestGetRequestFormReturnsTheCorrectMatchValue(t *testing.T) {
|
|||||||
getRequestForm(w, r, &h)
|
getRequestForm(w, r, &h)
|
||||||
|
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "BAZ" {
|
if body, _ := io.ReadAll(res.Body); string(body) != "BAZ" {
|
||||||
t.Errorf("Body mismatch. Expected: BAZ. Got: %v", string(body))
|
t.Errorf("Body mismatch. Expected: BAZ. Got: %v", string(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -925,7 +925,7 @@ func TestGetRequestFormReturnsEmptyBodyWhenFieldIsEmptyString(t *testing.T) {
|
|||||||
getRequestForm(w, r, &h)
|
getRequestForm(w, r, &h)
|
||||||
|
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "" {
|
if body, _ := io.ReadAll(res.Body); string(body) != "" {
|
||||||
t.Errorf(`Body mismatch. Expected: "". Got: %q`, string(body))
|
t.Errorf(`Body mismatch. Expected: "". Got: %q`, string(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1001,7 +1001,7 @@ func TestGetRequestFileNameReturnsTheCorrectFilename(t *testing.T) {
|
|||||||
getRequestFileName(w, r, &h)
|
getRequestFileName(w, r, &h)
|
||||||
|
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "BAZ" {
|
if body, _ := io.ReadAll(res.Body); string(body) != "BAZ" {
|
||||||
t.Errorf(`Body mismatch. Expected: "BAZ". Got: %q`, string(body))
|
t.Errorf(`Body mismatch. Expected: "BAZ". Got: %q`, string(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1080,7 +1080,7 @@ func TestGetRequestFileContentReturnsTheCorrectFileContent(t *testing.T) {
|
|||||||
getRequestFileContent(w, r, &h)
|
getRequestFileContent(w, r, &h)
|
||||||
|
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "BAZ" {
|
if body, _ := io.ReadAll(res.Body); string(body) != "BAZ" {
|
||||||
t.Errorf(`Body mismatch. Expected: "BAZ". Got: %q`, string(body))
|
t.Errorf(`Body mismatch. Expected: "BAZ". Got: %q`, string(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1205,7 +1205,7 @@ func TestGetSSLClientDNSetsOctectStreamContentType(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func mockAuthenticateClient(tls *tls.ConnectionState) error {
|
func mockAuthenticateClient(tls *tls.ConnectionState) error {
|
||||||
fileData, err := ioutil.ReadFile("./testdata/client_chain.crt")
|
fileData, err := os.ReadFile("./testdata/client_chain.crt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error loading certificates file: %v", err)
|
return fmt.Errorf("Error loading certificates file: %v", err)
|
||||||
}
|
}
|
||||||
@@ -1237,7 +1237,7 @@ func TestGetSSLClientDNReturnsCorrectDN(t *testing.T) {
|
|||||||
|
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
|
|
||||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != h.Request.TLS.VerifiedChains[0][0].Subject.String() {
|
if body, _ := io.ReadAll(res.Body); string(body) != h.Request.TLS.VerifiedChains[0][0].Subject.String() {
|
||||||
t.Errorf("Body mismatch. Expected: %q, got: %q", h.Request.TLS.VerifiedChains[0][0].Subject.String(), string(body))
|
t.Errorf("Body mismatch. Expected: %q, got: %q", h.Request.TLS.VerifiedChains[0][0].Subject.String(), string(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1286,7 +1286,7 @@ func TestGetRouteIdReturnsTheCorrectRouteId(t *testing.T) {
|
|||||||
getRouteId(w, r, &h)
|
getRouteId(w, r, &h)
|
||||||
|
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != h.Route.ID {
|
if body, _ := io.ReadAll(res.Body); string(body) != h.Route.ID {
|
||||||
t.Errorf("Body mismatch. Expected: %q, got: %q", h.Route.ID, string(body))
|
t.Errorf("Body mismatch. Expected: %q, got: %q", h.Route.ID, string(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1575,7 +1575,7 @@ func TestSetResponseBodySetsTheResponseBody(t *testing.T) {
|
|||||||
setResponseBody(w, r, &h)
|
setResponseBody(w, r, &h)
|
||||||
|
|
||||||
res := hw.Result()
|
res := hw.Result()
|
||||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "BAZ" {
|
if body, _ := io.ReadAll(res.Body); string(body) != "BAZ" {
|
||||||
t.Errorf(`Body mismatch. Expected: "BAZ". Got: %q`, string(body))
|
t.Errorf(`Body mismatch. Expected: "BAZ". Got: %q`, string(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ package data
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -40,7 +40,7 @@ func checkErrorResponse(r *http.Response, expectedErrcode int, expectedReason st
|
|||||||
}
|
}
|
||||||
|
|
||||||
errMsg := httperror.ServerErrMessage{}
|
errMsg := httperror.ServerErrMessage{}
|
||||||
if bodyBytes, err := ioutil.ReadAll(r.Body); err != nil {
|
if bodyBytes, err := io.ReadAll(r.Body); err != nil {
|
||||||
errList = append(errList, fmt.Errorf("Unexpected error reading response body: %v", err))
|
errList = append(errList, fmt.Errorf("Unexpected error reading response body: %v", err))
|
||||||
} else if err := json.Unmarshal(bodyBytes, &errMsg); err != nil {
|
} else if err := json.Unmarshal(bodyBytes, &errMsg); err != nil {
|
||||||
errList = append(errList, fmt.Errorf("Response body contains invalid JSON entity: %v", err))
|
errList = append(errList, fmt.Errorf("Response body contains invalid JSON entity: %v", err))
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ package httperror_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -53,7 +53,7 @@ func TestErrorJSONSetsBodyCorrectly(t *testing.T) {
|
|||||||
httperror.ErrorJSON(w, expectedReason, http.StatusNotFound)
|
httperror.ErrorJSON(w, expectedReason, http.StatusNotFound)
|
||||||
|
|
||||||
errMsg := httperror.ServerErrMessage{}
|
errMsg := httperror.ServerErrMessage{}
|
||||||
if bodyBytes, err := ioutil.ReadAll(w.Result().Body); err != nil {
|
if bodyBytes, err := io.ReadAll(w.Result().Body); err != nil {
|
||||||
t.Errorf("Unexpected error reading response body: %v", err)
|
t.Errorf("Unexpected error reading response body: %v", err)
|
||||||
} else if err := json.Unmarshal(bodyBytes, &errMsg); err != nil {
|
} else if err := json.Unmarshal(bodyBytes, &errMsg); err != nil {
|
||||||
t.Errorf("Response body contains invalid JSON entity: %v", err)
|
t.Errorf("Response body contains invalid JSON entity: %v", err)
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ package mux
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"reflect"
|
"reflect"
|
||||||
@@ -152,7 +151,7 @@ func TestGorillizeReturnsAMuxThatRespectsRouteOrderAB(t *testing.T) {
|
|||||||
|
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
|
|
||||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "routeA" {
|
if body, _ := io.ReadAll(res.Body); string(body) != "routeA" {
|
||||||
t.Errorf("Mux did not respect route order %q", body)
|
t.Errorf("Mux did not respect route order %q", body)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,7 +179,7 @@ func TestGorillizeReturnsAMuxThatRespectsRouteOrderBA(t *testing.T) {
|
|||||||
|
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
|
|
||||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "routeB" {
|
if body, _ := io.ReadAll(res.Body); string(body) != "routeB" {
|
||||||
t.Errorf("Mux did not respect route order %q", body)
|
t.Errorf("Mux did not respect route order %q", body)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ import (
|
|||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/BBVA/kapow/internal/logger"
|
"github.com/BBVA/kapow/internal/logger"
|
||||||
@@ -90,7 +90,7 @@ func Run(bindAddr string, wg *sync.WaitGroup, certFile, keyFile, cliCaFile strin
|
|||||||
func loadCertificatesFromFile(certFile string) (pool *x509.CertPool, err error) {
|
func loadCertificatesFromFile(certFile string) (pool *x509.CertPool, err error) {
|
||||||
if certFile != "" {
|
if certFile != "" {
|
||||||
var caCerts []byte
|
var caCerts []byte
|
||||||
caCerts, err = ioutil.ReadFile(certFile)
|
caCerts, err = os.ReadFile(certFile)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
pool = x509.NewCertPool()
|
pool = x509.NewCertPool()
|
||||||
if !pool.AppendCertsFromPEM(caCerts) {
|
if !pool.AppendCertsFromPEM(caCerts) {
|
||||||
|
|||||||
Reference in New Issue
Block a user