From c70f5696dc3d755df6fcd5b771c51cad341d8d76 Mon Sep 17 00:00:00 2001 From: Juan Font Alonso Date: Fri, 4 Nov 2022 00:23:20 +0100 Subject: [PATCH] Linting fixes --- integration/auth_web_flow_test.go | 19 +++++++++---------- integration/tsic/tsic.go | 12 ++++++------ 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/integration/auth_web_flow_test.go b/integration/auth_web_flow_test.go index 69fba862..b1d00cf6 100644 --- a/integration/auth_web_flow_test.go +++ b/integration/auth_web_flow_test.go @@ -1,15 +1,14 @@ package integration import ( - "crypto/tls" "fmt" "io" + "log" "net/http" "net/url" "strings" "testing" - - "log" + "time" ) type AuthWebFlowScenario struct { @@ -127,7 +126,6 @@ func (s *AuthWebFlowScenario) runTailscaleUp( if err != nil { log.Printf("failed to register client: %s", err) } - }(client) } namespace.joinWaitGroup.Wait() @@ -143,10 +141,9 @@ func (s *AuthWebFlowScenario) runHeadscaleRegister(namespaceStr string, loginURL loginURL.Host = fmt.Sprintf("%s:8080", s.Headscale().GetIP()) loginURL.Scheme = "http" - insecureTransport := &http.Transport{ - TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + httpClient := &http.Client{ + Timeout: time.Second * 10, } - httpClient := &http.Client{Transport: insecureTransport} resp, err := httpClient.Get(loginURL.String()) if err != nil { @@ -158,21 +155,23 @@ func (s *AuthWebFlowScenario) runHeadscaleRegister(namespaceStr string, loginURL return err } + defer resp.Body.Close() + // see api.go HTML template code := strings.Split(string(body), "")[0] key := strings.Split(code, "key ")[1] if headscale, ok := s.controlServers["headscale"]; ok { - _, err = headscale.Execute([]string{ - "headscale", "-n", namespaceStr, "nodes", "register", "--key", key}) + _, err = headscale.Execute([]string{"headscale", "-n", namespaceStr, "nodes", "register", "--key", key}) if err != nil { log.Printf("failed to register node: %s", err) + return err } log.Printf("registered node %s", key) + return nil } return fmt.Errorf("failed to find headscale: %w", errNoHeadscaleAvailable) - } diff --git a/integration/tsic/tsic.go b/integration/tsic/tsic.go index 627d5a83..0f1d9c85 100644 --- a/integration/tsic/tsic.go +++ b/integration/tsic/tsic.go @@ -23,10 +23,9 @@ const ( ) var ( - errTailscalePingFailed = errors.New("ping failed") - errTailscaleNotLoggedIn = errors.New("tailscale not logged in") - errTailscaleWrongPeerCount = errors.New("wrong peer count") - errTailscaleCannotUpWithoutAuthkey = errors.New("cannot up without authkey") + errTailscalePingFailed = errors.New("ping failed") + errTailscaleNotLoggedIn = errors.New("tailscale not logged in") + errTailscaleWrongPeerCount = errors.New("wrong peer count") ) type TailscaleInContainer struct { @@ -176,14 +175,15 @@ func (t *TailscaleInContainer) UpWithLoginURL( urlStr = strings.TrimSpace(urlStr) // parse URL - loginUrl, err := url.Parse(urlStr) + loginURL, err := url.Parse(urlStr) if err != nil { log.Printf("Could not parse login URL: %s", err) log.Printf("Original join command result: %s", stderr) + return nil, err } - return loginUrl, nil + return loginURL, nil } func (t *TailscaleInContainer) IPs() ([]netip.Addr, error) {