mirror of
https://github.com/tailscale/tailscale.git
synced 2026-03-28 11:14:06 -04:00
* ipn: reject advertised routes with non-address bits set The config file path, EditPrefs local API, and App Connector API were accepting invalid subnet route prefixes with non-address bits set (e.g., 2a01:4f9:c010:c015::1/64 instead of 2a01:4f9:c010:c015::/64). All three paths now reject prefixes where prefix != prefix.Masked() with an error message indicating the expected masked form. Updates tailscale/corp#36738 Signed-off-by: Brendan Creane <bcreane@gmail.com> * address review comments Signed-off-by: Brendan Creane <bcreane@gmail.com> --------- Signed-off-by: Brendan Creane <bcreane@gmail.com>
67 lines
1.4 KiB
Go
67 lines
1.4 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package ipn
|
|
|
|
import (
|
|
"net/netip"
|
|
"testing"
|
|
)
|
|
|
|
// TestConfigVAlpha_ToPrefs_AdvertiseRoutes tests that ToPrefs validates routes
|
|
// provided directly as netip.Prefix values (not parsed from JSON).
|
|
func TestConfigVAlpha_ToPrefs_AdvertiseRoutes(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
routes []netip.Prefix
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "valid_routes",
|
|
routes: []netip.Prefix{
|
|
netip.MustParsePrefix("10.0.0.0/24"),
|
|
netip.MustParsePrefix("2001:db8::/32"),
|
|
},
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "invalid_ipv4_route",
|
|
routes: []netip.Prefix{
|
|
netip.MustParsePrefix("10.0.0.1/24"),
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "invalid_ipv6_route",
|
|
routes: []netip.Prefix{
|
|
netip.MustParsePrefix("2a01:4f9:c010:c015::1/64"),
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "mixed_valid_and_invalid",
|
|
routes: []netip.Prefix{
|
|
netip.MustParsePrefix("10.0.0.0/24"),
|
|
netip.MustParsePrefix("192.168.1.1/16"),
|
|
netip.MustParsePrefix("2001:db8::/32"),
|
|
netip.MustParsePrefix("2a01:4f9::1/64"),
|
|
},
|
|
wantErr: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
cfg := ConfigVAlpha{
|
|
Version: "alpha0",
|
|
AdvertiseRoutes: tt.routes,
|
|
}
|
|
|
|
_, err := cfg.ToPrefs()
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("cfg.ToPrefs() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|