Skip to content

Commit 30d557e

Browse files
NathanFlurryclaude
andcommitted
feat: US-007 - Create ssh2-sftp-transfer fixture
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent be70439 commit 30d557e

4 files changed

Lines changed: 78 additions & 1 deletion

File tree

packages/secure-exec/tests/e2e-docker/dockerfiles/sshd.Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ RUN apk add --no-cache openssh \
55
&& echo "testuser:testpass" | chpasswd \
66
&& sed -i 's/^#PasswordAuthentication.*/PasswordAuthentication yes/' /etc/ssh/sshd_config \
77
&& sed -i 's/^#PermitEmptyPasswords.*/PermitEmptyPasswords no/' /etc/ssh/sshd_config \
8-
&& mkdir -p /home/testuser/upload
8+
&& mkdir -p /home/testuser/upload \
9+
&& chown testuser:testuser /home/testuser/upload
910
EXPOSE 22
1011
CMD ["/usr/sbin/sshd", "-D", "-e"]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"entry": "src/index.js",
3+
"expectation": "fail",
4+
"services": ["ssh"],
5+
"fail": {
6+
"code": 1,
7+
"stderrIncludes": "net.Socket is not supported in sandbox"
8+
}
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "e2e-docker-ssh2-sftp-transfer",
3+
"private": true,
4+
"type": "commonjs",
5+
"dependencies": {
6+
"ssh2": "1.17.0"
7+
}
8+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
const { Client } = require("ssh2");
2+
3+
async function main() {
4+
const result = await new Promise((resolve, reject) => {
5+
const conn = new Client();
6+
7+
conn.on("ready", () => {
8+
conn.sftp((err, sftp) => {
9+
if (err) return reject(err);
10+
11+
const remotePath = "/home/testuser/upload/test-e2e.txt";
12+
const content = "hello-sftp-sandbox";
13+
14+
// Write file
15+
const writeStream = sftp.createWriteStream(remotePath);
16+
writeStream.end(content, () => {
17+
// Read it back
18+
sftp.readFile(remotePath, "utf8", (err, data) => {
19+
if (err) return reject(err);
20+
21+
// Stat it
22+
sftp.stat(remotePath, (err, stats) => {
23+
if (err) return reject(err);
24+
25+
// Delete it
26+
sftp.unlink(remotePath, (err) => {
27+
conn.end();
28+
if (err) return reject(err);
29+
resolve({
30+
connected: true,
31+
written: content,
32+
readBack: data,
33+
match: data === content,
34+
size: stats.size,
35+
});
36+
});
37+
});
38+
});
39+
});
40+
});
41+
});
42+
43+
conn.on("error", reject);
44+
45+
conn.connect({
46+
host: process.env.SSH_HOST,
47+
port: Number(process.env.SSH_PORT),
48+
username: "testuser",
49+
password: "testpass",
50+
});
51+
});
52+
53+
console.log(JSON.stringify(result));
54+
}
55+
56+
main().catch((err) => {
57+
console.error(err.message);
58+
process.exit(1);
59+
});

0 commit comments

Comments
 (0)