add ProxyJump function
This commit is contained in:
1 parent
56e20e5464
commit
7f0e0fdb23
48 files changed
+3875
-44
No files matched your search
@@ -0,0 +1,55 @@
|
||||
package keymgr
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"ssh-access-tui/internal/model"
|
||||
)
|
||||
|
||||
func TestRenderInstructionsProxyJump(t *testing.T) {
|
||||
forwards := []model.Forward{
|
||||
{HostName: "db-prod-1", Address: "10.0.0.5", Port: 22, ServiceName: "ssh", Description: "primary db"},
|
||||
{HostName: "db-prod-1", Address: "10.0.0.5", Port: 8080, ServiceName: "web-admin"},
|
||||
}
|
||||
|
||||
out := RenderInstructionsProxyJump("a-makarov", "a-makarov_jump_key", forwards)
|
||||
|
||||
if !strings.Contains(out, "a-makarov") {
|
||||
t.Errorf("expected username in output, got:\n%s", out)
|
||||
}
|
||||
// ProxyJump-mode instructions tell the user to run "ssh <alias>" per
|
||||
// service, not to open one tunnel and point tools at a local port.
|
||||
if strings.Contains(out, "127.0.0.1") {
|
||||
t.Errorf("ProxyJump instructions must not reference local forwarded ports, got:\n%s", out)
|
||||
}
|
||||
if strings.Contains(out, "ssh -N jump") {
|
||||
t.Errorf("ProxyJump instructions must not tell the user to open the always-on tunnel, got:\n%s", out)
|
||||
}
|
||||
for _, wantAlias := range []string{"ssh db-prod-1-ssh", "ssh db-prod-1-web-admin"} {
|
||||
if !strings.Contains(out, wantAlias) {
|
||||
t.Errorf("expected instructions to mention %q, got:\n%s", wantAlias, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderInstructionsProxyJump_NoForwards(t *testing.T) {
|
||||
out := RenderInstructionsProxyJump("nobody", "nobody_jump_key", nil)
|
||||
if !strings.Contains(out, "обратитесь к администратору") {
|
||||
t.Errorf("expected a no-services fallback message, got:\n%s", out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderConfigUpdateInstructionsProxyJump(t *testing.T) {
|
||||
forwards := []model.Forward{
|
||||
{HostName: "cache-1", Address: "10.0.0.9", Port: 6379, ServiceName: "redis"},
|
||||
}
|
||||
out := RenderConfigUpdateInstructionsProxyJump("a-makarov", forwards)
|
||||
|
||||
if strings.Contains(out, "127.0.0.1") {
|
||||
t.Errorf("ProxyJump config-update instructions must not reference local ports, got:\n%s", out)
|
||||
}
|
||||
if !strings.Contains(out, "ssh cache-1") {
|
||||
t.Errorf("expected instructions to mention the cache-1 alias, got:\n%s", out)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user