authenticate: remove unused paths, generate cipher at startup, remove qp store (#1495)

* authenticate: remove unused paths, generate cipher on boot

- internal/httputil: add JSON renderer
- internal/httputil: remove unused query param store and references

Signed-off-by: Bobby DeSimone <bobbydesimone@gmail.com>
This commit is contained in:
bobby 2020-10-19 08:09:53 -07:00 committed by GitHub
parent aadbcd23bd
commit f719d885b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 105 additions and 57 deletions

View file

@ -2,6 +2,7 @@ package httputil
import (
"errors"
"math"
"net/http"
"net/http/httptest"
"testing"
@ -92,3 +93,58 @@ func TestHandlerFunc_ServeHTTP(t *testing.T) {
})
}
}
func TestRenderJSON(t *testing.T) {
tests := []struct {
name string
code int
v interface{}
wantBody string
wantCode int
}{
{"simple",
http.StatusTeapot,
struct {
A string
B string
C int
}{
A: "A",
B: "B",
C: 1,
},
"{\"A\":\"A\",\"B\":\"B\",\"C\":1}\n",
http.StatusTeapot,
},
{"map",
http.StatusOK,
map[string]interface{}{
"C": 1, // notice order does not matter
"A": "A",
"B": "B",
},
// alphabetical
"{\"A\":\"A\",\"B\":\"B\",\"C\":1}\n", http.StatusOK,
},
{"bad!",
http.StatusOK,
map[string]interface{}{
"BAD BOI": math.Inf(1),
},
`{"error":"json: unsupported value: +Inf"}`, http.StatusInternalServerError},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
w := httptest.NewRecorder()
RenderJSON(w, tt.code, tt.v)
if diff := cmp.Diff(tt.wantBody, w.Body.String()); diff != "" {
t.Errorf("TestRenderJSON:\n %s", diff)
}
if diff := cmp.Diff(tt.wantCode, w.Result().StatusCode); diff != "" {
t.Errorf("TestRenderJSON:\n %s", diff)
}
})
}
}