mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-02 16:30:17 +02:00
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:
parent
aadbcd23bd
commit
f719d885b7
7 changed files with 105 additions and 57 deletions
|
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue