Skip to content

Commit

Permalink
tests: add unittest for upload_file method
Browse files Browse the repository at this point in the history
  • Loading branch information
Miyoshi-Ryota committed May 5, 2024
1 parent 536167a commit b838acc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ ASYNC_SSH2_TEST_CLIENT_PROT_PRIV
ASYNC_SSH2_TEST_CLIENT_PRIV
ASYNC_SSH2_TEST_CLIENT_PROT_PASS
ASYNC_SSH2_TEST_SERVER_PUB
ASYNC_SSH2_TEST_UPLOAD_FILE
",
)
}
Expand Down Expand Up @@ -791,4 +792,12 @@ ASYNC_SSH2_TEST_SERVER_PUB
assert_eq!(result1.stdout, "test clone\n");
assert_eq!(result2.stdout, "test clone2\n");
}

#[tokio::test]
async fn client_can_upload_file() {
let client = establish_test_host_connection().await;
let _ = client.upload_file(&env("ASYNC_SSH2_TEST_UPLOAD_FILE"), "/tmp/uploaded").await.unwrap();
let result = client.execute("cat /tmp/uploaded").await.unwrap();
assert_eq!(result.stdout, "this is a test file\n");
}
}
1 change: 1 addition & 0 deletions tests/async-ssh2-tokio/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ENV ASYNC_SSH2_TEST_SERVER_PUB=/root/server.ed25519.pub
ENV ASYNC_SSH2_TEST_HOST_PORT=22
ENV ASYNC_SSH2_TEST_HOST_NAME=ssh-server
ENV ASYNC_SSH2_TEST_KNOWN_HOSTS=/root/.ssh/known_hosts
ENV ASYNC_SSH2_TEST_UPLOAD_FILE=/async-ssh2-tokio/tests/async-ssh2-tokio/test-upload-file

COPY tests/async-ssh2-tokio/id_ed25519 /root/.ssh/id_ed25519
COPY tests/async-ssh2-tokio/id_ed25519.pub /root/.ssh/id_ed25519.pub
Expand Down
1 change: 1 addition & 0 deletions tests/async-ssh2-tokio/test-upload-file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is a test file
3 changes: 3 additions & 0 deletions tests/sshd-test/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ FROM linuxkit/sshd:62036c2a279715d05e8298b9269a0659964f2619-amd64

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

RUN apk add openssh-sftp-server

# hadolint ignore=DL3006
RUN echo 'root:root' |chpasswd

RUN sed -ri 's/^#?PermitRootLogin\s+.*/PermitRootLogin yes/g' /etc/ssh/sshd_config
RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
RUN sed -ri 's/^#?PasswordAuthentication.*$/PasswordAuthentication yes/g' /etc/ssh/sshd_config
RUN sed -ri 's/^#Subsystem/Subsystem/g' /etc/ssh/sshd_config

COPY ssh_host_ed25519_key ssh_host_ed25519_key.pub /etc/ssh/
COPY authorized_keys /root/.ssh/authorized_keys
Expand Down

0 comments on commit b838acc

Please sign in to comment.