feat: sftp, scp, and named port forwards
Add netssh sftp and netssh scp. Both resolve the host like a connection does (cache, shortcuts and rewrites, instance/host, default user and port, SSH options and rules, --jump/--no-jump, --dry-run) and get shell completion. The per-client flag tables handle the differences from ssh: the port is -P, -l is a bandwidth limit (the default user goes in as -o User=), and IPv6 addresses are bracketed in host:path. All remote scp operands must name the same host. Add named port forwards under ssh.forwards (global, per instance, per rule; a more specific layer replaces a forward of the same name), netssh tunnel HOST NAME|SPEC... (ssh -N with ExitOnForwardFailure) and netssh --forward NAME. Specs such as 8080:localhost:80 work without configuration. Forwards are editable in netssh configure and completed in the shell; the TUI opens SFTP with ctrl+o and a tunnel with ctrl+t. Host resolution moves out of runSSHWrapper into resolveTarget, shared by ssh, sftp, scp, tunnel, and the TUI. Options added by netssh are now inserted before the first operand or "--": after "--", ssh read them as the destination, and scp stops reading options at the first operand. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
878701aba7
commit
b7fa71fe45
19 files changed
+1389
-141
No files matched your search
@@ -1,6 +1,8 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
tea "charm.land/bubbletea/v2"
|
||||
@@ -70,3 +72,53 @@ func TestConnectionEditorKeepsOriginalHost(t *testing.T) {
|
||||
t.Fatalf("edited host changed: %+v", m.selected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCtrlOSelectsSFTP(t *testing.T) {
|
||||
m := New(nil, nil, "")
|
||||
m.updateListItems([]netbox.HostEntry{{Name: "web01", PrimaryIP4: "10.0.0.1"}})
|
||||
m.Update(tea.KeyPressMsg{Code: 'o', Mod: tea.ModCtrl})
|
||||
if m.selected == nil || m.selected.Action != ActionSFTP || m.selected.Name != "web01" {
|
||||
t.Fatalf("got %+v", m.selected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCtrlTStartsTunnelWithForwards(t *testing.T) {
|
||||
m := New(nil, nil, "")
|
||||
m.SetForwards(func(name, kind string, tags []string) []string {
|
||||
if name != "web01" || len(tags) != 1 {
|
||||
t.Errorf("forwards asked for %s %v", name, tags)
|
||||
}
|
||||
return []string{"web"}
|
||||
})
|
||||
m.updateListItems([]netbox.HostEntry{{Name: "web01", PrimaryIP4: "10.0.0.1", Tags: []string{"dmz"}}})
|
||||
m.Update(tea.KeyPressMsg{Code: 't', Mod: tea.ModCtrl})
|
||||
if !m.forwardMode || m.selected != nil {
|
||||
t.Fatal("forward input not opened")
|
||||
}
|
||||
if !strings.Contains(m.viewContent(), "forwards: web") {
|
||||
t.Fatalf("configured forwards not shown:\n%s", m.viewContent())
|
||||
}
|
||||
|
||||
m.forwardInput.SetValue("nope")
|
||||
m.Update(tea.KeyPressMsg{Code: tea.KeyEnter})
|
||||
if m.selected != nil || m.err == nil {
|
||||
t.Fatal("unknown forward accepted")
|
||||
}
|
||||
|
||||
m.forwardInput.SetValue("WEB, 9000:localhost:9000")
|
||||
m.Update(tea.KeyPressMsg{Code: tea.KeyEnter})
|
||||
want := []string{"WEB", "9000:localhost:9000"}
|
||||
if m.selected == nil || m.selected.Action != ActionTunnel || !reflect.DeepEqual(m.selected.Forwards, want) {
|
||||
t.Fatalf("got %+v", m.selected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestForwardInputEscCancels(t *testing.T) {
|
||||
m := New(nil, nil, "")
|
||||
m.updateListItems([]netbox.HostEntry{{Name: "web01"}})
|
||||
m.Update(tea.KeyPressMsg{Code: 't', Mod: tea.ModCtrl})
|
||||
m.Update(tea.KeyPressMsg{Code: tea.KeyEscape})
|
||||
if m.forwardMode || m.selected != nil {
|
||||
t.Fatal("esc did not cancel")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user