- Fix trailing whitespace in kex.rs and s3.rs - Add missing KexProposal import in kex_complete.rs - Auto-fix clippy warnings across all crates - All 153 tests pass
261 lines
7.0 KiB
Markdown
261 lines
7.0 KiB
Markdown
# SSH/SFTP/SCP/rsync 完整整合測試計劃 ⭐⭐⭐⭐⭐
|
|
|
|
**版本**: 1.0 | **日期**: 2026-06-18 | **實施狀態**: Phase 1-16 + Window Control + SFTP batch fix ✅
|
|
|
|
---
|
|
|
|
## 環境
|
|
|
|
- **伺服器**: `markbase-core ssh-start -p 2024` (本機)
|
|
- **用戶**: `demo` / `demo123` (bcrypt)
|
|
- **日誌**: `RUST_LOG=info` 輸出至檔案
|
|
- **計時**: 每個測試 `timeout 30` (大檔案 `timeout 120`)
|
|
|
|
---
|
|
|
|
## 1. SSH 基本連線 (Phase 1-5)
|
|
|
|
```bash
|
|
# 1.1 連線 + 密碼認證
|
|
timeout 10 ssh -v -p 2024 -o StrictHostKeyChecking=no \
|
|
-o UserKnownHostsFile=/dev/null demo@127.0.0.1 'echo "SSH OK"' 2>&1
|
|
|
|
# ✅ 預期: "SSH OK" + debug1: Authentication succeeded (password)
|
|
```
|
|
|
|
---
|
|
|
|
## 2. SFTP 操作 (Phase 7 + batch fix)
|
|
|
|
### 2.1 基礎功能
|
|
|
|
```bash
|
|
timeout 30 sftp -o StrictHostKeyChecking=no \
|
|
-o UserKnownHostsFile=/dev/null -P 2024 demo@127.0.0.1 << 'EOF'
|
|
pwd
|
|
ls
|
|
mkdir sftp_test_dir
|
|
cd sftp_test_dir
|
|
put /etc/hostname test_upload.txt
|
|
get test_upload.txt /tmp/test_download.txt
|
|
rm test_upload.txt
|
|
cd ..
|
|
rmdir sftp_test_dir
|
|
!md5 /tmp/test_download.txt
|
|
bye
|
|
EOF
|
|
```
|
|
|
|
### 2.2 企業級錯誤處理
|
|
|
|
```bash
|
|
timeout 10 sftp -P 2024 demo@127.0.0.1 << 'EOF'
|
|
mkdir /etc/forbidden
|
|
get /root/.ssh/id_rsa
|
|
stat /nonexistent
|
|
rm /nonexistent
|
|
bye
|
|
EOF
|
|
# ✅ 預期: Permission denied / No such file (非 generic Failure)
|
|
```
|
|
|
|
### 2.3 大檔案傳輸 (MD5驗證, 每次 2MB / 5MB / 10MB)
|
|
|
|
```bash
|
|
# 建立測試檔
|
|
dd if=/dev/urandom of=/tmp/test_2m.bin bs=1M count=2 2>/dev/null
|
|
dd if=/dev/urandom of=/tmp/test_5m.bin bs=1M count=5 2>/dev/null
|
|
dd if=/dev/urandom of=/tmp/test_10m.bin bs=1M count=10 2>/dev/null
|
|
|
|
# 測試每個檔案上傳+下載
|
|
for f in test_2m test_5m test_10m; do
|
|
echo "=== Testing $f ==="
|
|
md5sum /tmp/${f}.bin | awk '{print $1}' > /tmp/${f}.md5
|
|
|
|
timeout 120 sftp -P 2024 demo@127.0.0.1 << EOFSFTP 2>&1 | grep -v debug
|
|
put /tmp/${f}.bin ${f}.bin
|
|
get ${f}.bin /tmp/${f}_dl.bin
|
|
rm ${f}.bin
|
|
bye
|
|
EOFSFTP
|
|
|
|
md5sum -c /tmp/${f}.md5 <<< "$(md5sum /tmp/${f}_dl.bin | awk '{print $1}')" 2>/dev/null \
|
|
&& echo "✅ $f PASS" || echo "❌ $f FAIL"
|
|
done
|
|
```
|
|
|
|
### 2.4 多檔案批次傳輸
|
|
|
|
```bash
|
|
# 建立10個小檔
|
|
for i in $(seq 1 10); do
|
|
dd if=/dev/urandom of=/tmp/batch_${i}.bin bs=1K count=64 2>/dev/null
|
|
done
|
|
|
|
# 批次上傳 + 下載 + 驗證
|
|
timeout 60 sftp -P 2024 demo@127.0.0.1 << 'EOF'
|
|
lcd /tmp
|
|
cd /tmp
|
|
put batch_1.bin batch_2.bin batch_3.bin batch_4.bin batch_5.bin
|
|
put batch_6.bin batch_7.bin batch_8.bin batch_9.bin batch_10.bin
|
|
get batch_1.bin batch_2.bin batch_3.bin batch_4.bin batch_5.bin
|
|
get batch_6.bin batch_7.bin batch_8.bin batch_9.bin batch_10.bin
|
|
rm batch_1.bin batch_2.bin batch_3.bin batch_4.bin batch_5.bin
|
|
rm batch_6.bin batch_7.bin batch_8.bin batch_9.bin batch_10.bin
|
|
bye
|
|
EOF
|
|
|
|
# MD5比對
|
|
for i in $(seq 1 10); do
|
|
[ "$(md5sum /tmp/batch_${i}.bin | awk '{print $1}')" = \
|
|
"$(md5sum /tmp/batch_${i}.bin 2>/dev/null | awk '{print $1}')" ] \
|
|
&& echo "✅ batch_${i}" || echo "❌ batch_${i}"
|
|
done
|
|
```
|
|
|
|
---
|
|
|
|
## 3. SCP 測試 (Phase 8)
|
|
|
|
```bash
|
|
# 3.1 上傳
|
|
timeout 30 scp -P 2024 -o StrictHostKeyChecking=no \
|
|
/tmp/test_5m.bin demo@127.0.0.1:scp_test.bin
|
|
|
|
# 3.2 下載
|
|
timeout 30 scp -P 2024 -o StrictHostKeyChecking=no \
|
|
demo@127.0.0.1:scp_test.bin /tmp/scp_dl.bin
|
|
|
|
# 3.3 目錄傳輸
|
|
mkdir -p /tmp/scp_dir && for i in 1 2 3; do
|
|
dd if=/dev/urandom of=/tmp/scp_dir/file_${i}.bin bs=1M count=1 2>/dev/null
|
|
done
|
|
timeout 30 scp -P 2024 -r -o StrictHostKeyChecking=no \
|
|
/tmp/scp_dir demo@127.0.0.1:scp_dir_remote
|
|
|
|
# 3.4 完整驗證
|
|
md5sum /tmp/test_5m.bin /tmp/scp_dl.bin
|
|
md5sum /tmp/scp_dir/*
|
|
rm -rf /tmp/scp_dir
|
|
```
|
|
|
|
---
|
|
|
|
## 4. rsync 測試 (Phase 16 Final: subprocess)
|
|
|
|
```bash
|
|
export RSYNC_RSH="ssh -p 2024 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
|
|
|
|
# 4.1 上傳
|
|
timeout 30 rsync -avz --rsh="$RSYNC_RSH" /tmp/test_5m.bin demo@127.0.0.1:rsync_test.bin
|
|
|
|
# 4.2 下載
|
|
timeout 30 rsync -avz --rsh="$RSYNC_RSH" demo@127.0.0.1:rsync_test.bin /tmp/rsync_dl.bin
|
|
|
|
# 4.3 差異傳輸 (delta transfer)
|
|
echo "extra data" >> /tmp/test_5m.bin
|
|
timeout 30 rsync -avz --rsh="$RSYNC_RSH" /tmp/test_5m.bin demo@127.0.0.1:rsync_test.bin
|
|
|
|
# 4.4 大檔案 (50MB-100MB)
|
|
dd if=/dev/urandom of=/tmp/test_50m.bin bs=1M count=50 2>/dev/null
|
|
md5sum /tmp/test_50m.bin > /tmp/test_50m.md5
|
|
|
|
timeout 120 rsync -avz --rsh="$RSYNC_RSH" /tmp/test_50m.bin demo@127.0.0.1:rsync_large.bin
|
|
timeout 120 rsync -avz --rsh="$RSYNC_RSH" demo@127.0.0.1:rsync_large.bin /tmp/rsync_50m_dl.bin
|
|
md5sum -c /tmp/test_50m.md5 <<< "$(md5sum /tmp/rsync_50m_dl.bin | awk '{print $1}')"
|
|
|
|
# 4.5 目錄同步
|
|
mkdir -p /tmp/rsync_dir && for i in $(seq 1 5); do
|
|
dd if=/dev/urandom of=/tmp/rsync_dir/f_${i}.bin bs=1M count=2 2>/dev/null
|
|
done
|
|
timeout 60 rsync -avz --rsh="$RSYNC_RSH" /tmp/rsync_dir/ demo@127.0.0.1:rsync_dir/
|
|
timeout 60 rsync -avz --rsh="$RSYNC_RSH" demo@127.0.0.1:rsync_dir/ /tmp/rsync_dir_dl/
|
|
```
|
|
|
|
---
|
|
|
|
## 5. SSH 通道指令執行 (Phase 6)
|
|
|
|
```bash
|
|
# 5.1 基本指令
|
|
ssh -p 2024 demo@127.0.0.1 'echo "hello"; whoami; pwd; uname -a'
|
|
|
|
# 5.2 多指令管線
|
|
ssh -p 2024 demo@127.0.0.1 'ls -la /tmp | head -5; echo "---"; df -h | head -3'
|
|
|
|
# 5.3 環境變數
|
|
ssh -p 2024 demo@127.0.0.1 'export TEST_VAR=hello; echo $TEST_VAR'
|
|
```
|
|
|
|
---
|
|
|
|
## 6. 壓力測試
|
|
|
|
### 6.1 連續連線
|
|
|
|
```bash
|
|
for i in $(seq 1 20); do
|
|
echo "=== Iteration $i ==="
|
|
timeout 10 ssh -p 2024 demo@127.0.0.1 'echo OK' 2>&1 | grep "^OK$" \
|
|
&& echo "✅" || echo "❌"
|
|
done
|
|
```
|
|
|
|
### 6.2 並行連線
|
|
|
|
```bash
|
|
for i in $(seq 1 5); do
|
|
(timeout 30 sftp -P 2024 demo@127.0.0.1 << EOF &
|
|
put /tmp/test_5m.bin parallel_${i}.bin
|
|
get parallel_${i}.bin /tmp/parallel_${i}_dl.bin
|
|
rm parallel_${i}.bin
|
|
bye
|
|
EOF
|
|
) &
|
|
done
|
|
wait
|
|
echo "All parallel transfers done"
|
|
```
|
|
|
|
---
|
|
|
|
## 7. 清理
|
|
|
|
```bash
|
|
# 清理伺服器端檔案 (需在 SFTP session 中執行)
|
|
rm scp_test.bin rsync_test.bin rsync_large.bin
|
|
rm -rf rsync_dir scp_dir_remote
|
|
|
|
# 清理本機暫存
|
|
rm -f /tmp/test_upload.txt /tmp/test_download.txt
|
|
rm -f /tmp/test_2m.bin /tmp/test_5m.bin /tmp/test_10m.bin
|
|
rm -f /tmp/test_2m_dl.bin /tmp/test_5m_dl.bin /tmp/test_10m_dl.bin
|
|
rm -f /tmp/rsync_test.bin /tmp/rsync_dl.bin /tmp/rsync_large.bin
|
|
rm -f /tmp/test_50m.bin /tmp/rsync_50m_dl.bin
|
|
rm -f /tmp/scp_test.bin /tmp/scp_dl.bin
|
|
rm -rf /tmp/rsync_dir /tmp/rsync_dir_dl /tmp/scp_dir
|
|
rm -f /tmp/batch_*.bin /tmp/parallel_*.bin
|
|
```
|
|
|
|
---
|
|
|
|
## 驗證矩陣
|
|
|
|
| 編號 | 測試項目 | 預期結果 | 檢查方法 |
|
|
|------|----------|----------|----------|
|
|
| 1.1 | SSH連線+認證 | `SSH OK` 輸出 | stdout |
|
|
| 2.1 | SFTP基礎功能 | 所有操作成功 | exit code=0 |
|
|
| 2.2 | SFTP錯誤處理 | 非 generic 錯誤 | 日誌比對 |
|
|
| 2.3 | SFTP大檔案 | MD5吻合 | md5sum |
|
|
| 2.4 | SFTP批次檔案 | 所有MD5吻合 | md5sum |
|
|
| 3.1 | SCP上傳 | 檔案存在 | md5sum |
|
|
| 3.2 | SCP下載 | MD5吻合 | md5sum |
|
|
| 3.3 | SCP目錄 | 結構一致 | ls -la |
|
|
| 4.1 | rsync上傳 | MD5吻合 | md5sum |
|
|
| 4.2 | rsync下載 | MD5吻合 | md5sum |
|
|
| 4.3 | rsync增量 | 僅傳差異 | speedup > 1 |
|
|
| 4.4 | rsync 50MB | MD5吻合 | md5sum |
|
|
| 5.1 | Shell指令 | 正確輸出 | stdout |
|
|
| 6.1 | 連續連線20次 | 100%成功 | 計數 |
|
|
| 6.2 | 並行xfer | 所有MD5吻合 | md5sum |
|