Skip to content

Commit

Permalink
Return error when peer is not valid (#1573)
Browse files Browse the repository at this point in the history
Fix count with invalid peers
  • Loading branch information
mlsmaycon committed Feb 13, 2024
1 parent dd14db6 commit e890fda
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 7 additions & 0 deletions management/server/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ func (am *DefaultAccountManager) SaveGroup(accountID, userID string, newGroup *G
if err != nil {
return err
}

for _, peerID := range newGroup.Peers {
if account.Peers[peerID] == nil {
return status.Errorf(status.InvalidArgument, "peer with ID \"%s\" not found", peerID)
}
}

oldGroup, exists := account.Groups[newGroup.ID]
account.Groups[newGroup.ID] = newGroup

Expand Down
10 changes: 6 additions & 4 deletions management/server/http/groups_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,9 @@ func (h *GroupsHandler) GetGroup(w http.ResponseWriter, r *http.Request) {
func toGroupResponse(account *server.Account, group *server.Group) *api.Group {
cache := make(map[string]api.PeerMinimum)
gr := api.Group{
Id: group.ID,
Name: group.Name,
PeersCount: len(group.Peers),
Issued: &group.Issued,
Id: group.ID,
Name: group.Name,
Issued: &group.Issued,
}

for _, pid := range group.Peers {
Expand All @@ -261,5 +260,8 @@ func toGroupResponse(account *server.Account, group *server.Group) *api.Group {
gr.Peers = append(gr.Peers, peerResp)
}
}

gr.PeersCount = len(gr.Peers)

return &gr
}

0 comments on commit e890fda

Please sign in to comment.