From b3f5af30a44733b860e774eba561e898debf0846 Mon Sep 17 00:00:00 2001 From: Juan Font Alonso Date: Fri, 4 Nov 2022 11:41:45 +0100 Subject: [PATCH] Linting fixes + disable interfacebloat linter --- .golangci.yaml | 3 +++ integration/auth_web_flow_test.go | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index d09a2827..49eea58f 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -33,6 +33,9 @@ linters: - makezero - maintidx + # Limits the methods of an interface to 10. We have more in integration tests + - interfacebloat + # We might want to enable this, but it might be a lot of work - cyclop - nestif diff --git a/integration/auth_web_flow_test.go b/integration/auth_web_flow_test.go index ce0c6f0b..3d164657 100644 --- a/integration/auth_web_flow_test.go +++ b/integration/auth_web_flow_test.go @@ -2,6 +2,7 @@ package integration import ( "context" + "errors" "fmt" "io" "log" @@ -11,6 +12,8 @@ import ( "testing" ) +var errParseAuthPage = errors.New("failed to parse auth page") + type AuthWebFlowScenario struct { *Scenario } @@ -157,8 +160,18 @@ func (s *AuthWebFlowScenario) runHeadscaleRegister(namespaceStr string, loginURL defer resp.Body.Close() // see api.go HTML template - code := strings.Split(string(body), "")[0] - key := strings.Split(code, "key ")[1] + codeSep := strings.Split(string(body), "") + if len(codeSep) != 2 { + return errParseAuthPage + } + + keySep := strings.Split(codeSep[0], "key ") + if len(keySep) != 2 { + return errParseAuthPage + } + key := keySep[1] + log.Printf("registering node %s", key) + if headscale, ok := s.controlServers["headscale"]; ok { _, err = headscale.Execute([]string{"headscale", "-n", namespaceStr, "nodes", "register", "--key", key}) if err != nil { @@ -167,8 +180,6 @@ func (s *AuthWebFlowScenario) runHeadscaleRegister(namespaceStr string, loginURL return err } - log.Printf("registered node %s", key) - return nil }