fix: Inituser (#386)

* fix: init user only create change pw event if pw set

* fix: init user only create change pw event if pw set

* fix: tests
This commit is contained in:
Fabi 2020-07-08 09:53:09 +02:00 committed by GitHub
parent c0f85c2733
commit a5bfd085a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 5 deletions

View File

@ -31,3 +31,4 @@ cockroachdb/cockroach:v19.2.2 start --insecure
#### Should show eventstore, management, admin, auth
`show databases;`

View File

@ -15,6 +15,9 @@ func getUserMethodPermissions(ctx context.Context, t TokenVerifier, requiredPerm
if err != nil {
return nil, nil, err
}
if grant == nil {
return context.WithValue(ctx, permissionsKey, []string{}), []string{}, nil
}
permissions := mapGrantToPermissions(requiredPerm, grant, authConfig)
return context.WithValue(ctx, permissionsKey, permissions), permissions, nil
}

View File

@ -47,6 +47,9 @@ func (repo *UserGrantRepo) SearchMyZitadelPermissions(ctx context.Context) ([]st
return nil, err
}
if grant == nil {
return []string{}, nil
}
permissions := &grant_model.Permissions{Permissions: []string{}}
for _, role := range grant.Roles {
roleName, ctxID := auth.SplitPermission(role)

View File

@ -282,7 +282,7 @@ func InitCodeVerifiedAggregate(aggCreator *es_models.AggregateCreator, existing
return nil, err
}
}
if password != nil {
if password != nil && password.Secret != nil {
agg, err = agg.AppendEvent(model.UserPasswordChanged, password)
if err != nil {
return nil, err

View File

@ -2,6 +2,7 @@ package eventsourcing
import (
"context"
"github.com/caos/zitadel/internal/crypto"
"testing"
"time"
@ -756,12 +757,11 @@ func TestInitCodeVerifiedAggregate(t *testing.T) {
Profile: &model.Profile{UserName: "UserName"},
Email: &model.Email{EmailAddress: "EmailAddress", IsEmailVerified: true},
},
password: &model.Password{ChangeRequired: false},
aggCreator: models.NewAggregateCreator("Test"),
},
res: res{
eventLen: 2,
eventTypes: []models.EventType{model.UserPasswordChanged, model.InitializedUserCheckSucceeded},
eventLen: 1,
eventTypes: []models.EventType{model.InitializedUserCheckSucceeded},
},
},
{
@ -772,7 +772,7 @@ func TestInitCodeVerifiedAggregate(t *testing.T) {
Profile: &model.Profile{UserName: "UserName"},
Email: &model.Email{EmailAddress: "EmailAddress"},
},
password: &model.Password{ChangeRequired: false},
password: &model.Password{Secret: &crypto.CryptoValue{}, ChangeRequired: false},
aggCreator: models.NewAggregateCreator("Test"),
},
res: res{