@@ -36,6 +36,17 @@ summary() {
3636 fi
3737}
3838
39+ # ── Helpers ───────────────────────────────────────────────────────────────────
40+
41+ # Returns 0 if systemd is running AND the unit file is installed on disk.
42+ systemd_and_unit_available () {
43+ [ -d /run/systemd/system ] && command -v systemctl > /dev/null 2>&1 || return 1
44+ for path in " ${UNIT_FILE_PATHS[@]} " ; do
45+ [ -f " $path " ] && return 0
46+ done
47+ return 1
48+ }
49+
3950# ── Check functions ───────────────────────────────────────────────────────────
4051
4152check_binary_executable () {
@@ -77,6 +88,16 @@ check_config_dir() {
7788 fi
7889}
7990
91+ check_config_dir_permissions () {
92+ local perms
93+ perms=$( stat -c ' %a' " $CONFIG_DIR " 2> /dev/null)
94+ if [ " $perms " = " 750" ]; then
95+ pass " Config directory has secure permissions ($perms ): $CONFIG_DIR "
96+ else
97+ fail " Config directory has insecure permissions ($perms , expected 750): $CONFIG_DIR "
98+ fi
99+ }
100+
80101check_binary_help () {
81102 HELP_OUTPUT=$( " $BINARY " --help 2>&1 ) && HELP_RC=$? || HELP_RC=$?
82103 if [ " $HELP_RC " -eq 0 ] || echo " $HELP_OUTPUT " | grep -qi ' gateway\|usage\|help' ; then
@@ -147,19 +168,87 @@ check_single_execstart() {
147168 fi
148169}
149170
150- check_service_startup () {
151- info " [Best-effort] Checking service startup…"
152- warn " systemd service startup testing is best-effort in containers."
153- warn " Full service validation requires a real systemd environment."
154- if [ -d /run/systemd/system ]; then
155- info " systemd detected; attempting service start…"
156- if systemctl start devolutions-gateway 2>&1 ; then
157- pass " [Best-effort] Service started successfully"
158- systemctl status devolutions-gateway 2>&1 || true
159- else
160- warn " Service start failed (expected in some container environments)."
171+ check_provisioner_key () {
172+ info " Generating RSA-2048 provisioner key pair with openssl…"
173+ KEY_LOG=$( mktemp)
174+ if openssl genrsa -out " $CONFIG_DIR /provisioner.key" 2048 > " $KEY_LOG " 2>&1 \
175+ && openssl rsa -in " $CONFIG_DIR /provisioner.key" \
176+ -pubout -out " $CONFIG_DIR /provisioner.pem" >> " $KEY_LOG " 2>&1 ; then
177+ pass " Provisioner key pair generated: $CONFIG_DIR /provisioner.pem"
178+ else
179+ echo " openssl output:"
180+ cat " $KEY_LOG "
181+ fail " Failed to generate provisioner key pair"
182+ fi
183+ rm -f " $KEY_LOG "
184+ }
185+
186+ check_service_health () {
187+ info " Checking service health…"
188+
189+ local health_url=" http://localhost:7171/jet/health"
190+ local gateway_pid=" "
191+
192+ if systemd_and_unit_available; then
193+ info " systemd available — using systemctl start/stop"
194+ if ! systemctl start devolutions-gateway > /dev/null 2>&1 ; then
195+ fail " systemctl start devolutions-gateway failed"
196+ return
197+ fi
198+ else
199+ info " systemd not available — starting binary directly"
200+ " $BINARY " &
201+ gateway_pid=$!
202+ fi
203+
204+ # Wait for the service to be ready (up to 10 s).
205+ local i=0
206+ while [ " $i " -lt 10 ]; do
207+ curl -sf " $health_url " > /dev/null 2>&1 && break
208+ sleep 1
209+ i=$(( i + 1 ))
210+ done
211+
212+ HEALTH_OUTPUT=$( curl -sf " $health_url " 2> /dev/null) && HEALTH_RC=$? || HEALTH_RC=$?
213+
214+ # Stop the service.
215+ if systemd_and_unit_available; then
216+ systemctl stop devolutions-gateway > /dev/null 2>&1 || true
217+ elif [ -n " $gateway_pid " ]; then
218+ kill " $gateway_pid " 2> /dev/null || true
219+ wait " $gateway_pid " 2> /dev/null || true
220+ fi
221+
222+ if [ " $HEALTH_RC " -eq 0 ]; then
223+ pass " Health endpoint responded: $HEALTH_OUTPUT "
224+ else
225+ fail " Health endpoint did not respond at $health_url "
226+ fi
227+ }
228+
229+ check_post_uninstall () {
230+ if [ ! -f " $BINARY " ]; then
231+ pass " Binary removed after uninstall"
232+ else
233+ fail " Binary still present after uninstall: $BINARY "
234+ fi
235+
236+ local unit_file_found=0
237+ for path in " ${UNIT_FILE_PATHS[@]} " ; do
238+ if [ -f " $path " ]; then
239+ unit_file_found=1
240+ break
161241 fi
242+ done
243+ if [ " $unit_file_found " -eq 0 ]; then
244+ pass " Unit file removed after uninstall"
245+ else
246+ fail " Unit file still present after uninstall"
247+ fi
248+
249+ if [ -d " $CONFIG_DIR " ]; then
250+ pass " Config directory preserved after uninstall: $CONFIG_DIR "
162251 else
163- info " No systemd detected; skipping service startup test. "
252+ fail " Config directory was removed after uninstall (should be preserved) "
164253 fi
165254}
0 commit comments