|
1 | 1 | package main |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "strings" |
5 | 4 | "testing" |
| 5 | + |
| 6 | + "github.com/gliderlabs/ssh" |
6 | 7 | ) |
7 | 8 |
|
8 | | -func TestBuildInteractiveLoginScriptIncludesDevTmuxBootstrap(t *testing.T) { |
9 | | - script := buildInteractiveLoginScript(map[string]string{}, "/bin/bash", "/workspace", "1") |
| 9 | +func TestNewServerEnablesLocalPortForwarding(t *testing.T) { |
| 10 | + srv := newServer(":2222", "/bin/sh", nil) |
10 | 11 |
|
11 | | - for _, want := range []string{ |
12 | | - "cd '/workspace'", |
13 | | - "/workspace/.okdev/post-attach.sh", |
14 | | - "/var/okdev/dev.tmux.conf", |
15 | | - "exec tmux new-session -A -s okdev", |
16 | | - } { |
17 | | - if !strings.Contains(script, want) { |
18 | | - t.Fatalf("expected script to contain %q, got:\n%s", want, script) |
19 | | - } |
| 12 | + if srv.ChannelHandlers == nil { |
| 13 | + t.Fatal("expected channel handlers to be configured") |
| 14 | + } |
| 15 | + if _, ok := srv.ChannelHandlers["session"]; !ok { |
| 16 | + t.Fatal("expected default session channel handler") |
| 17 | + } |
| 18 | + if _, ok := srv.ChannelHandlers["direct-tcpip"]; !ok { |
| 19 | + t.Fatal("expected direct-tcpip channel handler for ssh forwarding") |
| 20 | + } |
| 21 | + if srv.LocalPortForwardingCallback == nil { |
| 22 | + t.Fatal("expected local port forwarding callback") |
| 23 | + } |
| 24 | + if !srv.LocalPortForwardingCallback(nil, "127.0.0.1", 8080) { |
| 25 | + t.Fatal("expected local port forwarding to be allowed") |
20 | 26 | } |
21 | 27 | } |
22 | 28 |
|
23 | | -func TestBuildInteractiveLoginScriptSkipsTmuxWhenDisabledForSession(t *testing.T) { |
24 | | - script := buildInteractiveLoginScript(map[string]string{"OKDEV_NO_TMUX": "1"}, "/bin/sh", "/workspace", "1") |
25 | | - if strings.Contains(script, "tmux") { |
26 | | - t.Fatalf("expected tmux bootstrap to be skipped, got:\n%s", script) |
| 29 | +func TestNewServerAddsPublicKeyHandlerWhenKeysProvided(t *testing.T) { |
| 30 | + pub, _, _, _, err := ssh.ParseAuthorizedKey([]byte("ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIE9mN6e2Q2x8tQz4pT2r8j04YfGLwRoTSesFiNUFDXL9 test\n")) |
| 31 | + if err != nil { |
| 32 | + t.Fatalf("parse authorized key: %v", err) |
27 | 33 | } |
28 | | - if !strings.Contains(script, "exec '/bin/sh' -l") { |
29 | | - t.Fatalf("expected shell fallback, got:\n%s", script) |
| 34 | + |
| 35 | + srv := newServer(":2222", "/bin/sh", []ssh.PublicKey{pub}) |
| 36 | + if srv.PublicKeyHandler == nil { |
| 37 | + t.Fatal("expected public key handler to be configured") |
30 | 38 | } |
31 | 39 | } |
0 commit comments