mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-07-10 00:14:38 +00:00
Verify host uninstall enforces token binding
This commit is contained in:
parent
e069507d97
commit
895a7e07e2
1 changed files with 25 additions and 0 deletions
|
|
@ -164,6 +164,31 @@ func TestHostAgentHandlers_HandleUninstall(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestHostAgentHandlers_HandleUninstallRejectsTokenMismatch(t *testing.T) {
|
||||
handler, monitor := newHostAgentHandlers(t, nil)
|
||||
hostID := seedHostAgent(t, monitor)
|
||||
|
||||
state := monitorState(t, monitor)
|
||||
state.UpsertHost(models.Host{
|
||||
ID: hostID,
|
||||
Hostname: "host-token-mismatch.local",
|
||||
TokenID: "token-1",
|
||||
})
|
||||
|
||||
body := []byte(`{"hostId":"` + hostID + `"}`)
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/agents/host/uninstall", bytes.NewReader(body))
|
||||
attachAPITokenRecord(req, &config.APITokenRecord{
|
||||
ID: "token-2",
|
||||
Scopes: []string{config.ScopeHostReport},
|
||||
})
|
||||
rec := httptest.NewRecorder()
|
||||
|
||||
handler.HandleUninstall(rec, req)
|
||||
if rec.Code != http.StatusForbidden {
|
||||
t.Fatalf("status = %d, want 403: %s", rec.Code, rec.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestHostAgentHandlers_HandleLinkUnlink(t *testing.T) {
|
||||
handler, monitor := newHostAgentHandlers(t, nil)
|
||||
hostID := seedHostAgent(t, monitor)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue