Some checks failed
Build docker and publish / build (20.15.1) (push) Failing after 8m0s
47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
package middleware
|
|
|
|
import "testing"
|
|
|
|
func TestParseLoginType(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
claims map[string]interface{}
|
|
want string
|
|
}{
|
|
{
|
|
name: "prefer CtxLoginType when both exist",
|
|
claims: map[string]interface{}{"CtxLoginType": "device", "LoginType": "email"},
|
|
want: "device",
|
|
},
|
|
{
|
|
name: "fallback to legacy LoginType",
|
|
claims: map[string]interface{}{"LoginType": "device"},
|
|
want: "device",
|
|
},
|
|
{
|
|
name: "ignore non-string values",
|
|
claims: map[string]interface{}{"CtxLoginType": 123, "LoginType": true},
|
|
want: "",
|
|
},
|
|
{
|
|
name: "empty values return empty",
|
|
claims: map[string]interface{}{"CtxLoginType": "", "LoginType": ""},
|
|
want: "",
|
|
},
|
|
{
|
|
name: "missing values return empty",
|
|
claims: map[string]interface{}{},
|
|
want: "",
|
|
},
|
|
}
|
|
|
|
for _, testCase := range tests {
|
|
t.Run(testCase.name, func(t *testing.T) {
|
|
got := parseLoginType(testCase.claims)
|
|
if got != testCase.want {
|
|
t.Fatalf("parseLoginType() = %q, want %q", got, testCase.want)
|
|
}
|
|
})
|
|
}
|
|
}
|