ipn/ipnlocal: set the push device token correctly

It would end up resetting whatever hostinfo we had constructed
and leave the backend statemachine in a broken state.
This fixes that by storing the PushDeviceToken on the LocalBackend
and populating it on Hostinfo before passing it to controlclient.

Updates tailscale/corp#8940
Updates tailscale/corp#15367

Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
Maisem Ali
2023-10-23 10:22:34 -07:00
committed by Maisem Ali
parent 0e89245c0f
commit 17b2072b72
4 changed files with 21 additions and 34 deletions

View File

@@ -1553,8 +1553,7 @@ func (h *Handler) serveSetPushDeviceToken(w http.ResponseWriter, r *http.Request
http.Error(w, "invalid JSON body", http.StatusBadRequest)
return
}
hostinfo.SetPushDeviceToken(params.PushDeviceToken)
h.b.ResendHostinfoIfNeeded()
h.b.SetPushDeviceToken(params.PushDeviceToken)
w.WriteHeader(http.StatusOK)
}

View File

@@ -15,7 +15,6 @@ import (
"testing"
"tailscale.com/client/tailscale/apitype"
"tailscale.com/hostinfo"
"tailscale.com/ipn/ipnlocal"
"tailscale.com/tailcfg"
"tailscale.com/tstest"
@@ -77,7 +76,7 @@ func TestSetPushDeviceToken(t *testing.T) {
if res.StatusCode != 200 {
t.Errorf("res.StatusCode=%d, want 200. body: %s", res.StatusCode, body)
}
if got := hostinfo.New().PushDeviceToken; got != want {
if got := h.b.GetPushDeviceToken(); got != want {
t.Errorf("hostinfo.PushDeviceToken=%q, want %q", got, want)
}
}