-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_test_local.sh
More file actions
executable file
·102 lines (81 loc) · 3.31 KB
/
Copy pathrun_test_local.sh
File metadata and controls
executable file
·102 lines (81 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
set -e
echo "=== Starting SSH Client Wrapper Tests with Dual Hosts ==="
# Start both testbed containers
echo "Starting testbed containers..."
docker compose up testbed testbed2 -d
# Wait for containers to be ready
sleep 5
# Set test environment variables
export TEST_HOST=localhost
export TEST_USER=testuser
export TEST_PW=passw0rd
export TEST_PORT=4100
# For remoteToRemoteCopy tests:
# - From host machine (for verification): use localhost:4101
# - From inside testbed container (for rsync): use testbed2:22
# The dstHostInfo in tests will use testbed2:22 for the actual copy
# but we also need localhost:4101 for verification
export TEST_HOST2=testbed2 # Internal Docker hostname for SSH from testbed
export TEST_HOST2_VERIFY=localhost # External hostname for verification from test
export TEST_USER2=testuser
export TEST_PORT2=22 # Internal Docker port
export TEST_PORT2_VERIFY=4101 # External port for verification
# Remove old host keys
ssh-keygen -R '[localhost]:4100' 2>/dev/null || true
ssh-keygen -R '[localhost]:4101' 2>/dev/null || true
# Create test SSH key directory
TEST_KEY_DIR="./.test-ssh-keys"
TEST_KEY_FILE="$TEST_KEY_DIR/id_rsa"
mkdir -p "$TEST_KEY_DIR"
# Always generate fresh SSH key for testing
echo "Generating test SSH key..."
rm -f "$TEST_KEY_FILE" "$TEST_KEY_FILE.pub"
ssh-keygen -t rsa -b 2048 -f "$TEST_KEY_FILE" -N "" -C "test-key-for-ssh-client-wrapper" >/dev/null 2>&1
# Start ssh-agent and add key
echo "Starting ssh-agent..."
eval "$(ssh-agent -s)"
ssh-add "$TEST_KEY_FILE"
# Install SSH key to both testbed containers using docker exec
echo "Setting up SSH key authentication on testbed containers..."
PUB_KEY=$(cat "$TEST_KEY_FILE.pub")
# Install to testbed (port 4100)
docker exec testbed bash -c "mkdir -p /home/$TEST_USER/.ssh && echo '$PUB_KEY' > /home/$TEST_USER/.ssh/authorized_keys && chmod 700 /home/$TEST_USER/.ssh && chmod 600 /home/$TEST_USER/.ssh/authorized_keys && chown -R $TEST_USER:$TEST_USER /home/$TEST_USER/.ssh"
# Install to testbed2 (port 4101)
docker exec testbed2 bash -c "mkdir -p /home/$TEST_USER/.ssh && echo '$PUB_KEY' > /home/$TEST_USER/.ssh/authorized_keys && chmod 700 /home/$TEST_USER/.ssh && chmod 600 /home/$TEST_USER/.ssh/authorized_keys && chown -R $TEST_USER:$TEST_USER /home/$TEST_USER/.ssh"
# Verify SSH key authentication works
echo "Verifying SSH key authentication..."
if ! ssh -o StrictHostKeyChecking=no -o BatchMode=yes -p 4100 ${TEST_USER}@localhost "echo 'testbed1 connection OK'"; then
echo "ERROR: SSH key auth to testbed1 failed"
docker compose down
exit 1
fi
if ! ssh -o StrictHostKeyChecking=no -o BatchMode=yes -p 4101 ${TEST_USER}@localhost "echo 'testbed2 connection OK'"; then
echo "ERROR: SSH key auth to testbed2 failed"
docker compose down
exit 1
fi
echo "✓ SSH authentication verified on both hosts"
# Enable SSH key for tests
export TEST_KEYFILE="$TEST_KEY_FILE"
echo "Running tests..."
# Run tests
npm run test
TEST_RESULT=$?
if [ $TEST_RESULT -eq 0 ]; then
echo "✓ All tests passed!"
else
echo "✗ Tests failed with exit code: $TEST_RESULT"
fi
# Cleanup
if [ x${1} != xkeep ]; then
echo "Cleaning up..."
# Kill ssh-agent
if [ -n "$SSH_AGENT_PID" ]; then
kill $SSH_AGENT_PID 2>/dev/null || true
fi
docker compose down
# Clean up test SSH keys
rm -f "$TEST_KEY_FILE" "$TEST_KEY_FILE.pub"
fi
exit $TEST_RESULT