Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/sshd/channel_handlers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !windows
// +build !windows2012R2

package main

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// +build windows
// +build windows2012R2

package main

import "code.cloudfoundry.org/diego-ssh/handlers"
import (
"code.cloudfoundry.org/diego-ssh/handlers"
)

func newChannelHandlers() map[string]handlers.NewChannelHandler {
return map[string]handlers.NewChannelHandler{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !external
// +build !windows2012R2

package main_test

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build external
// +build windows2012R2

package main_test

Expand All @@ -13,7 +13,7 @@ import (
)

func buildSshd() string {
sshd, err := gexec.Build("code.cloudfoundry.org/diego-ssh/cmd/sshd", "-race", "-tags", "external")
sshd, err := gexec.Build("code.cloudfoundry.org/diego-ssh/cmd/sshd", "-race", "-tags", "windows2012R2")
Expect(err).NotTo(HaveOccurred())
return sshd
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/sshd/main_internal_port.go → cmd/sshd/main_port.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !external
// +build !windows2012R2

package main

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build external
// +build windows2012R2

package main

Expand Down
7 changes: 7 additions & 0 deletions cmd/sshd/main_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main_test

import (
"encoding/json"
"os"
"runtime"

"code.cloudfoundry.org/diego-ssh/keys"
. "github.com/onsi/ginkgo"
Expand All @@ -26,6 +28,11 @@ func TestSSHDaemon(t *testing.T) {
}

var _ = SynchronizedBeforeSuite(func() []byte {
if runtime.GOOS == "windows" {
if os.Getenv("WINPTY_DLL_PATH") == "" {
Fail("Missing WINPTY_DLL_PATH environment variable")
}
}
sshd := buildSshd()

hostKey, err := keys.RSAKeyPairFactory.NewKeyPair(1024)
Expand Down
36 changes: 28 additions & 8 deletions cmd/sshd/main_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !windows
// +build !windows2012R2

package main_test

Expand All @@ -11,6 +11,7 @@ import (
"os"
"os/exec"
"regexp"
"runtime"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -241,6 +242,10 @@ var _ = Describe("SSH daemon", func() {

var ItDoesNotExposeSensitiveInformation = func() {
It("does not expose the key on the command line", func() {
if runtime.GOOS == "windows" {
Skip("no fork/exec on windows")
}

pid := runner.(*ginkgomon.Runner).Command.Process.Pid
command := exec.Command("ps", "-fp", strconv.Itoa(pid))
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expand Down Expand Up @@ -489,10 +494,17 @@ var _ = Describe("SSH daemon", func() {
session, err := client.NewSession()
Expect(err).NotTo(HaveOccurred())

result, err := session.Output("/bin/echo -n 'Hello there!'")
var cmd string
if runtime.GOOS == "windows" {
cmd = "echo Hello There!"
} else {
cmd = "/bin/echo -n 'Hello There!'"
}

result, err := session.Output(cmd)
Expect(err).NotTo(HaveOccurred())

Expect(string(result)).To(Equal("Hello there!"))
Expect(strings.TrimSpace(string(result))).To(Equal(strings.TrimSpace("Hello There!")))
})
})

Expand All @@ -510,7 +522,7 @@ var _ = Describe("SSH daemon", func() {

stdout := &bytes.Buffer{}

session.Stdin = strings.NewReader("/bin/echo -n $ENV_VAR")
session.Stdin = strings.NewReader(envVarCmd("ENV_VAR"))
session.Stdout = stdout

session.Setenv("ENV_VAR", "env_var_value")
Expand All @@ -529,7 +541,7 @@ var _ = Describe("SSH daemon", func() {

stdout := &bytes.Buffer{}

session.Stdin = strings.NewReader("/bin/echo -n $TEST")
session.Stdin = strings.NewReader(envVarCmd("TEST"))
session.Stdout = stdout

err = session.Shell()
Expand All @@ -547,7 +559,7 @@ var _ = Describe("SSH daemon", func() {

stdout := &bytes.Buffer{}

session.Stdin = strings.NewReader("/bin/echo -n $PATH")
session.Stdin = strings.NewReader(envVarCmd("PATH"))
session.Stdout = stdout

err = session.Shell()
Expand All @@ -571,7 +583,7 @@ var _ = Describe("SSH daemon", func() {

stdout := &bytes.Buffer{}

session.Stdin = strings.NewReader("/bin/echo -n $ENV_VAR")
session.Stdin = strings.NewReader(envVarCmd("ENV_VAR"))
session.Stdout = stdout

session.Setenv("ENV_VAR", "env_var_value")
Expand All @@ -590,7 +602,7 @@ var _ = Describe("SSH daemon", func() {

stdout := &bytes.Buffer{}

session.Stdin = strings.NewReader("/bin/echo -n $TEST")
session.Stdin = strings.NewReader(envVarCmd("TEST"))
session.Stdout = stdout

err = session.Shell()
Expand Down Expand Up @@ -639,3 +651,11 @@ var _ = Describe("SSH daemon", func() {
})
})
})

func envVarCmd(envVar string) string {
if runtime.GOOS == "windows" {
return "echo %" + envVar + "%\r\n"
}

return fmt.Sprintf("/bin/echo -n $%s", envVar)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build windows
// +build windows2012R2

package main_test

Expand Down
9 changes: 9 additions & 0 deletions handlers/handlers_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package handlers_test

import (
"os"
"runtime"

"code.cloudfoundry.org/diego-ssh/keys"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand All @@ -21,4 +24,10 @@ var _ = BeforeSuite(func() {
Expect(err).NotTo(HaveOccurred())

TestHostKey = hostKey.PrivateKey()

if runtime.GOOS == "windows" {
if os.Getenv("WINPTY_DLL_PATH") == "" {
Fail("Missing WINPTY_DLL_PATH environment variable")
}
}
})
2 changes: 1 addition & 1 deletion handlers/session_channel_handler.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !windows
// +build !windows,!windows2012R2

package handlers

Expand Down
2 changes: 1 addition & 1 deletion handlers/session_channel_handler_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !windows
// +build !windows,!windows2012R2

package handlers_test

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build windows
// +build windows2012R2

package handlers

Expand All @@ -15,7 +15,7 @@ func NewSessionChannelHandler() *SessionChannelHandler {
}

func (handler *SessionChannelHandler) HandleNewChannel(logger lager.Logger, newChannel ssh.NewChannel) {
err := newChannel.Reject(ssh.Prohibited, "SSH is not supported on windows cells")
err := newChannel.Reject(ssh.Prohibited, "SSH is not supported on windows2012R2 cells")
if err != nil {
logger.Error("handle-new-session-channel-failed", err)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build windows
// +build windows2012R2

package handlers_test

Expand Down Expand Up @@ -68,7 +68,6 @@ var _ = Describe("SessionChannelHandler", func() {
})

Context("when a session is opened", func() {

It("doesn't accept sessions", func() {
_, sessionErr := client.NewSession()

Expand Down
Loading