mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-25 12:39:50 +02:00
state: infer user from subject (#772)
Signed-off-by: Bobby DeSimone <bobbydesimone@gmail.com>
This commit is contained in:
parent
ad79585ae8
commit
7ccd364c7e
3 changed files with 43 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
|||
package sessions
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -144,3 +145,41 @@ func TestState_accessTokenHash(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestState_UnmarshalJSON(t *testing.T) {
|
||||
fixedTime := time.Date(2009, 11, 17, 20, 34, 58, 651387237, time.UTC)
|
||||
timeNow = func() time.Time {
|
||||
return fixedTime
|
||||
}
|
||||
defer func() { timeNow = time.Now }()
|
||||
tests := []struct {
|
||||
name string
|
||||
in *State
|
||||
want State
|
||||
wantErr bool
|
||||
}{
|
||||
{"good", &State{}, State{}, false},
|
||||
{"with user", &State{User: "user"}, State{User: "user"}, false},
|
||||
{"without", &State{Subject: "user"}, State{User: "user", Subject: "user"}, false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
data, err := json.Marshal(tt.in)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
s := &State{}
|
||||
if err := s.UnmarshalJSON(data); (err != nil) != tt.wantErr {
|
||||
t.Errorf("State.UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
got := *s
|
||||
cmpOpts := []cmp.Option{
|
||||
cmpopts.IgnoreUnexported(State{}),
|
||||
}
|
||||
if diff := cmp.Diff(got, tt.want, cmpOpts...); diff != "" {
|
||||
t.Errorf("State.UnmarshalJSON() error = %v", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue