Skip to content

Commit

Permalink
fix: Inituser (#386)
Browse files Browse the repository at this point in the history
* fix: init user only create change pw event if pw set

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

* fix: tests
  • Loading branch information
hifabienne committed Jul 8, 2020
1 parent c0f85c2 commit a5bfd08
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/local.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ cockroachdb/cockroach:v19.2.2 start --insecure

#### Should show eventstore, management, admin, auth
`show databases;`

3 changes: 3 additions & 0 deletions internal/api/auth/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/user/repository/eventsourcing/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions internal/user/repository/eventsourcing/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package eventsourcing

import (
"context"
"github.com/caos/zitadel/internal/crypto"
"testing"
"time"

Expand Down Expand Up @@ -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},
},
},
{
Expand All @@ -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{
Expand Down

0 comments on commit a5bfd08

Please sign in to comment.