Skip to content

Commit

Permalink
tests: ido: test on FreeBSD and NetBSD
Browse files Browse the repository at this point in the history
The binary bash is located in /usr/local/bin on the FreeBSD and OpenBSD
systems and in /usr/pkg/bin on NetBSD the system:

	[freebox@freebsd ~/src/iamroot]$ uname -s
	FreeBSD
	[freebox@freebsd ~/src/iamroot]$ which bash
	/usr/local/bin/bash

	-bash-5.2$ uname -s
	NetBSD
	-bash-5.2$ which bash
	/usr/pkg/bin/bash

	-bash-5.2$ uname -s
	OpenBSD
	-bash-5.2$ which bash
	/usr/local/bin/bash

	[freebox@freebsd ~/src/iamroot]$ make test-ido EXIT_ON_ERROR=1
	(...)
	Running ido: test environment sets IDO_COMMAND to the command run by ido...
	Having trouble using fetch through a firewall? Try setting the environment
	variable FTP_PASSIVE_MODE to yes, and see fetch(3) for more details.
	IDO_COMMAND=/bin/csh
	ido: test environment sets IDO_COMMAND to the command run by ido: [KO]
	Test report:
	ido: test environment sets IDO_COMMAND to the command run by ido at line 652 has failed!
	47 test(s) succeed!
	Error: 1 test(s) failed!
	Exited!

The procfs is mostly Linux specific:

	[freebox@freebsd ~/src/iamroot]$ make test-ido EXIT_ON_ERROR=1
	(...)
	Running ido: test option -C=101 do not closes file descriptors < 100...
	/usr/home/freebox/src/iamroot/ido: line 324: [[: *: syntax error: operand expected (error token is "*")
	ido: test option -C=101 do not closes file descriptors < 100: [KO]
	Test report:
	ido: test option -C=101 do not closes file descriptors < 100 at line 196 has failed!
	2 test(s) succeed!
	Error: 1 test(s) failed!
	Exited!

	[freebox@freebsd ~/src/iamroot]$ make test-ido EXIT_ON_ERROR=1
	(...)
	Running ido: test option --close-from=100 closes file descriptor >= 100...
	/usr/home/freebox/src/iamroot/ido: line 324: [[: *: syntax error: operand expected (error token is "*")
	ido: test option --close-from=100 closes file descriptor >= 100: [OK]

	Test report:
	3 test(s) succeed!

	[freebox@freebsd ~/src/iamroot]$ make test-ido EXIT_ON_ERROR=1
	(...)
	Running ido: test option --debug-fd=100 sets and duplicates debug fd...
	IAMROOT_DEBUG_FD=100
	ido: test option --debug-fd=100 sets and duplicates debug fd: [KO]
	Test report:
	ido: test option --debug-fd=100 sets and duplicates debug fd at line 576 has failed!
	40 test(s) succeed!
	Error: 1 test(s) failed!
	Exited!

Also, there is no group for root the BSD systems:

	[freebox@freebsd ~/src/iamroot]$ uname -s
	FreeBSD
	[freebox@freebsd ~/src/iamroot]$ getent group root

	-bash-5.2$ uname -s
	NetBSD
	-bash-5.2$ getent group root

	-bash-5.2$ uname -s
	OpenBSD
	-bash-5.2$ getent group root

	[freebox@freebsd ~/src/iamroot]$ make test-ido EXIT_ON_ERROR=1
	(...)
	Running ido: test option -g=root runs command as group name root...
	ido: unknown group root
	ido: test option -g=root runs command as group name root: [KO]
	Test report:
	ido: test option -g=root runs command as group name root at line 267 has failed!
	7 test(s) succeed!
	Error: 1 test(s) failed!
	Exited!

	[freebox@freebsd ~/src/iamroot]$ make test-ido EXIT_ON_ERROR=1
	(...)
	Running ido: test option -P preserves group vector 1000 0...
	GROUPS=1000
	ido: test option -P preserves group vector 1000 0: [KO]
	Test report:
	ido: test option -P preserves group vector 1000 0 at line 360 has failed!
	16 test(s) succeed!
	Error: 1 test(s) failed!
	Exited!

The binary bash is located in /usr/local/bin on FreeBSD or /usr/pkg/bin
on NetBSD:

	[freebox@freebsd ~/src/iamroot]$ make test-ido EXIT_ON_ERROR=1
	(...)
	Running ido: test option -P preserves group vector 0 1000...
	execvP: No such file or directory
	ido: test option -P preserves group vector 0 1000: [KO]
	Test report:
	ido: test option -P preserves group vector 0 1000 at line 360 has failed!
	16 test(s) succeed!
	Error: 1 test(s) failed!
	Exited!

	[freebox@freebsd ~/src/iamroot]$ make test-ido EXIT_ON_ERROR=1
	(...)
	Running ido: test option --preserve-groups preserves group vector 1000...
	execvP: No such file or directory
	ido: test option --preserve-groups preserves group vector 1000: [KO]
	Test report:
	ido: test option --preserve-groups preserves group vector 1000 at line 369 has failed!
	17 test(s) succeed!
	Error: 1 test(s) failed!
	Exited!

	[freebox@freebsd ~/src/iamroot]$ make test-ido EXIT_ON_ERROR=1
	(...)
	Running ido: test option --shell runs /bin/bash with the specified command...
	execvP: No such file or directory
	ido: test option --shell runs /bin/bash with the specified command: [KO]
	Test report:
	ido: test option --shell runs /bin/bash with the specified command at line 405 has failed!
	21 test(s) succeed!
	Error: 1 test(s) failed!
	Exited!
  • Loading branch information
gportay committed Oct 17, 2024
1 parent 8b0c64b commit 91bd6f3
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 31 deletions.
2 changes: 1 addition & 1 deletion tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ endif

.PHONY: test-ido
test-ido: | rootfs
ifeq ($(OS),GNU/Linux)
ifneq ($(OS),OpenBSD)
bash tests-ido.bash
endif

Expand Down
80 changes: 50 additions & 30 deletions tests/tests-ido.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
#
# Copyright 2024 Gaël PORTAY
#
Expand Down Expand Up @@ -175,6 +175,8 @@ export -n IAMROOT_DEBUG_IGNORE
export -n IAMROOT_EXEC_IGNORE
export -n IAMROOT_PATH_RESOLUTION_IGNORE

OS="$(shell uname -o 2>/dev/null || uname -s 2>/dev/null)"

run "ido: test without argument"
if ! ido
then
Expand All @@ -193,23 +195,26 @@ else
fi
echo

run "ido: test option -C=101 do not closes file descriptors < 100"
if ( exec 100>&2 && ido -C=101 readlink /proc/self/fd/100 )
if [[ "$OS" =~ Linux ]]
then
ok
else
ko
fi
echo
run "ido: test option -C=101 do not closes file descriptors < 100"
if ( exec 100>&2 && ido -C=101 readlink /proc/self/fd/100 )
then
ok
else
ko
fi
echo

run "ido: test option --close-from=100 closes file descriptor >= 100"
if ( exec 100>&2 && ! ido --close-from=100 readlink /proc/self/fd/100 )
then
ok
else
ko
run "ido: test option --close-from=100 closes file descriptor >= 100"
if ( exec 100>&2 && ! ido --close-from=100 readlink /proc/self/fd/100 )
then
ok
else
ko
fi
echo
fi
echo

run "ido: test option -D=/tmp changes working directory"
if ido -D=/tmp pwd | tee /dev/stderr | grep -q "^/tmp$"
Expand Down Expand Up @@ -259,14 +264,26 @@ else
fi
echo

run "ido: test option -g=root runs command as group name root"
if ido -g=root id -gn | tee /dev/stderr | grep -q "^root$"
if [[ "$OS" =~ BSD$ ]]
then
ok
run "ido: test option -g=wheel runs command as group name wheel"
if ido -g=wheel id -gn | tee /dev/stderr | grep -q "^wheel$"
then
ok
else
ko
fi
echo
else
ko
run "ido: test option -g=root runs command as group name root"
if ido -g=root id -gn | tee /dev/stderr | grep -q "^root$"
then
ok
else
ko
fi
echo
fi
echo

run "ido: test option -g=\#0 runs command as group ID 0"
if ido -g=0 id -g | tee /dev/stderr | grep -q "^0$"
Expand Down Expand Up @@ -350,7 +367,7 @@ fi
echo

run "ido: test option --preserve-groups preserves group vector ${GROUPS[*]}"
if ( export SHELL=/bin/bash && ido --user="$USER" --preserve-groups --shell <<<'echo "GROUPS=${GROUPS[*]}"' | tee /dev/stderr | grep -q "GROUPS=${GROUPS[*]}" )
if ( export SHELL=bash && ido --user="$USER" --preserve-groups --shell <<<'echo "GROUPS=${GROUPS[*]}"' | tee /dev/stderr | grep -q "GROUPS=${GROUPS[*]}" )
then
ok
else
Expand Down Expand Up @@ -385,8 +402,8 @@ else
fi
echo

run "ido: test option --shell runs /bin/bash with the specified command"
if ( export SHELL=/bin/bash; ido --shell env | tee /dev/stderr | grep -q '^SHELL=/bin/bash$' )
run "ido: test option --shell runs bash with the specified command"
if ( export SHELL=bash; ido --shell env | tee /dev/stderr | grep -q '^SHELL=bash$' )
then
ok
else
Expand Down Expand Up @@ -556,15 +573,18 @@ else
fi
echo

run "ido: test option --debug-fd=100 sets and duplicates debug fd"
if ido --debug-fd=100 env | grep "^IAMROOT_DEBUG_FD=100$" &&
ido --debug-fd=100 readlink /proc/self/fd/100
if [[ "$OS" =~ Linux ]]
then
ok
else
ko
run "ido: test option --debug-fd=100 sets and duplicates debug fd"
if ido --debug-fd=100 env | grep "^IAMROOT_DEBUG_FD=100$" &&
ido --debug-fd=100 readlink /proc/self/fd/100
then
ok
else
ko
fi
echo
fi
echo

run "ido: test option --debug-ignore=^(chroot|chdir|fchdir)$ sets regular expression of path to ignore for path resolution in chroot."
if ido --debug-ignore="^(chroot|chdir|fchdir)$" env | grep "^IAMROOT_DEBUG_IGNORE=^(chroot|chdir|fchdir)\\$\$"
Expand Down

0 comments on commit 91bd6f3

Please sign in to comment.