mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-04-29 12:00:13 +00:00
Restore legacy host config fetch compatibility (#1254)
This commit is contained in:
parent
4120d75359
commit
04a828264a
3 changed files with 70 additions and 1 deletions
|
|
@ -44,3 +44,37 @@ func TestHostAgentConfigUsesTokenBindingInRouter(t *testing.T) {
|
|||
t.Fatalf("expected host id %q, got %q", "host-1", resp.HostID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHostAgentConfigAllowsLegacyHostReportScopeInRouter(t *testing.T) {
|
||||
rawToken := "host-config-legacy-token-123.12345678"
|
||||
record := newTokenRecord(t, rawToken, []string{config.ScopeHostReport}, nil)
|
||||
record.ID = "token-1"
|
||||
|
||||
cfg := newTestConfigWithTokens(t, record)
|
||||
|
||||
state := models.NewState()
|
||||
state.UpsertHost(models.Host{ID: "host-1", TokenID: "token-1"})
|
||||
monitor := &monitoring.Monitor{}
|
||||
setUnexportedField(t, monitor, "state", state)
|
||||
|
||||
router := NewRouter(cfg, monitor, nil, nil, nil, "1.0.0")
|
||||
|
||||
req := httptest.NewRequest(http.MethodGet, "/api/agents/host/host-2/config", nil)
|
||||
req.Header.Set("X-API-Token", rawToken)
|
||||
rec := httptest.NewRecorder()
|
||||
router.Handler().ServeHTTP(rec, req)
|
||||
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("expected 200 for legacy bound host config, got %d", rec.Code)
|
||||
}
|
||||
|
||||
var resp struct {
|
||||
HostID string `json:"hostId"`
|
||||
}
|
||||
if err := json.NewDecoder(rec.Body).Decode(&resp); err != nil {
|
||||
t.Fatalf("decode response: %v", err)
|
||||
}
|
||||
if resp.HostID != "host-1" {
|
||||
t.Fatalf("expected host id %q, got %q", "host-1", resp.HostID)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue