fix: address protocol probe review findings

This commit is contained in:
proxyctl coordinator
2026-07-18 00:44:10 +08:00
parent 02b49d5112
commit 954e7d977a
12 changed files with 315 additions and 489 deletions
@@ -105,6 +105,49 @@ func TestCompleteModelProtocolProbeNeverRunsWithoutExplicitInvocation(t *testing
}
}
func TestCompleteModelProtocolProbeCompletionPreservesAnotherEditedFieldsFocusCursorAndViewport(t *testing.T) {
module := &recordingModule{}
model := openProtocolProbeEditor(t, module, func(context.Context, string) (probe.Capabilities, error) {
return probe.Capabilities{HTTP: true}, nil
}, "proxy.example:8080")
model, command := startProtocolProbe(t, model)
model = updateKey(model, "shift+tab")
model = editorKey(model, tea.KeyHome)
model = updateRunes(model, "a-very-long-prefix-that-forces-the-name-field-to-scroll-horizontally-")
model = editorKey(model, tea.KeyLeft)
before := model.View()
assertUsableFrame(t, before, 80, 24, "> Name [focused]", "Protocol Probe: checking proxy.example:8080")
model = finishProtocolProbe(t, model, command)
after := model.View()
assertUsableFrame(t, after, 80, 24, "> Name [focused]", "Protocol Probe: detected HTTP proxy at proxy.example:8080")
if fieldLine(before, "> Name [focused]") != fieldLine(after, "> Name [focused]") {
t.Fatalf("non-mode-changing probe completion reset the edited field viewport or cursor:\nbefore:\n%s\nafter:\n%s", before, after)
}
model = updateRunes(model, "X")
model = updateKey(model, "ctrl+s")
if len(module.intents) != 1 {
t.Fatalf("save after asynchronous completion dispatched %#v", module.intents)
}
if got, want := module.intents[0].Profile.Name, "a-very-long-prefix-that-forces-the-name-field-to-scroll-horizontallyX-office"; got != want {
t.Fatalf("focus/cursor was not preserved: saved name = %q, want %q", got, want)
}
if got := module.intents[0].Profile.SingleURL; got != "http://proxy.example:8080" {
t.Fatalf("probe did not update its affected URL input: %q", got)
}
}
func fieldLine(frame, label string) string {
for _, line := range strings.Split(frame, "\n") {
if strings.Contains(line, label) {
return line
}
}
return ""
}
func TestCompleteModelProtocolProbePopulatesEstablishedCapabilityRepresentations(t *testing.T) {
tests := []struct {
name string
@@ -143,12 +186,12 @@ func TestCompleteModelProtocolProbePopulatesEstablishedCapabilityRepresentations
}
attachedField := "Single proxy URL"
if test.caps.HTTP && test.caps.SOCKS5 {
attachedField = "HTTP URL"
attachedField = "Single proxy URL probe [read-only]"
}
field := strings.Index(view, attachedField)
result := strings.Index(view, "Protocol Probe: detected")
if field < 0 || result < field || strings.Count(view[field:result], "\n") > 1 {
t.Fatalf("capability result was not attached to its populated URL field:\n%s", view)
t.Fatalf("capability result was not attached to its initiating URL context:\n%s", view)
}
model = updateKey(model, "ctrl+s")
@@ -163,6 +206,27 @@ func TestCompleteModelProtocolProbePopulatesEstablishedCapabilityRepresentations
}
}
func TestCompleteModelProtocolProbeDualResultRetainsSingleSourceAndLinksGeneratedFields(t *testing.T) {
model := openProtocolProbeEditor(t, &recordingModule{}, func(context.Context, string) (probe.Capabilities, error) {
return probe.Capabilities{HTTP: true, SOCKS5: true}, nil
}, "proxy.example:7890")
model, command := startProtocolProbe(t, model)
model = finishProtocolProbe(t, model, command)
view := model.View()
assertUsableFrame(t, view, 80, 24,
"Create Proxy Profile — advanced mode",
"Single proxy URL probe [read-only]: proxy.example:7890",
"Protocol Probe: detected HTTP and SOCKS5 proxy at proxy.example:7890",
"Generated Advanced URL fields from this Single proxy URL probe:",
"HTTP URL", "HTTPS URL", "ALL/SOCKS URL")
if strings.Index(view, "Single proxy URL probe [read-only]") > strings.Index(view, "HTTP URL") {
t.Fatalf("initiating Single URL context was not visibly linked before generated fields:\n%s", view)
}
if strings.Contains(fieldLine(view, "HTTP URL"), "Protocol Probe") {
t.Fatalf("dual result was silently relabelled as an HTTP-field probe:\n%s", view)
}
}
func TestCompleteModelProtocolProbeFailureAndUnrecognizedResultsRemainEditableAndSavable(t *testing.T) {
tests := []struct {
name string
@@ -338,33 +402,43 @@ func TestCompleteModelProtocolProbeSurvivesResizeWithoutRestartingOrDetaching(t
}
}
func TestCompleteModelProtocolProbeKeepsCredentialsOutOfDialStatusErrorsAndFrames(t *testing.T) {
func TestCompleteModelProtocolProbeKeepsAllUserinfoOutOfDialStatusErrorsAndEveryFormFrame(t *testing.T) {
const (
inputUser = "alice-private"
inputSecret = "input-secret"
errorUser = "mallory-private"
errorSecret = "error-secret"
)
var dialed []string
model := openProtocolProbeEditor(t, &recordingModule{}, func(_ context.Context, address string) (probe.Capabilities, error) {
module := &recordingModule{}
model := openProtocolProbeEditor(t, module, func(_ context.Context, address string) (probe.Capabilities, error) {
dialed = append(dialed, address)
return probe.Capabilities{}, errors.New("failed https://mallory:" + errorSecret + "@evil.example:9999")
}, "alice:"+inputSecret+"@proxy.example:8080")
return probe.Capabilities{}, errors.New("failed https://" + errorUser + ":" + errorSecret + "@evil.example:9999")
}, inputUser+":"+inputSecret+"@proxy.example:8080")
frames := []string{model.View()}
model, command := startProtocolProbe(t, model)
progress := model.View()
if strings.Contains(progress, inputSecret) {
t.Fatalf("probe progress exposed credentials:\n%s", progress)
}
for _, line := range strings.Split(progress, "\n") {
if strings.Contains(line, "Protocol Probe") && strings.Contains(line, "alice") {
t.Fatalf("probe-generated progress exposed userinfo:\n%s", progress)
}
}
frames = append(frames, model.View())
model = finishProtocolProbe(t, model, command)
view := model.View()
frames = append(frames, model.View())
model = resize(model, 60, 16)
frames = append(frames, model.View())
model = resize(model, 80, 24)
frames = append(frames, model.View())
if len(dialed) != 1 || dialed[0] != "proxy.example:8080" {
t.Fatalf("probe dial evidence = %#v, want credential-free endpoint", dialed)
}
if strings.Contains(view, inputSecret) || strings.Contains(view, errorSecret) || strings.Contains(view, "mallory") {
t.Fatalf("probe frame exposed input or lower-layer credentials:\n%s", view)
for i, frame := range frames {
for _, literal := range []string{inputUser, inputSecret, errorUser, errorSecret} {
if strings.Contains(frame, literal) {
t.Fatalf("form frame %d exposed userinfo literal %q:\n%s", i, literal, frame)
}
}
}
assertUsableFrame(t, frames[len(frames)-1], 80, 24, "Protocol Probe failed for proxy.example:8080")
model = updateKey(model, "ctrl+s")
if len(module.intents) != 1 || module.intents[0].Profile.SingleURL != "http://"+inputUser+":"+inputSecret+"@proxy.example:8080" {
t.Fatalf("userinfo masking weakened saved Profile semantics: %#v", module.intents)
}
assertUsableFrame(t, view, 80, 24, "Protocol Probe failed for proxy.example:8080")
}