mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-01 11:26:29 +02:00
- cryptutil: add hmac & tests - cryptutil: rename cipher / encoders to be more clear - cryptutil: simplify SecureEncoder interface - cryptutil: renamed NewCipherFromBase64 to NewAEADCipherFromBase64 - cryptutil: move key & random generators to helpers Signed-off-by: Bobby DeSimone <bobbydesimone@gmail.com>
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package httputil
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
"github.com/gorilla/mux"
|
|
)
|
|
|
|
func TestCSRFFailureHandler(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
name string
|
|
|
|
wantBody string
|
|
wantStatus int
|
|
}{
|
|
{"basic csrf failure", "{\"error\":\"CSRF Failure\"}\n", http.StatusForbidden},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
r := httptest.NewRequest(http.MethodGet, "/", nil)
|
|
r.Header.Set("Accept", "application/json")
|
|
w := httptest.NewRecorder()
|
|
CSRFFailureHandler(w, r)
|
|
gotBody := w.Body.String()
|
|
gotStatus := w.Result().StatusCode
|
|
if diff := cmp.Diff(gotBody, tt.wantBody); diff != "" {
|
|
t.Errorf("RetrieveSession() = %s", diff)
|
|
}
|
|
if diff := cmp.Diff(gotStatus, tt.wantStatus); diff != "" {
|
|
t.Errorf("RetrieveSession() = %s", diff)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestNewRouter(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
want *mux.Router
|
|
}{
|
|
{"this is a gorilla router right?", mux.NewRouter()},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := NewRouter(); !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("NewRouter() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|