From b692985aefe4416612223ffd7dcfcaa434b54e8d Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 12 Aug 2024 14:58:54 -0700 Subject: [PATCH] client/tailscale: add LocalClient.OmitAuth for tests Similar to UseSocketOnly, but pulled out separately in case people are doing unknown weird things. Updates #13038 Change-Id: I7478e5cb9794439b947440b831caa798941845ea Signed-off-by: Brad Fitzpatrick --- client/tailscale/localclient.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/client/tailscale/localclient.go b/client/tailscale/localclient.go index 53310e3d1..6f27e56b8 100644 --- a/client/tailscale/localclient.go +++ b/client/tailscale/localclient.go @@ -69,6 +69,14 @@ type LocalClient struct { // connecting to the GUI client variants. UseSocketOnly bool + // OmitAuth, if true, omits sending the local Tailscale daemon any + // authentication token that might be required by the platform. + // + // As of 2024-08-12, only macOS uses an authentication token. OmitAuth is + // meant for when Dial is set and the LocalAPI is being proxied to a + // different operating system, such as in integration tests. + OmitAuth bool + // tsClient does HTTP requests to the local Tailscale daemon. // It's lazily initialized on first use. tsClient *http.Client @@ -124,8 +132,10 @@ func (lc *LocalClient) DoLocalRequest(req *http.Request) (*http.Response, error) }, } }) - if _, token, err := safesocket.LocalTCPPortAndToken(); err == nil { - req.SetBasicAuth("", token) + if !lc.OmitAuth { + if _, token, err := safesocket.LocalTCPPortAndToken(); err == nil { + req.SetBasicAuth("", token) + } } return lc.tsClient.Do(req) }