mirror of
https://github.com/netbirdio/netbird.git
synced 2025-04-10 18:58:27 +02:00
Disable peer expiration of peers added with setup keys (#758)
This commit is contained in:
parent
628b497e81
commit
e6292e3124
@ -358,11 +358,11 @@ func (a *Account) GetNextPeerExpiration() (time.Duration, bool) {
|
|||||||
return *nextExpiry, true
|
return *nextExpiry, true
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPeersWithExpiration returns a list of peers that have Peer.LoginExpirationEnabled set to true
|
// GetPeersWithExpiration returns a list of peers that have Peer.LoginExpirationEnabled set to true and that were added by a user
|
||||||
func (a *Account) GetPeersWithExpiration() []*Peer {
|
func (a *Account) GetPeersWithExpiration() []*Peer {
|
||||||
peers := make([]*Peer, 0)
|
peers := make([]*Peer, 0)
|
||||||
for _, peer := range a.Peers {
|
for _, peer := range a.Peers {
|
||||||
if peer.LoginExpirationEnabled {
|
if peer.LoginExpirationEnabled && peer.AddedWithSSOLogin() {
|
||||||
peers = append(peers, peer)
|
peers = append(peers, peer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1605,9 +1605,11 @@ func TestAccount_GetPeersWithExpiration(t *testing.T) {
|
|||||||
peers: map[string]*Peer{
|
peers: map[string]*Peer{
|
||||||
"peer-1": {
|
"peer-1": {
|
||||||
LoginExpirationEnabled: false,
|
LoginExpirationEnabled: false,
|
||||||
|
UserID: userID,
|
||||||
},
|
},
|
||||||
"peer-2": {
|
"peer-2": {
|
||||||
LoginExpirationEnabled: false,
|
LoginExpirationEnabled: false,
|
||||||
|
UserID: userID,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedPeers: map[string]struct{}{},
|
expectedPeers: map[string]struct{}{},
|
||||||
@ -1618,9 +1620,11 @@ func TestAccount_GetPeersWithExpiration(t *testing.T) {
|
|||||||
"peer-1": {
|
"peer-1": {
|
||||||
ID: "peer-1",
|
ID: "peer-1",
|
||||||
LoginExpirationEnabled: true,
|
LoginExpirationEnabled: true,
|
||||||
|
UserID: userID,
|
||||||
},
|
},
|
||||||
"peer-2": {
|
"peer-2": {
|
||||||
LoginExpirationEnabled: false,
|
LoginExpirationEnabled: false,
|
||||||
|
UserID: userID,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedPeers: map[string]struct{}{
|
expectedPeers: map[string]struct{}{
|
||||||
@ -1680,12 +1684,14 @@ func TestAccount_GetNextPeerExpiration(t *testing.T) {
|
|||||||
Connected: false,
|
Connected: false,
|
||||||
},
|
},
|
||||||
LoginExpirationEnabled: true,
|
LoginExpirationEnabled: true,
|
||||||
|
UserID: userID,
|
||||||
},
|
},
|
||||||
"peer-2": {
|
"peer-2": {
|
||||||
Status: &PeerStatus{
|
Status: &PeerStatus{
|
||||||
Connected: true,
|
Connected: true,
|
||||||
},
|
},
|
||||||
LoginExpirationEnabled: false,
|
LoginExpirationEnabled: false,
|
||||||
|
UserID: userID,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expiration: time.Second,
|
expiration: time.Second,
|
||||||
@ -1701,12 +1707,14 @@ func TestAccount_GetNextPeerExpiration(t *testing.T) {
|
|||||||
Connected: true,
|
Connected: true,
|
||||||
},
|
},
|
||||||
LoginExpirationEnabled: false,
|
LoginExpirationEnabled: false,
|
||||||
|
UserID: userID,
|
||||||
},
|
},
|
||||||
"peer-2": {
|
"peer-2": {
|
||||||
Status: &PeerStatus{
|
Status: &PeerStatus{
|
||||||
Connected: true,
|
Connected: true,
|
||||||
},
|
},
|
||||||
LoginExpirationEnabled: false,
|
LoginExpirationEnabled: false,
|
||||||
|
UserID: userID,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expiration: time.Second,
|
expiration: time.Second,
|
||||||
@ -1723,6 +1731,7 @@ func TestAccount_GetNextPeerExpiration(t *testing.T) {
|
|||||||
LoginExpired: true,
|
LoginExpired: true,
|
||||||
},
|
},
|
||||||
LoginExpirationEnabled: true,
|
LoginExpirationEnabled: true,
|
||||||
|
UserID: userID,
|
||||||
},
|
},
|
||||||
"peer-2": {
|
"peer-2": {
|
||||||
Status: &PeerStatus{
|
Status: &PeerStatus{
|
||||||
@ -1730,6 +1739,7 @@ func TestAccount_GetNextPeerExpiration(t *testing.T) {
|
|||||||
LoginExpired: true,
|
LoginExpired: true,
|
||||||
},
|
},
|
||||||
LoginExpirationEnabled: true,
|
LoginExpirationEnabled: true,
|
||||||
|
UserID: userID,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expiration: time.Second,
|
expiration: time.Second,
|
||||||
@ -1747,6 +1757,7 @@ func TestAccount_GetNextPeerExpiration(t *testing.T) {
|
|||||||
},
|
},
|
||||||
LoginExpirationEnabled: true,
|
LoginExpirationEnabled: true,
|
||||||
LastLogin: time.Now(),
|
LastLogin: time.Now(),
|
||||||
|
UserID: userID,
|
||||||
},
|
},
|
||||||
"peer-2": {
|
"peer-2": {
|
||||||
Status: &PeerStatus{
|
Status: &PeerStatus{
|
||||||
@ -1754,6 +1765,7 @@ func TestAccount_GetNextPeerExpiration(t *testing.T) {
|
|||||||
LoginExpired: true,
|
LoginExpired: true,
|
||||||
},
|
},
|
||||||
LoginExpirationEnabled: true,
|
LoginExpirationEnabled: true,
|
||||||
|
UserID: userID,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expiration: time.Minute,
|
expiration: time.Minute,
|
||||||
@ -1761,6 +1773,31 @@ func TestAccount_GetNextPeerExpiration(t *testing.T) {
|
|||||||
expectedNextRun: true,
|
expectedNextRun: true,
|
||||||
expectedNextExpiration: expectedNextExpiration,
|
expectedNextExpiration: expectedNextExpiration,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Peers added with setup keys, no expiration",
|
||||||
|
peers: map[string]*Peer{
|
||||||
|
"peer-1": {
|
||||||
|
Status: &PeerStatus{
|
||||||
|
Connected: true,
|
||||||
|
LoginExpired: false,
|
||||||
|
},
|
||||||
|
LoginExpirationEnabled: true,
|
||||||
|
SetupKey: "key",
|
||||||
|
},
|
||||||
|
"peer-2": {
|
||||||
|
Status: &PeerStatus{
|
||||||
|
Connected: true,
|
||||||
|
LoginExpired: false,
|
||||||
|
},
|
||||||
|
LoginExpirationEnabled: true,
|
||||||
|
SetupKey: "key",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expiration: time.Second,
|
||||||
|
expirationEnabled: false,
|
||||||
|
expectedNextRun: false,
|
||||||
|
expectedNextExpiration: time.Duration(0),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
t.Run(testCase.name, func(t *testing.T) {
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
@ -528,7 +528,7 @@ func (am *DefaultAccountManager) AddPeer(setupKey, userID string, peer *Peer) (*
|
|||||||
SSHEnabled: false,
|
SSHEnabled: false,
|
||||||
SSHKey: peer.SSHKey,
|
SSHKey: peer.SSHKey,
|
||||||
LastLogin: time.Now(),
|
LastLogin: time.Now(),
|
||||||
LoginExpirationEnabled: true,
|
LoginExpirationEnabled: addedByUser,
|
||||||
}
|
}
|
||||||
|
|
||||||
// add peer to 'All' group
|
// add peer to 'All' group
|
||||||
|
Loading…
Reference in New Issue
Block a user