mirror of
https://github.com/juanfont/headscale.git
synced 2026-10-01 04:20:53 +09:00
35a90e0018
HEADSCALE_DEBUG_INSECURE_TLS_LISTEN_ADDR serves the router over throwaway TLS and marks the embedded region InsecureForTests: TLS DERP for CA-less clients (tailscale-rs, Android), plus the :443 noise fallback Go redials use.
61 lines
1.7 KiB
Go
61 lines
1.7 KiB
Go
package server
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/juanfont/headscale/hscontrol/types"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"tailscale.com/envknob"
|
|
)
|
|
|
|
// TestGenerateRegionInsecureTLS pins the contract nix/testkit.nix relies on:
|
|
// with the knob set, the embedded node advertises the TLS listener's port and
|
|
// InsecureForTests, so clients without the self-signed cert can relay.
|
|
func TestGenerateRegionInsecureTLS(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
knob string
|
|
wantPort int
|
|
wantInsecure bool
|
|
wantErr bool
|
|
}{
|
|
{name: "unset keeps server_url port", knob: "", wantPort: 80},
|
|
{name: "set advertises TLS port", knob: "[::]:443", wantPort: 443, wantInsecure: true},
|
|
{name: "named port", knob: ":https", wantPort: 443, wantInsecure: true},
|
|
{name: "random port is refused", knob: ":0", wantErr: true},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
envknob.Setenv("HEADSCALE_DEBUG_INSECURE_TLS_LISTEN_ADDR", tt.knob)
|
|
t.Cleanup(func() { envknob.Setenv("HEADSCALE_DEBUG_INSECURE_TLS_LISTEN_ADDR", "") })
|
|
|
|
d := &DERPServer{
|
|
serverURL: "http://headscale",
|
|
cfg: &types.DERPConfig{
|
|
ServerRegionID: 999,
|
|
ServerRegionCode: "headscale",
|
|
STUNAddr: "[::]:3478",
|
|
},
|
|
}
|
|
|
|
region, err := d.GenerateRegion()
|
|
if tt.wantErr {
|
|
require.Error(t, err)
|
|
|
|
return
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
require.Len(t, region.Nodes, 1)
|
|
|
|
node := region.Nodes[0]
|
|
assert.Equal(t, "headscale", node.HostName)
|
|
assert.Equal(t, tt.wantPort, node.DERPPort)
|
|
assert.Equal(t, tt.wantInsecure, node.InsecureForTests)
|
|
assert.Equal(t, 3478, node.STUNPort)
|
|
})
|
|
}
|
|
}
|