@@ -3717,3 +3717,80 @@ func TestSqlStore_GetPeersByGroupIDs(t *testing.T) {
37173717 })
37183718 }
37193719}
3720+
3721+ func TestSqlStore_ApproveAccountPeers (t * testing.T ) {
3722+ runTestForAllEngines (t , "" , func (t * testing.T , store Store ) {
3723+ accountID := "test-account"
3724+ ctx := context .Background ()
3725+
3726+ account := newAccountWithId (ctx , accountID , "testuser" , "example.com" )
3727+ err := store .SaveAccount (ctx , account )
3728+ require .NoError (t , err )
3729+
3730+ peers := []* nbpeer.Peer {
3731+ {
3732+ ID : "peer1" ,
3733+ AccountID : accountID ,
3734+ DNSLabel : "peer1.netbird.cloud" ,
3735+ Key : "peer1-key" ,
3736+ IP : net .ParseIP ("100.64.0.1" ),
3737+ Status : & nbpeer.PeerStatus {
3738+ RequiresApproval : true ,
3739+ LastSeen : time .Now ().UTC (),
3740+ },
3741+ },
3742+ {
3743+ ID : "peer2" ,
3744+ AccountID : accountID ,
3745+ DNSLabel : "peer2.netbird.cloud" ,
3746+ Key : "peer2-key" ,
3747+ IP : net .ParseIP ("100.64.0.2" ),
3748+ Status : & nbpeer.PeerStatus {
3749+ RequiresApproval : true ,
3750+ LastSeen : time .Now ().UTC (),
3751+ },
3752+ },
3753+ {
3754+ ID : "peer3" ,
3755+ AccountID : accountID ,
3756+ DNSLabel : "peer3.netbird.cloud" ,
3757+ Key : "peer3-key" ,
3758+ IP : net .ParseIP ("100.64.0.3" ),
3759+ Status : & nbpeer.PeerStatus {
3760+ RequiresApproval : false ,
3761+ LastSeen : time .Now ().UTC (),
3762+ },
3763+ },
3764+ }
3765+
3766+ for _ , peer := range peers {
3767+ err = store .AddPeerToAccount (ctx , peer )
3768+ require .NoError (t , err )
3769+ }
3770+
3771+ t .Run ("approve all pending peers" , func (t * testing.T ) {
3772+ count , err := store .ApproveAccountPeers (ctx , accountID )
3773+ require .NoError (t , err )
3774+ assert .Equal (t , 2 , count )
3775+
3776+ allPeers , err := store .GetAccountPeers (ctx , LockingStrengthNone , accountID , "" , "" )
3777+ require .NoError (t , err )
3778+
3779+ for _ , peer := range allPeers {
3780+ assert .False (t , peer .Status .RequiresApproval , "peer %s should not require approval" , peer .ID )
3781+ }
3782+ })
3783+
3784+ t .Run ("no peers to approve" , func (t * testing.T ) {
3785+ count , err := store .ApproveAccountPeers (ctx , accountID )
3786+ require .NoError (t , err )
3787+ assert .Equal (t , 0 , count )
3788+ })
3789+
3790+ t .Run ("non-existent account" , func (t * testing.T ) {
3791+ count , err := store .ApproveAccountPeers (ctx , "non-existent" )
3792+ require .NoError (t , err )
3793+ assert .Equal (t , 0 , count )
3794+ })
3795+ })
3796+ }
0 commit comments