From ef0f7c0c0992ab9759b74d21e12f4e45a89f5507 Mon Sep 17 00:00:00 2001 From: Juan Font Alonso Date: Mon, 4 Oct 2021 18:04:08 +0200 Subject: [PATCH] Integration tests for MagicDNS working --- app.go | 1 - integration_test.go | 43 +++++++++++++++++++++++--------- integration_test/etc/config.json | 12 +++++++-- 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/app.go b/app.go index 57fa47bb..c8c799b1 100644 --- a/app.go +++ b/app.go @@ -116,7 +116,6 @@ func NewHeadscale(cfg Config) (*Headscale, error) { } } - fmt.Printf("dns: %+v\n", h.cfg.DNSConfig) return &h, nil } diff --git a/integration_test.go b/integration_test.go index e80ff46b..00cff388 100644 --- a/integration_test.go +++ b/integration_test.go @@ -589,7 +589,7 @@ func (s *IntegrationTestSuite) TestTailDrop() { _, err = executeCommand( &tailscale, command, - []string{"ALL_PROXY=socks5://localhost:1055/"}, + []string{"ALL_PROXY=socks5://localhost:1055"}, ) if err == nil { break @@ -642,18 +642,37 @@ func (s *IntegrationTestSuite) TestTailDrop() { } } -// func (s *IntegrationTestSuite) TestMagicDNS() { -// for _, scales := range s.namespaces { -// ips, err := getIPs(scales.tailscales) -// assert.Nil(s.T(), err) -// apiURLs, err := getAPIURLs(scales.tailscales) -// assert.Nil(s.T(), err) +func (s *IntegrationTestSuite) TestMagicDNS() { + for namespace, scales := range s.namespaces { + ips, err := getIPs(scales.tailscales) + assert.Nil(s.T(), err) + for hostname, tailscale := range scales.tailscales { + for peername, ip := range ips { + s.T().Run(fmt.Sprintf("%s-%s", hostname, peername), func(t *testing.T) { + if peername != hostname { + command := []string{ + "tailscale", "ping", + "--timeout=10s", + "--c=20", + "--until-direct=true", + fmt.Sprintf("%s.%s.headscale.net", peername, namespace), + } -// for hostname, tailscale := range scales.tailscales { - -// } -// } -// } + fmt.Printf("Pinging using Hostname (magicdns) from %s (%s) to %s (%s)\n", hostname, ips[hostname], peername, ip) + result, err := executeCommand( + &tailscale, + command, + []string{}, + ) + assert.Nil(t, err) + fmt.Printf("Result for %s: %s\n", hostname, result) + assert.Contains(t, result, "pong") + } + }) + } + } + } +} func getIPs(tailscales map[string]dockertest.Resource) (map[string]netaddr.IP, error) { ips := make(map[string]netaddr.IP) diff --git a/integration_test/etc/config.json b/integration_test/etc/config.json index 8a6fd962..8868d1be 100644 --- a/integration_test/etc/config.json +++ b/integration_test/etc/config.json @@ -7,5 +7,13 @@ "db_type": "sqlite3", "db_path": "/tmp/integration_test_db.sqlite3", "acl_policy_path": "", - "log_level": "debug" -} + "log_level": "debug", + "dns_config": { + "nameservers": [ + "1.1.1.1" + ], + "domains": [], + "magic_dns": true, + "base_domain": "headscale.net" + } +} \ No newline at end of file