2023-07-12 12:24:01 +00:00
|
|
|
package oidc
|
2023-07-10 13:27:00 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2023-07-12 12:24:01 +00:00
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
2023-07-10 13:27:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAMR(t *testing.T) {
|
|
|
|
type args struct {
|
2023-07-12 12:24:01 +00:00
|
|
|
methodTypes []domain.UserAuthMethodType
|
2023-07-10 13:27:00 +00:00
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
want []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"no checks, empty",
|
|
|
|
args{
|
2023-07-12 12:24:01 +00:00
|
|
|
nil,
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
2024-03-20 10:18:46 +00:00
|
|
|
nil,
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"pw checked",
|
|
|
|
args{
|
2023-07-12 12:24:01 +00:00
|
|
|
[]domain.UserAuthMethodType{domain.UserAuthMethodTypePassword},
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
|
|
|
[]string{PWD},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"passkey checked",
|
|
|
|
args{
|
2023-07-12 12:24:01 +00:00
|
|
|
[]domain.UserAuthMethodType{domain.UserAuthMethodTypePasswordless},
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
|
|
|
[]string{UserPresence, MFA},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"u2f checked",
|
|
|
|
args{
|
2023-07-12 12:24:01 +00:00
|
|
|
[]domain.UserAuthMethodType{domain.UserAuthMethodTypeU2F},
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
|
|
|
[]string{UserPresence},
|
|
|
|
},
|
|
|
|
{
|
2023-08-02 16:57:53 +00:00
|
|
|
"totp checked",
|
2023-07-10 13:27:00 +00:00
|
|
|
args{
|
2023-08-02 16:57:53 +00:00
|
|
|
[]domain.UserAuthMethodType{domain.UserAuthMethodTypeTOTP},
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
|
|
|
[]string{OTP},
|
|
|
|
},
|
2023-08-02 16:57:53 +00:00
|
|
|
{
|
|
|
|
"otp sms checked",
|
|
|
|
args{
|
|
|
|
[]domain.UserAuthMethodType{domain.UserAuthMethodTypeOTPSMS},
|
|
|
|
},
|
|
|
|
[]string{OTP},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"otp email checked",
|
|
|
|
args{
|
|
|
|
[]domain.UserAuthMethodType{domain.UserAuthMethodTypeOTPEmail},
|
|
|
|
},
|
|
|
|
[]string{OTP},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"multiple (t)otp checked",
|
|
|
|
args{
|
|
|
|
[]domain.UserAuthMethodType{domain.UserAuthMethodTypeTOTP, domain.UserAuthMethodTypeOTPEmail},
|
|
|
|
},
|
|
|
|
[]string{OTP, MFA},
|
|
|
|
},
|
2023-07-10 13:27:00 +00:00
|
|
|
{
|
|
|
|
"multiple checked",
|
|
|
|
args{
|
2023-07-12 12:24:01 +00:00
|
|
|
[]domain.UserAuthMethodType{domain.UserAuthMethodTypePassword, domain.UserAuthMethodTypeU2F},
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
|
|
|
[]string{PWD, UserPresence, MFA},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2023-07-12 12:24:01 +00:00
|
|
|
got := AuthMethodTypesToAMR(tt.args.methodTypes)
|
2023-07-10 13:27:00 +00:00
|
|
|
assert.Equal(t, tt.want, got)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|