mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-19 08:46:38 +00:00
Return error from EncodePrefix instead of silently clamping bits
This commit is contained in:
@@ -1262,7 +1262,9 @@ func anonymizePeerConfig(config *mgmProto.PeerConfig, anonymizer *anonymize.Anon
|
||||
|
||||
if v6Prefix, err := netiputil.DecodePrefix(config.GetAddressV6()); err == nil {
|
||||
anonV6 := anonymizer.AnonymizeIP(v6Prefix.Addr())
|
||||
config.AddressV6 = netiputil.EncodePrefix(netip.PrefixFrom(anonV6, v6Prefix.Bits()))
|
||||
if b, err := netiputil.EncodePrefix(netip.PrefixFrom(anonV6, v6Prefix.Bits())); err == nil {
|
||||
config.AddressV6 = b
|
||||
}
|
||||
}
|
||||
|
||||
anonymizeSSHConfig(config.SshConfig)
|
||||
|
||||
@@ -20,6 +20,13 @@ import (
|
||||
"github.com/netbirdio/netbird/shared/netiputil"
|
||||
)
|
||||
|
||||
func mustEncodePrefix(t *testing.T, p netip.Prefix) []byte {
|
||||
t.Helper()
|
||||
b, err := netiputil.EncodePrefix(p)
|
||||
require.NoError(t, err)
|
||||
return b
|
||||
}
|
||||
|
||||
func TestAnonymizeStateFile(t *testing.T) {
|
||||
testState := map[string]json.RawMessage{
|
||||
"null_state": json.RawMessage("null"),
|
||||
@@ -278,7 +285,7 @@ func TestAnonymizeNetworkMap(t *testing.T) {
|
||||
networkMap := &mgmProto.NetworkMap{
|
||||
PeerConfig: &mgmProto.PeerConfig{
|
||||
Address: "203.0.113.5",
|
||||
AddressV6: netiputil.EncodePrefix(origV6Prefix),
|
||||
AddressV6: mustEncodePrefix(t, origV6Prefix),
|
||||
Dns: "1.2.3.4",
|
||||
Fqdn: "peer1.corp.example.com",
|
||||
SshConfig: &mgmProto.SSHConfig{
|
||||
|
||||
Reference in New Issue
Block a user