mirror of
https://github.com/juanfont/headscale.git
synced 2026-09-27 10:36:35 +09:00
3aece65014
PR tailscale/tailscale#20646 changed the representation of DERP region
IDs from plain ints to a tailcfg.DERPRegionID type. This patch
requires that version of the tailscale.com library and updates our
code to also use the new type.
Updates: tailscale/tailscale#20165
(cherry picked from commit 79695ab51b)
29 lines
868 B
Go
29 lines
868 B
Go
package derp
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"tailscale.com/tailcfg"
|
|
)
|
|
|
|
// TestMergeDERPMapsClonesRegions ensures merged DERP maps own their regions
|
|
// rather than aliasing the source pointers, so a later in-place node shuffle
|
|
// cannot mutate a shared or previously served map.
|
|
func TestMergeDERPMapsClonesRegions(t *testing.T) {
|
|
src := &tailcfg.DERPMap{
|
|
Regions: map[tailcfg.DERPRegionID]*tailcfg.DERPRegion{
|
|
1: {RegionID: 1, Nodes: []*tailcfg.DERPNode{{Name: "a"}, {Name: "b"}}},
|
|
},
|
|
}
|
|
|
|
merged := mergeDERPMaps([]*tailcfg.DERPMap{src})
|
|
|
|
assert.NotSame(t, src.Regions[1], merged.Regions[1],
|
|
"merged region must not alias the source region pointer")
|
|
|
|
merged.Regions[1].Nodes[0] = &tailcfg.DERPNode{Name: "mutated"}
|
|
assert.Equal(t, "a", src.Regions[1].Nodes[0].Name,
|
|
"source region was mutated through a shared pointer")
|
|
}
|