1
0
mirror of https://github.com/netbirdio/netbird.git synced 2025-04-24 03:19:22 +02:00

Return error when peer is not valid ()

Fix count with invalid peers
This commit is contained in:
Maycon Santos 2024-02-13 10:59:31 +01:00 committed by GitHub
parent dd14db6478
commit e890fdae54
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 4 deletions
management/server

View File

@ -115,6 +115,13 @@ func (am *DefaultAccountManager) SaveGroup(accountID, userID string, newGroup *G
if err != nil { if err != nil {
return err 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] oldGroup, exists := account.Groups[newGroup.ID]
account.Groups[newGroup.ID] = newGroup account.Groups[newGroup.ID] = newGroup

View File

@ -240,10 +240,9 @@ func (h *GroupsHandler) GetGroup(w http.ResponseWriter, r *http.Request) {
func toGroupResponse(account *server.Account, group *server.Group) *api.Group { func toGroupResponse(account *server.Account, group *server.Group) *api.Group {
cache := make(map[string]api.PeerMinimum) cache := make(map[string]api.PeerMinimum)
gr := api.Group{ gr := api.Group{
Id: group.ID, Id: group.ID,
Name: group.Name, Name: group.Name,
PeersCount: len(group.Peers), Issued: &group.Issued,
Issued: &group.Issued,
} }
for _, pid := range group.Peers { for _, pid := range group.Peers {
@ -261,5 +260,8 @@ func toGroupResponse(account *server.Account, group *server.Group) *api.Group {
gr.Peers = append(gr.Peers, peerResp) gr.Peers = append(gr.Peers, peerResp)
} }
} }
gr.PeersCount = len(gr.Peers)
return &gr return &gr
} }