11#! /bin/bash
22
3+ # Usage: ./test_x11vnc.sh [log_file]
4+ # If no log file is provided, defaults to "x11vnc_test.log"
5+
6+ # Set default log file
7+ LOG_FILE=" ${1:- x11vnc_test.log} "
8+
9+ # Show usage if help is requested
10+ if [[ " $1 " == " -h" || " $1 " == " --help" ]]; then
11+ echo " Usage: $0 [log_file]"
12+ echo " log_file: Path to the log file (default: x11vnc_test.log)"
13+ echo " -h, --help: Show this help message"
14+ exit 0
15+ fi
16+
317SCRIPTS_DIR=" $GITHUB_WORKSPACE /.github/scripts/x11vnc"
418
519killall x11vnc > /dev/null 2> /dev/null
@@ -11,9 +25,9 @@ X11VNC_TEST_FAIL=0
1125# CA / cert generation
1226
1327
14- echo -e " \n\nTesting -sslGenCA\n" > x11vnc_test.log
28+ echo -e " \n\nTesting -sslGenCA\n" > " $LOG_FILE "
1529
16- $SCRIPTS_DIR /x11vnc_sslgenca.exp >> x11vnc_test.log 2>> x11vnc_test.log
30+ $SCRIPTS_DIR /x11vnc_sslgenca.exp >> " $LOG_FILE " 2>> " $LOG_FILE "
1731
1832if [ $? -eq 0 ] && [ -f " ca-dir/CA/cacert.pem" ] && [ -f " ca-dir/CA/private/cakey.pem" ]
1933then
2438fi
2539
2640
27- echo -e " \n\nTesting -sslGenCert client\n" >> x11vnc_test.log
41+ echo -e " \n\nTesting -sslGenCert client\n" >> " $LOG_FILE "
2842
29- $SCRIPTS_DIR /x11vnc_sslgencert_client.exp >> x11vnc_test.log 2>> x11vnc_test.log
43+ $SCRIPTS_DIR /x11vnc_sslgencert_client.exp >> " $LOG_FILE " 2>> " $LOG_FILE "
3044
3145if [ $? -eq 0 ] && [ -f " ca-dir/clients/wolf.pem" ] && [ -f " ca-dir/clients/wolf.crt" ]
3246then
3751fi
3852
3953
40- echo -e " \n\nTesting -sslGenCert server\n" >> x11vnc_test.log
54+ echo -e " \n\nTesting -sslGenCert server\n" >> " $LOG_FILE "
4155
42- $SCRIPTS_DIR /x11vnc_sslgencert_server.exp >> x11vnc_test.log 2>> x11vnc_test.log
56+ $SCRIPTS_DIR /x11vnc_sslgencert_server.exp >> " $LOG_FILE " 2>> " $LOG_FILE "
4357
4458if [ $? -eq 0 ] && [ -f " ca-dir/server-wolf.pem" ] && [ -f " ca-dir/server-wolf.crt" ]
4559then
5064fi
5165
5266
53- echo -e " \n\nTesting -sslCertInfo\n" >> x11vnc_test.log
67+ echo -e " \n\nTesting -sslCertInfo\n" >> " $LOG_FILE "
5468
5569OPENSSL_CONF=' ' OPENSSL_MODULES=' ' timeout 5 x11vnc -sslCertInfo ca-dir/server-wolf.pem > cert_info_ossl.txt
5670timeout 5 x11vnc -sslCertInfo ca-dir/server-wolf.pem > cert_info.txt
5771
58- if [ $? -eq 0 ] && diff -y cert_info.txt cert_info_ossl.txt >> x11vnc_test.log 2>> x11vnc_test.log \
59- && cat cert_info.txt >> x11vnc_test.log
72+ if [ $? -eq 0 ] && diff -y cert_info.txt cert_info_ossl.txt >> " $LOG_FILE " 2>> " $LOG_FILE " \
73+ && cat cert_info.txt >> " $LOG_FILE "
6074then
6175 echo " [ PASSED ] -sslCertInfo"
6276else
6579fi
6680
6781
68- echo -e " \n\nTesting -sslEncKey\n" >> x11vnc_test.log
82+ echo -e " \n\nTesting -sslEncKey\n" >> " $LOG_FILE "
6983
70- $SCRIPTS_DIR /x11vnc_sslenckey.exp >> x11vnc_test.log 2>> x11vnc_test.log
84+ $SCRIPTS_DIR /x11vnc_sslenckey.exp >> " $LOG_FILE " 2>> " $LOG_FILE "
7185
7286if [ $? -eq 0 ] && grep -q " BEGIN ENCRYPTED PRIVATE KEY" ca-dir/server-wolf.pem
7387then
8397
8498# Setup Xvfb, which is a purely virtual display, i.e., humans cannot see it
8599# but it works the same as any other X server
86- Xvfb :0 -screen 0 100x100x8 2>> x11vnc_test.log &
100+ Xvfb :0 -screen 0 100x100x8 2>> " $LOG_FILE " &
87101sleep 2
88102
89103
90104# Testing with SSL will use the TLSNone security type
91- echo -e " \n\nTesting -ssl handshake, authentication, initialization...\n" >> x11vnc_test.log
105+ echo -e " \n\nTesting -ssl handshake, authentication, initialization...\n" >> " $LOG_FILE "
92106
93107PORT=` x11vnc -ssl TMP -display :0 -localhost -bg -o server.log`
94108PORT=` echo " $PORT " | grep -m 1 " PORT=" | sed -e ' s/PORT=//' `
@@ -105,13 +119,13 @@ else
105119 X11VNC_TEST_FAIL=1
106120fi
107121killall x11vnc > /dev/null 2> /dev/null
108- cat server.log client.log >> x11vnc_test.log
122+ cat server.log client.log >> " $LOG_FILE "
109123
110124
111125# Testing with a password changes the security type from TLSNone to TLSVnc
112- echo -e " \n\nTesting -ssl with a password...\n" >> x11vnc_test.log
126+ echo -e " \n\nTesting -ssl with a password...\n" >> " $LOG_FILE "
113127
114- x11vnc -storepasswd wolfprov passwd 2>> x11vnc_test.log
128+ x11vnc -storepasswd wolfprov passwd 2>> " $LOG_FILE "
115129
116130PORT=` x11vnc -ssl TMP -display :0 -localhost -bg -o server.log -rfbauth passwd`
117131PORT=` echo " $PORT " | grep -m 1 " PORT=" | sed -e ' s/PORT=//' `
128142 X11VNC_TEST_FAIL=1
129143fi
130144killall x11vnc > /dev/null 2> /dev/null
131- cat server.log client.log >> x11vnc_test.log
145+ cat server.log client.log >> " $LOG_FILE "
132146
133147
134148# HTTP HTTPS
@@ -140,9 +154,9 @@ echo "<html><body>Use WolfSSL!</body></html>" > index.html
140154PORT=` x11vnc -ssl TMP -display :0 -localhost -httpdir . -https 5678 -bg -o server.log`
141155PORT=` echo " $PORT " | grep -m 1 -Eo " http://localhost:[0-9]+" server.log | sed -e ' s/http:\/\/localhost://' `
142156
143- echo -e " \n\nTesting -https with http...\n" >> x11vnc_test.log
157+ echo -e " \n\nTesting -https with http...\n" >> " $LOG_FILE "
144158
145- if OPENSSL_CONF=' ' OPENSSL_MODULES=' ' curl -ks " http://localhost:$PORT /index.html" >> x11vnc_test.log
159+ if OPENSSL_CONF=' ' OPENSSL_MODULES=' ' curl -ks " http://localhost:$PORT /index.html" >> " $LOG_FILE "
146160then
147161 echo " [ PASSED ] -https with an http request"
148162else
@@ -151,23 +165,20 @@ else
151165fi
152166
153167
154- echo -e " \n\nTesting -https with https...\n" >> x11vnc_test.log
168+ echo -e " \n\nTesting -https with https...\n" >> " $LOG_FILE "
155169
156- if OPENSSL_CONF=' ' OPENSSL_MODULES=' ' curl -ks " https://localhost:5678/index.html" >> x11vnc_test.log
170+ if OPENSSL_CONF=' ' OPENSSL_MODULES=' ' curl -ks " https://localhost:5678/index.html" >> " $LOG_FILE "
157171then
158172 echo " [ PASSED ] -https with an https request"
159173else
160174 echo " [ FAILED ] -https with an https request"
161175 X11VNC_TEST_FAIL=1
162176fi
163177
164- killall x11vnc > /dev/null 2> /dev/null
165- killall Xvfb > /dev/null 2> /dev/null
166- cat server.log >> x11vnc_test.log
167-
168- $GITHUB_WORKSPACE /.github/scripts/check-workflow-result.sh $X11VNC_TEST_FAIL " $WOLFPROV_FORCE_FAIL_STR " x11vnc
169- X11VNC_TEST_FAIL=$?
170-
171- if [[ $X11VNC_TEST_FAIL -eq 1 ]]; then cat x11vnc_test.log; fi
178+ killall x11vnc > /dev/null 2> /dev/null || true
179+ killall Xvfb > /dev/null 2> /dev/null || true
180+ cat server.log >> " $LOG_FILE "
172181
182+ printf " \n\nX11VNC_TEST_FAIL: $X11VNC_TEST_FAIL \n\n"
173183exit $X11VNC_TEST_FAIL
184+
0 commit comments