-
Notifications
You must be signed in to change notification settings - Fork 0
206 lines (176 loc) · 6.98 KB
/
test.yml
File metadata and controls
206 lines (176 loc) · 6.98 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
name: Test SSH Sync Action
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
test-ssh-sync:
name: Test SSH Sync Action (${{ matrix.method }})
runs-on: ubuntu-latest
strategy:
matrix:
method: [rsync, scp]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set execute permissions on scripts
run: chmod +x src/*.sh
- name: Set up SSH server and install sshpass
run: |
# Install SSH server and sshpass for password authentication
sudo apt-get update
sudo apt-get install -y openssh-server rsync sshpass
# Setup SSH server
sudo systemctl start ssh
# Enable password authentication
sudo sed -i 's/^#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config
sudo systemctl restart ssh
# Create test user
sudo useradd -m testuser || echo "User already exists"
sudo usermod -s /bin/bash testuser
echo "testuser:testpassword" | sudo chpasswd
# Create test directories and files
sudo mkdir -p /home/testuser/remote-dir
echo "This is a test file" | sudo tee /home/testuser/remote-dir/test-file.txt
echo "Another test file" | sudo tee /home/testuser/remote-dir/another-file.txt
sudo chown -R testuser:testuser /home/testuser/remote-dir || echo "Could not change ownership"
# Setup SSH keys for testing
mkdir -p ~/.ssh
ssh-keygen -t rsa -f ~/.ssh/id_rsa -N "" -q
sudo mkdir -p /home/testuser/.ssh
cat ~/.ssh/id_rsa.pub | sudo tee /home/testuser/.ssh/authorized_keys > /dev/null
sudo chown -R testuser:testuser /home/testuser/.ssh || echo "Could not change ownership"
sudo chmod 700 /home/testuser/.ssh
sudo chmod 600 /home/testuser/.ssh/authorized_keys
# Add localhost to known hosts
ssh-keyscan -H localhost >> ~/.ssh/known_hosts
# Test SSH connection to verify it works
ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa testuser@localhost "echo SSH connection successful"
# Test password authentication to verify it works
sshpass -p "testpassword" ssh -o StrictHostKeyChecking=no testuser@localhost "echo Password authentication successful"
- name: Create test data for upload
run: |
mkdir -p test/upload
mkdir -p test/download
echo "Local file for upload" > test/upload/local-file.txt
echo "Another local file for upload" > test/upload/local-file2.txt
- name: Test first SSH commands
uses: ./
with:
host: localhost
user: testuser
pass: testpassword
first_ssh: |
mkdir -p ~/test-dir
echo "Hello from SSH" > ~/test-dir/hello.txt
ls -la ~/test-dir
cat ~/test-dir/hello.txt
- name: Test rsync upload
if: matrix.method == 'rsync'
uses: ./
with:
host: localhost
user: testuser
pass: testpassword
rsync_upload: |
'./test/upload/*' => /home/testuser/upload-dir/
test/upload/local-file.txt => /home/testuser/single-file.txt
- name: Test scp upload
if: matrix.method == 'scp'
uses: ./
with:
host: localhost
user: testuser
pass: testpassword
scp_upload: |
'./test/upload/*' => /home/testuser/upload-dir/
test/upload/local-file.txt => /home/testuser/single-file.txt
- name: Verify uploads
uses: ./
with:
host: localhost
user: testuser
pass: testpassword
first_ssh: |
ls -la /home/testuser/upload-dir/
ls -la /home/testuser/single-file.txt
cat /home/testuser/single-file.txt
- name: Test rsync download
if: matrix.method == 'rsync'
uses: ./
with:
host: localhost
user: testuser
pass: testpassword
rsync_download: |
/home/testuser/remote-dir/* => ./test/download/
/home/testuser/remote-dir/test-file.txt => ./test/download/single-file.txt
- name: Test scp download
if: matrix.method == 'scp'
uses: ./
with:
host: localhost
user: testuser
pass: testpassword
scp_download: |
/home/testuser/remote-dir/* => ./test/download/
/home/testuser/remote-dir/test-file.txt => ./test/download/single-file.txt
- name: Verify downloads
run: |
ls -la ./test/download/
[ -f "./test/download/test-file.txt" ] && echo "✅ File download successful" || echo "❌ File download failed"
[ -f "./test/download/single-file.txt" ] && echo "✅ Single file download successful" || echo "❌ Single file download failed"
cat ./test/download/test-file.txt
cat ./test/download/single-file.txt
- name: Test last SSH commands
uses: ./
with:
host: localhost
user: testuser
pass: testpassword
last_ssh: |
echo "Cleanup operations"
rm -rf ~/test-dir
rm -rf ~/upload-dir
ls -la ~
test-password-auth:
name: Test Password Authentication
runs-on: ubuntu-latest
needs: test-ssh-sync
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set execute permissions on scripts
run: chmod +x src/*.sh
- name: Set up SSH server with password auth
run: |
# Install SSH server and sshpass
sudo apt-get update
sudo apt-get install -y openssh-server sshpass
# Setup SSH server for password auth
sudo sed -i 's/^#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config
sudo systemctl restart ssh
# Create test user with password
sudo useradd -m testuser2 || true
echo "testuser2:testpassword2" | sudo chpasswd
# Create test directories
sudo mkdir -p /home/testuser2/remote-dir
echo "Password auth test file" | sudo tee /home/testuser2/remote-dir/test-file.txt
sudo chown -R testuser2:testuser2 /home/testuser2/remote-dir
- name: Test SCP with password authentication
uses: ./
with:
host: localhost
user: testuser2
pass: testpassword2
first_ssh: |
echo "Testing password authentication"
ls -la ~
scp_download: |
/home/testuser2/remote-dir/test-file.txt => ./test-password.txt
- name: Verify password auth download
run: |
[ -f "./test-password.txt" ] && echo "✅ Password auth download successful" || echo "❌ Password auth download failed"
cat ./test-password.txt