8a4ccab3e6
writeImage drops bash -c/printf for GuestExecStdin(img+\n -> tee /etc/felhom-controller-image); new Runner.RunStdin/GuestExecStdin route stdin through the fenced sudo -n runner. 5 narrow, auditable sudoers grants (no general pct exec, no bash -c) + capability manifest entries (Critical) so the self-probe watches them and the build-test asserts coverage (companion red-proof). No controller change; swap orchestration/rollback/state unchanged. Spike GO. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EPZ4GJ8L5Jqf8UiPwbn1kt
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package proxmox
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
// mockDoer is an injectable HTTP transport for the API client. It records call
|
|
// count and routes each request to fn.
|
|
type mockDoer struct {
|
|
calls int
|
|
fn func(*http.Request) (*http.Response, error)
|
|
}
|
|
|
|
func (m *mockDoer) Do(r *http.Request) (*http.Response, error) {
|
|
m.calls++
|
|
return m.fn(r)
|
|
}
|
|
|
|
// jsonResp builds an HTTP response with a JSON body.
|
|
func jsonResp(code int, body string) *http.Response {
|
|
return &http.Response{
|
|
StatusCode: code,
|
|
Body: io.NopCloser(strings.NewReader(body)),
|
|
Header: http.Header{"Content-Type": []string{"application/json"}},
|
|
}
|
|
}
|
|
|
|
// newTestClient wraps a mockDoer in a Client (bypassing NewClient's real transport).
|
|
func newTestClient(d doer) *Client {
|
|
return &Client{base: "https://host:8006/api2/json", node: "demo-felhom", token: "u@pve!t=secret", http: d}
|
|
}
|
|
|
|
// mockRunner records privileged command invocations and returns canned output.
|
|
type mockRunner struct {
|
|
calls int
|
|
lastCmd string
|
|
lastArg []string
|
|
out []byte
|
|
err error
|
|
}
|
|
|
|
func (m *mockRunner) RunStdin(ctx context.Context, _ io.Reader, name string, args ...string) ([]byte, []byte, error) {
|
|
return m.Run(ctx, name, args...)
|
|
}
|
|
|
|
func (m *mockRunner) Run(_ context.Context, name string, args ...string) ([]byte, []byte, error) {
|
|
m.calls++
|
|
m.lastCmd = name
|
|
m.lastArg = args
|
|
return m.out, nil, m.err
|
|
}
|