Skip to content

Commit c1b983a

Browse files
Merge pull request #788 from wolfSSL/devin/1740739538-github-action-sftp-test
Add GitHub Action for testing wolfSSH server with Paramiko SFTP client
2 parents 76e8b9f + 647508b commit c1b983a

File tree

1 file changed

+198
-0
lines changed

1 file changed

+198
-0
lines changed
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
name: wolfSSH Paramiko SFTP Test
2+
3+
on:
4+
push:
5+
branches: [ '*' ]
6+
pull_request:
7+
branches: [ '*' ]
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
build_wolfssl:
15+
name: Build wolfssl
16+
runs-on: ubuntu-latest
17+
timeout-minutes: 4
18+
steps:
19+
- name: Checking cache for wolfssl
20+
uses: actions/cache@v4
21+
id: cache-wolfssl
22+
with:
23+
path: build-dir/
24+
key: wolfssh-paramiko-sftp-wolfssl-ubuntu-latest
25+
lookup-only: true
26+
27+
- name: Checkout, build, and install wolfssl
28+
if: steps.cache-wolfssl.outputs.cache-hit != 'true'
29+
uses: wolfSSL/actions-build-autotools-project@v1
30+
with:
31+
repository: wolfssl/wolfssl
32+
ref: master
33+
path: wolfssl
34+
configure: --enable-all
35+
check: false
36+
install: true
37+
38+
paramiko_sftp_test:
39+
needs: build_wolfssl
40+
name: Paramiko SFTP Test
41+
runs-on: ubuntu-latest
42+
timeout-minutes: 10
43+
steps:
44+
- name: Checking cache for wolfssl
45+
uses: actions/cache@v4
46+
with:
47+
path: build-dir/
48+
key: wolfssh-paramiko-sftp-wolfssl-ubuntu-latest
49+
fail-on-cache-miss: true
50+
51+
- uses: actions/checkout@v4
52+
with:
53+
path: wolfssh/
54+
55+
- name: autogen
56+
working-directory: ./wolfssh/
57+
run: ./autogen.sh
58+
59+
- name: configure
60+
working-directory: ./wolfssh/
61+
run: |
62+
./configure --enable-all LDFLAGS="-L${{ github.workspace }}/build-dir/lib" CPPFLAGS="-I${{ github.workspace }}/build-dir/include -DWOLFSSH_NO_FPKI"
63+
64+
- name: make
65+
working-directory: ./wolfssh/
66+
run: make
67+
68+
- name: Install dependencies
69+
run: |
70+
sudo apt-get update
71+
sudo apt-get install -y python3-pip openssh-client
72+
python3 -m pip install paramiko
73+
74+
- name: Create test directories
75+
run: |
76+
mkdir -p /tmp/sftp_upload
77+
mkdir -p /tmp/sftp_download
78+
79+
- name: Create 20MB test file for upload
80+
run: |
81+
dd if=/dev/urandom of=/tmp/sftp_upload/test_upload.dat bs=1M count=20
82+
echo "Created 20MB test file at /tmp/sftp_upload/test_upload.dat"
83+
md5sum /tmp/sftp_upload/test_upload.dat
84+
85+
- name: Configure wolfSSHd
86+
working-directory: ./wolfssh/
87+
run: |
88+
# Create a minimal sshd_config file
89+
cat > sshd_config.txt << EOF
90+
Port 22222
91+
HostKey ./keys/server-key.pem
92+
PasswordAuthentication yes
93+
Subsystem sftp internal-sftp
94+
EOF
95+
96+
# Set proper permissions for keys
97+
chmod 600 ./keys/server-key.pem
98+
99+
# Print debug info
100+
echo "Contents of sshd_config.txt:"
101+
cat sshd_config.txt
102+
103+
- name: Start wolfSSHd
104+
working-directory: ./wolfssh/
105+
run: |
106+
# Create a test user with known password
107+
echo "Creating test user..."
108+
sudo useradd -m testuser
109+
echo "testuser:testpassword" | sudo chpasswd
110+
111+
# Start wolfSSHd with debug output
112+
echo "Starting wolfSSHd..."
113+
sudo ./apps/wolfsshd/wolfsshd -f sshd_config.txt -h ./keys/server-key.pem -p 22222 -d &
114+
echo "Started wolfSSHd on port 22222"
115+
sleep 5 # Give the server time to start
116+
117+
# Check if server is running
118+
if ! nc -z 127.0.0.1 22222; then
119+
echo "Error: wolfSSHd failed to start"
120+
exit 1
121+
fi
122+
123+
# Print debug info
124+
echo "wolfSSHd process info:"
125+
ps aux | grep wolfsshd
126+
127+
- name: Create Paramiko SFTP test script
128+
run: |
129+
cat > /tmp/paramiko_sftp_test.py << 'EOF'
130+
import paramiko
131+
import os
132+
import time
133+
import sys
134+
135+
def run_sftp_test():
136+
# Create SSH client
137+
ssh = paramiko.SSHClient()
138+
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
139+
140+
# Connect to server using password authentication with testuser
141+
print("Connecting to wolfSSHd server...")
142+
try:
143+
ssh.connect('127.0.0.1', port=22222, username='testuser', password='testpassword')
144+
except Exception as e:
145+
print(f"Connection error: {e}")
146+
raise
147+
148+
# Open SFTP session
149+
print("Opening SFTP session...")
150+
sftp = ssh.open_sftp()
151+
152+
# Upload test
153+
print("Uploading 20MB test file...")
154+
start_time = time.time()
155+
sftp.put('/tmp/sftp_upload/test_upload.dat', '/tmp/test_upload.dat')
156+
upload_time = time.time() - start_time
157+
print(f"Upload completed in {upload_time:.2f} seconds")
158+
159+
# Download test
160+
print("Downloading 20MB test file...")
161+
start_time = time.time()
162+
sftp.get('/tmp/test_upload.dat', '/tmp/sftp_download/test_download.dat')
163+
download_time = time.time() - start_time
164+
print(f"Download completed in {download_time:.2f} seconds")
165+
166+
# Close connections
167+
sftp.close()
168+
ssh.close()
169+
170+
print("SFTP session closed")
171+
return True
172+
173+
if __name__ == "__main__":
174+
try:
175+
success = run_sftp_test()
176+
sys.exit(0 if success else 1)
177+
except Exception as e:
178+
print(f"Error: {e}")
179+
sys.exit(1)
180+
EOF
181+
182+
- name: Run Paramiko SFTP test
183+
run: |
184+
python3 /tmp/paramiko_sftp_test.py
185+
186+
- name: Verify file integrity
187+
run: |
188+
echo "Verifying file integrity..."
189+
if cmp -s /tmp/sftp_upload/test_upload.dat /tmp/sftp_download/test_download.dat; then
190+
echo "SFTP Test PASSED: Files match"
191+
else
192+
echo "SFTP Test FAILED: Files do not match"
193+
exit 1
194+
fi
195+
196+
- name: Stop wolfSSHd
197+
run: |
198+
sudo pkill wolfsshd || true

0 commit comments

Comments
 (0)