mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-03 04:16:03 +02:00
CookieStore's ClearSession now properly clears the user session cookie by setting MaxAge to -1. internal/sessions: move encoder interface to encoding package, and rename to MarshalUnmarshaler. internal/encoding: move mock to own package authenticate: use INFO log level for authZ error. Signed-off-by: Bobby DeSimone <bobbydesimone@gmail.com>
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package sessions
|
|
|
|
import (
|
|
"errors"
|
|
"net/http/httptest"
|
|
"net/url"
|
|
"testing"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
"github.com/pomerium/pomerium/internal/encoding"
|
|
"github.com/pomerium/pomerium/internal/encoding/mock"
|
|
)
|
|
|
|
func TestNewQueryParamStore(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
name string
|
|
State *State
|
|
|
|
enc encoding.MarshalUnmarshaler
|
|
qp string
|
|
wantErr bool
|
|
wantURL *url.URL
|
|
}{
|
|
{"simple good", &State{Email: "user@domain.com", User: "user"}, mock.Encoder{MarshalResponse: []byte("ok")}, "", false, &url.URL{Path: "/", RawQuery: "pomerium_session=ok"}},
|
|
{"marshall error", &State{Email: "user@domain.com", User: "user"}, mock.Encoder{MarshalError: errors.New("error")}, "", true, &url.URL{Path: "/"}},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := NewQueryParamStore(tt.enc, tt.qp)
|
|
|
|
r := httptest.NewRequest("GET", "/", nil)
|
|
w := httptest.NewRecorder()
|
|
|
|
if err := got.SaveSession(w, r, tt.State); (err != nil) != tt.wantErr {
|
|
t.Errorf("NewQueryParamStore.SaveSession() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
|
|
if diff := cmp.Diff(r.URL, tt.wantURL); diff != "" {
|
|
t.Errorf("NewQueryParamStore() = %v", diff)
|
|
}
|
|
got.ClearSession(w, r)
|
|
if diff := cmp.Diff(r.URL, &url.URL{Path: "/"}); diff != "" {
|
|
t.Errorf("NewQueryParamStore() = %v", diff)
|
|
}
|
|
})
|
|
}
|
|
}
|