Explorar o código

Merge branch 'fix/49-allow-update-to-self-ip' into dev

Mustafa Arici %!s(int64=8) %!d(string=hai) anos
pai
achega
e20aef5bac
Modificáronse 2 ficheiros con 3 adicións e 1 borrados
  1. 1 1
      user.go
  2. 2 0
      user_test.go

+ 1 - 1
user.go

@@ -227,7 +227,7 @@ func (u *User) Update(password string, nogw bool, hostid uint32, admin bool) err
 			return fmt.Errorf("ip %s, is out of vpn network %s", ip, network.String())
 		}
 
-		if hostIDsContains(getStaticHostIDs(), hostid) {
+		if u.HostID != hostid && hostIDsContains(getStaticHostIDs(), hostid) {
 			return fmt.Errorf("ip %s is already allocated", ip)
 		}
 	}

+ 2 - 0
user_test.go

@@ -108,6 +108,8 @@ func TestUserUpdate(t *testing.T) {
 		{"123", false, 0, true},
 		{"", true, 0, true},
 		{"", true, ovpm.IP2HostID(net.ParseIP("10.10.10.10").To4()), false}, // Invalid static address.
+		{"333", true, ovpm.IP2HostID(net.ParseIP("10.9.0.7").To4()), true},
+		{"222", true, ovpm.IP2HostID(net.ParseIP("10.9.0.7").To4()), true},
 	}
 
 	for _, tt := range updatetests {