mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-17 19:05:13 +00:00
feat: enable otp email and sms (#6260)
* feat: enable otp email and sms * feat: enable otp factors in login settings * remove tests without value * translate second factors * don't add new factors yet * add comment * add factors to docs * backward compatible settings api * compile tests * add available 2fa types * test: add mapping tests --------- Co-authored-by: Livio Spring <[email protected]>
This commit is contained in:
co-authored by
Livio Spring
parent
d3e403f645
commit
31ec1d83b9
@@ -231,7 +231,7 @@ func TestCommandSide_AddLoginPolicy(t *testing.T) {
|
||||
eventFromEventPusher(
|
||||
org.NewLoginPolicySecondFactorAddedEvent(context.Background(),
|
||||
&org.NewAggregate("org1").Aggregate,
|
||||
domain.SecondFactorTypeOTP,
|
||||
domain.SecondFactorTypeTOTP,
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
@@ -265,7 +265,7 @@ func TestCommandSide_AddLoginPolicy(t *testing.T) {
|
||||
MFAInitSkipLifetime: time.Hour * 3,
|
||||
SecondFactorCheckLifetime: time.Hour * 4,
|
||||
MultiFactorCheckLifetime: time.Hour * 5,
|
||||
SecondFactors: []domain.SecondFactorType{domain.SecondFactorTypeOTP},
|
||||
SecondFactors: []domain.SecondFactorType{domain.SecondFactorTypeTOTP},
|
||||
MultiFactors: []domain.MultiFactorType{domain.MultiFactorTypeU2FWithPIN},
|
||||
},
|
||||
},
|
||||
@@ -1504,7 +1504,7 @@ func TestCommandSide_AddSecondFactorLoginPolicy(t *testing.T) {
|
||||
eventFromEventPusher(
|
||||
org.NewLoginPolicySecondFactorAddedEvent(context.Background(),
|
||||
&org.NewAggregate("org1").Aggregate,
|
||||
domain.SecondFactorTypeOTP,
|
||||
domain.SecondFactorTypeTOTP,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -1512,7 +1512,7 @@ func TestCommandSide_AddSecondFactorLoginPolicy(t *testing.T) {
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
factor: domain.SecondFactorTypeOTP,
|
||||
factor: domain.SecondFactorTypeTOTP,
|
||||
resourceOwner: "org1",
|
||||
},
|
||||
res: res{
|
||||
@@ -1520,7 +1520,7 @@ func TestCommandSide_AddSecondFactorLoginPolicy(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "add factor, ok",
|
||||
name: "add factor totp, ok",
|
||||
fields: fields{
|
||||
eventstore: eventstoreExpect(
|
||||
t,
|
||||
@@ -1530,7 +1530,7 @@ func TestCommandSide_AddSecondFactorLoginPolicy(t *testing.T) {
|
||||
eventFromEventPusher(
|
||||
org.NewLoginPolicySecondFactorAddedEvent(context.Background(),
|
||||
&org.NewAggregate("org1").Aggregate,
|
||||
domain.SecondFactorTypeOTP),
|
||||
domain.SecondFactorTypeTOTP),
|
||||
),
|
||||
},
|
||||
),
|
||||
@@ -1538,11 +1538,96 @@ func TestCommandSide_AddSecondFactorLoginPolicy(t *testing.T) {
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
factor: domain.SecondFactorTypeOTP,
|
||||
factor: domain.SecondFactorTypeTOTP,
|
||||
resourceOwner: "org1",
|
||||
},
|
||||
res: res{
|
||||
want: domain.SecondFactorTypeOTP,
|
||||
want: domain.SecondFactorTypeTOTP,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "add factor otp email, ok",
|
||||
fields: fields{
|
||||
eventstore: eventstoreExpect(
|
||||
t,
|
||||
expectFilter(),
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
org.NewLoginPolicySecondFactorAddedEvent(context.Background(),
|
||||
&org.NewAggregate("org1").Aggregate,
|
||||
domain.SecondFactorTypeOTPEmail),
|
||||
),
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
factor: domain.SecondFactorTypeOTPEmail,
|
||||
resourceOwner: "org1",
|
||||
},
|
||||
res: res{
|
||||
want: domain.SecondFactorTypeOTPEmail,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "add factor otp sms, ok",
|
||||
fields: fields{
|
||||
eventstore: eventstoreExpect(
|
||||
t,
|
||||
expectFilter(),
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
org.NewLoginPolicySecondFactorAddedEvent(context.Background(),
|
||||
&org.NewAggregate("org1").Aggregate,
|
||||
domain.SecondFactorTypeOTPSMS),
|
||||
),
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
factor: domain.SecondFactorTypeOTPSMS,
|
||||
resourceOwner: "org1",
|
||||
},
|
||||
res: res{
|
||||
want: domain.SecondFactorTypeOTPSMS,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "add factor totp, add otp sms, ok",
|
||||
fields: fields{
|
||||
eventstore: eventstoreExpect(
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
org.NewLoginPolicySecondFactorAddedEvent(context.Background(),
|
||||
&org.NewAggregate("org1").Aggregate,
|
||||
domain.SecondFactorTypeTOTP,
|
||||
),
|
||||
),
|
||||
),
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
org.NewLoginPolicySecondFactorAddedEvent(context.Background(),
|
||||
&org.NewAggregate("org1").Aggregate,
|
||||
domain.SecondFactorTypeOTPSMS),
|
||||
),
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
factor: domain.SecondFactorTypeOTPSMS,
|
||||
resourceOwner: "org1",
|
||||
},
|
||||
res: res{
|
||||
want: domain.SecondFactorTypeOTPSMS,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -1593,7 +1678,7 @@ func TestCommandSide_RemoveSecondFactoroginPolicy(t *testing.T) {
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
factor: domain.SecondFactorTypeOTP,
|
||||
factor: domain.SecondFactorTypeTOTP,
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsErrorInvalidArgument,
|
||||
@@ -1624,7 +1709,7 @@ func TestCommandSide_RemoveSecondFactoroginPolicy(t *testing.T) {
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
factor: domain.SecondFactorTypeOTP,
|
||||
factor: domain.SecondFactorTypeTOTP,
|
||||
resourceOwner: "org1",
|
||||
},
|
||||
res: res{
|
||||
@@ -1632,7 +1717,7 @@ func TestCommandSide_RemoveSecondFactoroginPolicy(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "factor removed, not found error",
|
||||
name: "factor totp removed, not found error",
|
||||
fields: fields{
|
||||
eventstore: eventstoreExpect(
|
||||
t,
|
||||
@@ -1640,13 +1725,13 @@ func TestCommandSide_RemoveSecondFactoroginPolicy(t *testing.T) {
|
||||
eventFromEventPusher(
|
||||
org.NewLoginPolicySecondFactorAddedEvent(context.Background(),
|
||||
&org.NewAggregate("org1").Aggregate,
|
||||
domain.SecondFactorTypeOTP,
|
||||
domain.SecondFactorTypeTOTP,
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
org.NewLoginPolicySecondFactorRemovedEvent(context.Background(),
|
||||
&org.NewAggregate("org1").Aggregate,
|
||||
domain.SecondFactorTypeOTP,
|
||||
domain.SecondFactorTypeTOTP,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -1654,7 +1739,7 @@ func TestCommandSide_RemoveSecondFactoroginPolicy(t *testing.T) {
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
factor: domain.SecondFactorTypeOTP,
|
||||
factor: domain.SecondFactorTypeTOTP,
|
||||
resourceOwner: "org1",
|
||||
},
|
||||
res: res{
|
||||
@@ -1662,7 +1747,7 @@ func TestCommandSide_RemoveSecondFactoroginPolicy(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "add factor, ok",
|
||||
name: "factor otp email removed, not found error",
|
||||
fields: fields{
|
||||
eventstore: eventstoreExpect(
|
||||
t,
|
||||
@@ -1670,7 +1755,67 @@ func TestCommandSide_RemoveSecondFactoroginPolicy(t *testing.T) {
|
||||
eventFromEventPusher(
|
||||
org.NewLoginPolicySecondFactorAddedEvent(context.Background(),
|
||||
&org.NewAggregate("org1").Aggregate,
|
||||
domain.SecondFactorTypeOTP,
|
||||
domain.SecondFactorTypeOTPEmail,
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
org.NewLoginPolicySecondFactorRemovedEvent(context.Background(),
|
||||
&org.NewAggregate("org1").Aggregate,
|
||||
domain.SecondFactorTypeOTPEmail,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
factor: domain.SecondFactorTypeOTPEmail,
|
||||
resourceOwner: "org1",
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsNotFound,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "factor otp sms removed, not found error",
|
||||
fields: fields{
|
||||
eventstore: eventstoreExpect(
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
org.NewLoginPolicySecondFactorAddedEvent(context.Background(),
|
||||
&org.NewAggregate("org1").Aggregate,
|
||||
domain.SecondFactorTypeOTPSMS,
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
org.NewLoginPolicySecondFactorRemovedEvent(context.Background(),
|
||||
&org.NewAggregate("org1").Aggregate,
|
||||
domain.SecondFactorTypeOTPSMS,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
factor: domain.SecondFactorTypeOTPSMS,
|
||||
resourceOwner: "org1",
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsNotFound,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "add factor totp, ok",
|
||||
fields: fields{
|
||||
eventstore: eventstoreExpect(
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
org.NewLoginPolicySecondFactorAddedEvent(context.Background(),
|
||||
&org.NewAggregate("org1").Aggregate,
|
||||
domain.SecondFactorTypeTOTP,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -1679,7 +1824,7 @@ func TestCommandSide_RemoveSecondFactoroginPolicy(t *testing.T) {
|
||||
eventFromEventPusher(
|
||||
org.NewLoginPolicySecondFactorRemovedEvent(context.Background(),
|
||||
&org.NewAggregate("org1").Aggregate,
|
||||
domain.SecondFactorTypeOTP),
|
||||
domain.SecondFactorTypeTOTP),
|
||||
),
|
||||
},
|
||||
),
|
||||
@@ -1687,7 +1832,77 @@ func TestCommandSide_RemoveSecondFactoroginPolicy(t *testing.T) {
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
factor: domain.SecondFactorTypeOTP,
|
||||
factor: domain.SecondFactorTypeTOTP,
|
||||
resourceOwner: "org1",
|
||||
},
|
||||
res: res{
|
||||
want: &domain.ObjectDetails{
|
||||
ResourceOwner: "org1",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "add factor otp email, ok",
|
||||
fields: fields{
|
||||
eventstore: eventstoreExpect(
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
org.NewLoginPolicySecondFactorAddedEvent(context.Background(),
|
||||
&org.NewAggregate("org1").Aggregate,
|
||||
domain.SecondFactorTypeOTPEmail,
|
||||
),
|
||||
),
|
||||
),
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
org.NewLoginPolicySecondFactorRemovedEvent(context.Background(),
|
||||
&org.NewAggregate("org1").Aggregate,
|
||||
domain.SecondFactorTypeOTPEmail),
|
||||
),
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
factor: domain.SecondFactorTypeOTPEmail,
|
||||
resourceOwner: "org1",
|
||||
},
|
||||
res: res{
|
||||
want: &domain.ObjectDetails{
|
||||
ResourceOwner: "org1",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "add factor otp sms, ok",
|
||||
fields: fields{
|
||||
eventstore: eventstoreExpect(
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
org.NewLoginPolicySecondFactorAddedEvent(context.Background(),
|
||||
&org.NewAggregate("org1").Aggregate,
|
||||
domain.SecondFactorTypeOTPSMS,
|
||||
),
|
||||
),
|
||||
),
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
org.NewLoginPolicySecondFactorRemovedEvent(context.Background(),
|
||||
&org.NewAggregate("org1").Aggregate,
|
||||
domain.SecondFactorTypeOTPSMS),
|
||||
),
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
factor: domain.SecondFactorTypeOTPSMS,
|
||||
resourceOwner: "org1",
|
||||
},
|
||||
res: res{
|
||||
|
||||
Reference in New Issue
Block a user