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 <bradfitz@tailscale.com>
pull/13088/head
Brad Fitzpatrick 3 months ago committed by Brad Fitzpatrick
parent 0686bc8b19
commit b692985aef

@ -69,6 +69,14 @@ type LocalClient struct {
// connecting to the GUI client variants. // connecting to the GUI client variants.
UseSocketOnly bool 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. // tsClient does HTTP requests to the local Tailscale daemon.
// It's lazily initialized on first use. // It's lazily initialized on first use.
tsClient *http.Client tsClient *http.Client
@ -124,9 +132,11 @@ func (lc *LocalClient) DoLocalRequest(req *http.Request) (*http.Response, error)
}, },
} }
}) })
if !lc.OmitAuth {
if _, token, err := safesocket.LocalTCPPortAndToken(); err == nil { if _, token, err := safesocket.LocalTCPPortAndToken(); err == nil {
req.SetBasicAuth("", token) req.SetBasicAuth("", token)
} }
}
return lc.tsClient.Do(req) return lc.tsClient.Do(req)
} }

Loading…
Cancel
Save