[management] expect specific error types on registration with setup key (#4094)

This commit is contained in:
Pascal Fischer
2025-07-02 20:04:28 +02:00
committed by GitHub
parent 57961afe95
commit 551cb4e467
2 changed files with 13 additions and 4 deletions

View File

@@ -488,7 +488,7 @@ func (am *DefaultAccountManager) AddPeer(ctx context.Context, setupKey, userID s
if addedByUser {
user, err := am.Store.GetUserByUserID(ctx, store.LockingStrengthNone, userID)
if err != nil {
return nil, nil, nil, fmt.Errorf("failed to get user groups: %w", err)
return nil, nil, nil, status.Errorf(status.NotFound, "failed adding new peer: user not found")
}
groupsToAdd = user.AutoGroups
opEvent.InitiatorID = userID
@@ -498,12 +498,12 @@ func (am *DefaultAccountManager) AddPeer(ctx context.Context, setupKey, userID s
// Validate the setup key
sk, err := am.Store.GetSetupKeyBySecret(ctx, store.LockingStrengthNone, encodedHashedKey)
if err != nil {
return nil, nil, nil, fmt.Errorf("failed to get setup key: %w", err)
return nil, nil, nil, status.Errorf(status.NotFound, "couldn't add peer: setup key is invalid")
}
// we will check key twice for early return
if !sk.IsValid() {
return nil, nil, nil, status.Errorf(status.PreconditionFailed, "couldn't add peer: setup key is invalid")
return nil, nil, nil, status.Errorf(status.NotFound, "couldn't add peer: setup key is invalid")
}
opEvent.InitiatorID = sk.Id