mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-10-26 21:47:20 +00:00
e9924fac05
Use observed HTTP status to distinguish authentication rejection, denial and unknown cause. Point to the actual saved connection and attempted endpoint without prescribing a role, mutating ACLs or exposing token identities or provider text. Preserve inventory and setup semantics and privilege separation; cover custom/manual identities and real-client 401/403/proxy producer paths. Contract-Neutral: Correct existing diagnostic guidance and expose only internal HTTP-status evidence; no API shape, collection, inventory, setup permission or guest-safety contract changes. Change-source: pulse-maintainer
31 lines
972 B
Go
31 lines
972 B
Go
package proxmox
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestAPIErrorStatusUsesWireEvidenceNotBody(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
name string
|
|
err error
|
|
status int
|
|
known bool
|
|
}{
|
|
{"wire-401", fmt.Errorf("wrapped: %w", &apiResponseError{statusCode: 401, cause: errors.New("API error 403: quoted body")}), 401, true},
|
|
{"wire-403", &apiResponseError{statusCode: 403, cause: errors.New("body says 401")}, 403, true},
|
|
{"proxy-502", &apiResponseError{statusCode: 502, cause: errors.New("API error 403: permission denied")}, 502, true},
|
|
{"login-401", &authHTTPError{status: 401, body: "untrusted 403"}, 401, true},
|
|
{"text-only", errors.New("403 permission denied"), 0, false},
|
|
{"nil", nil, 0, false},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
status, known := APIErrorStatus(tc.err)
|
|
if status != tc.status || known != tc.known {
|
|
t.Fatalf("status/known=%d/%v want %d/%v", status, known, tc.status, tc.known)
|
|
}
|
|
})
|
|
}
|
|
}
|