Skip to content

Commit

Permalink
Update Dockerfile to use pre-built OpenSSH binary and fix test refere…
Browse files Browse the repository at this point in the history
…nce to SSH binary (#522)

* Update Dockerfile to use pre-built OpenSSH binary and fix test reference to SSH binary

* Add support for multiple SSH binary versions in tests
  • Loading branch information
tg123 authored Feb 6, 2025
1 parent 9b7128b commit 77e9b21
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 42 deletions.
12 changes: 3 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,9 @@ RUN --mount=target=/src,type=bind,source=. --mount=type=cache,target=/root/.cach
ADD entrypoint.sh /sshpiperd

FROM builder as testrunner
RUN apt update && apt install -y autoconf automake libssl-dev libz-dev

RUN cd /tmp && \
curl -fsSL https://github.com/openssh/openssh-portable/archive/refs/tags/V_9_8_P1.tar.gz | tar xz && \
cd openssh-portable-V_9_8_P1 && \
autoreconf && \
./configure && \
make ssh && \
cp ssh /usr/bin/ssh-9.8.1p1

COPY --from=farmer1992/openssh-static:V_9_8_P1 /usr/bin/ssh /usr/bin/ssh-9.8p1
COPY --from=farmer1992/openssh-static:V_8_0_P1 /usr/bin/ssh /usr/bin/ssh-8.0p1

FROM docker.io/busybox
# LABEL maintainer="Boshi Lian<[email protected]>"
Expand Down
83 changes: 50 additions & 33 deletions e2e/fixed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,58 @@ func TestFixed(t *testing.T) {

waitForEndpointReady(piperaddr)

randtext := uuid.New().String()
targetfie := uuid.New().String()

c, stdin, stdout, err := runCmd(
"ssh-9.8.1p1",
"-v",
"-o",
"StrictHostKeyChecking=no",
"-o",
"UserKnownHostsFile=/dev/null",
"-o",
"RequestTTY=yes",
"-p",
piperport,
"-l",
"user",
"127.0.0.1",
fmt.Sprintf(`sh -c "echo SSHREADY && sleep 1 && echo -n %v > /shared/%v"`, randtext, targetfie), // sleep 1 to cover https://github.com/tg123/sshpiper/issues/323
)

if err != nil {
t.Errorf("failed to ssh to piper-fixed, %v", err)
for _, tc := range []struct {
name string
bin string
}{
{
name: "without-sshping",
bin: "ssh-8.0p1",
},
{
name: "with-sshping",
bin: "ssh-9.8p1",
},
} {
t.Run(tc.name, func(t *testing.T) {
randtext := uuid.New().String()
targetfie := uuid.New().String()

c, stdin, stdout, err := runCmd(
tc.bin,
"-v",
"-o",
"StrictHostKeyChecking=no",
"-o",
"UserKnownHostsFile=/dev/null",
"-o",
"RequestTTY=yes",
"-p",
piperport,
"-l",
"user",
"127.0.0.1",
fmt.Sprintf(`sh -c "echo SSHREADY && sleep 1 && echo -n %v > /shared/%v"`, randtext, targetfie), // sleep 1 to cover https://github.com/tg123/sshpiper/issues/323
)

if err != nil {
t.Errorf("failed to ssh to piper-fixed, %v", err)
}

defer killCmd(c)

enterPassword(stdin, stdout, "pass")

waitForStdoutContains(stdout, "SSHREADY", func(_ string) {
_, _ = stdin.Write([]byte(fmt.Sprintf("%v\n", "triggerping")))
})

time.Sleep(time.Second * 3) // wait for file flush

checkSharedFileContent(t, targetfie, randtext)
})
}

defer killCmd(c)

enterPassword(stdin, stdout, "pass")

waitForStdoutContains(stdout, "SSHREADY", func(_ string) {
_, _ = stdin.Write([]byte(fmt.Sprintf("%v\n", "triggerping")))
})

time.Sleep(time.Second * 3) // wait for file flush

checkSharedFileContent(t, targetfie, randtext)
}

func TestHostkeyParam(t *testing.T) {
Expand Down

0 comments on commit 77e9b21

Please sign in to comment.