-
Notifications
You must be signed in to change notification settings - Fork 92
178 lines (151 loc) · 5.59 KB
/
test-fatfs.yml
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
name: Test FATFS Support
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:
jobs:
get-fatfs:
runs-on: ubuntu-latest
steps:
- name: Set up cache key
id: cache-key
run: echo "CACHE_KEY=ff15a-cache" >> $GITHUB_ENV
- name: Download FF15a.zip
id: download
run: |
wget http://elm-chan.org/fsw/ff/arc/ff15a.zip -O ff15a.zip
- name: Cache the downloaded ZIP file
uses: actions/cache@v4
with:
path: ./ff15a.zip
key: ${{ env.CACHE_KEY }}
restore-keys: |
${{ env.CACHE_KEY }}
test-fatfs:
needs: get-fatfs
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Checking cache for FATFS
uses: actions/cache@v4
with:
path: ./ff15a.zip
key: ff15a-cache
fail-on-cache-miss: true
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential autoconf automake libtool pkg-config openssh-server dosfstools
- name: Clone wolfSSL
run: |
cd ..
git clone https://github.com/wolfSSL/wolfssl.git
cd wolfssl
./autogen.sh
- name: Configure and build wolfSSL
run: |
cd ../wolfssl
./configure --enable-wolfssh --enable-intelasm --disable-crl --disable-examples --disable-filesystem CFLAGS="-DNO_WOLFSSL_DIR"
make
sudo make install
sudo ldconfig
- name: Compile FATFS library
run: |
cd ide/Linux-FATFS
unzip ../../ff15a.zip
cp ffconf.h source/
make
- name: Configure and build wolfSSH with FATFS
run: |
./autogen.sh
export LD_LIBRARY_PATH=$(pwd)/ide/Linux-FATFS
./configure --enable-sftp CFLAGS="-DWOLFSSH_FATFS -Iide/Linux-FATFS/source -DSTDIN_FILENO=0 -DPRINTF=printf" LDFLAGS="-Lide/Linux-FATFS -lfatfs"
make
- name: Create test file
run: |
dd if=/dev/urandom of=test_file.bin bs=1M count=1
- name: Setup SSH server
run: |
sudo mkdir -p /run/sshd
sudo /usr/sbin/sshd
mkdir -p ~/.ssh
ssh-keygen -t rsa -f ~/.ssh/id_rsa -N ""
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
echo "Host localhost" > ~/.ssh/config
echo " StrictHostKeyChecking no" >> ~/.ssh/config
echo " UserKnownHostsFile=/dev/null" >> ~/.ssh/config
chmod 600 ~/.ssh/config
- name: Install expect
run: |
sudo apt-get update
sudo apt-get install -y expect
- name: Run wolfsftp client to get file
run: |
# Export the library path
export LD_LIBRARY_PATH=$(pwd)/ide/Linux-FATFS
# Get the full path to the test file
TEST_FILE_PATH=$(pwd)/test_file.bin
# Change to the sftpclient directory
cd examples/sftpclient
# Create the FATFS image file directly in the sftpclient directory
dd if=/dev/zero of=fatfs_image.img bs=1M count=32
mkdosfs fatfs_image.img
# Create a test user with a known password and add to the same group as the runner
sudo useradd -m testuser
echo "testuser:password123" | sudo chpasswd
sudo usermod -aG $(id -gn) testuser
# Make the test file accessible to testuser
chmod 644 ${TEST_FILE_PATH}
sudo chown testuser:$(id -gn) ${TEST_FILE_PATH}
# Configure SSH server to allow SFTP access
sudo sed -i 's/^#Subsystem\s\+sftp.*/Subsystem sftp \/usr\/lib\/openssh\/sftp-server/' /etc/ssh/sshd_config
sudo service ssh restart || sudo /etc/init.d/ssh restart || sudo /usr/sbin/sshd -t && sudo kill -HUP $(pgrep -f sshd)
# Create expect script to automate the wolfsftp client interaction
cat > /tmp/sftp_test.exp << EOF
#!/usr/bin/expect -f
set timeout 60
spawn ./wolfsftp -N -h localhost -p 22 -u testuser
expect "Password:"
send "password123\r"
expect "wolfSSH sftp>"
send "get ${TEST_FILE_PATH} test_file.bin\r"
expect "wolfSSH sftp>"
send "exit\r"
expect eof
EOF
chmod +x /tmp/sftp_test.exp
# Run the expect script
/tmp/sftp_test.exp
- name: Verify file in FATFS image
run: |
cd examples/sftpclient
sudo mkdir -p /mnt/fatfs
LOOPDEV=$(sudo losetup -f)
sudo losetup $LOOPDEV fatfs_image.img
sudo mount $LOOPDEV /mnt/fatfs
if [ -f /mnt/fatfs/test_file.bin ]; then
echo "File exists in FATFS image!"
ls -la /mnt/fatfs/
# Verify file contents match
if cmp -s ../../test_file.bin /mnt/fatfs/test_file.bin; then
echo "File contents match! FATFS test PASSED."
sudo umount /mnt/fatfs
sudo losetup -d $LOOPDEV
exit 0
else
echo "File contents do not match! FATFS test FAILED."
sudo umount /mnt/fatfs
sudo losetup -d $LOOPDEV
exit 1
fi
else
echo "File does not exist in FATFS image! FATFS test FAILED."
ls -la /mnt/fatfs/
sudo umount /mnt/fatfs
sudo losetup -d $LOOPDEV
exit 1
fi