zitadel/internal/api/oidc/amr_test.go
Livio Spring ee26f99ebf
fix: store auth methods instead of AMR in auth request linking and OIDC Session (#6192)
This PR changes the information stored on the SessionLinkedEvent and (OIDC Session) AddedEvent from OIDC AMR strings to domain.UserAuthMethodTypes, so no information is lost in the process (e.g. authentication with an IDP)
2023-07-12 12:24:01 +00:00

70 lines
1.2 KiB
Go

package oidc
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/zitadel/zitadel/internal/domain"
)
func TestAMR(t *testing.T) {
type args struct {
methodTypes []domain.UserAuthMethodType
}
tests := []struct {
name string
args args
want []string
}{
{
"no checks, empty",
args{
nil,
},
[]string{},
},
{
"pw checked",
args{
[]domain.UserAuthMethodType{domain.UserAuthMethodTypePassword},
},
[]string{PWD},
},
{
"passkey checked",
args{
[]domain.UserAuthMethodType{domain.UserAuthMethodTypePasswordless},
},
[]string{UserPresence, MFA},
},
{
"u2f checked",
args{
[]domain.UserAuthMethodType{domain.UserAuthMethodTypeU2F},
},
[]string{UserPresence},
},
{
"otp checked",
args{
[]domain.UserAuthMethodType{domain.UserAuthMethodTypeOTP},
},
[]string{OTP},
},
{
"multiple checked",
args{
[]domain.UserAuthMethodType{domain.UserAuthMethodTypePassword, domain.UserAuthMethodTypeU2F},
},
[]string{PWD, UserPresence, MFA},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := AuthMethodTypesToAMR(tt.args.methodTypes)
assert.Equal(t, tt.want, got)
})
}
}