From be627e5e9dc4f18c88248a5b35ece21783448106 Mon Sep 17 00:00:00 2001 From: odomingao Date: Mon, 18 Nov 2024 12:27:33 -0300 Subject: [PATCH 1/2] Update sysctl --- apparmor.d/profiles-s-z/sysctl | 1 + 1 file changed, 1 insertion(+) diff --git a/apparmor.d/profiles-s-z/sysctl b/apparmor.d/profiles-s-z/sysctl index 6dd12a02..849aeb68 100644 --- a/apparmor.d/profiles-s-z/sysctl +++ b/apparmor.d/profiles-s-z/sysctl @@ -15,6 +15,7 @@ profile sysctl @{exec_path} { capability net_admin, capability sys_admin, + capability sys_ptrace, capability sys_resource, @{exec_path} mr, From 7b4e01217b8b46ae1f2170fb5bee68dbd4ee6bee Mon Sep 17 00:00:00 2001 From: Alexandre Pujol Date: Tue, 19 Nov 2024 21:13:25 +0000 Subject: [PATCH 2/2] tests: cleanup the basic structure of integration tests. --- Makefile | 2 +- tests/bats/aa-enforce.bats | 8 ------ tests/bats/aa-status.bats | 14 ---------- tests/bats/blkid.bats | 8 ------ tests/bats/chsh.bats | 9 ------ tests/bats/common.bash | 12 +++++++- tests/bats/cpuid.bats | 10 ------- tests/bats/df.bats | 14 ---------- tests/bats/dfc.bats | 12 -------- tests/bats/fc-cache.bats | 11 -------- tests/bats/fc-list.bats | 6 ---- tests/bats/flatpak.bats | 18 ------------ tests/bats/gpgconf.bats | 14 ---------- tests/bats/groupadd.bats | 12 -------- tests/bats/groups.bats | 8 ------ tests/bats/homectl.bats | 16 ----------- tests/bats/hostnamectl.bats | 7 ----- tests/bats/id.bats | 15 ---------- tests/bats/ip.bats | 43 +++++++++++++++-------------- tests/bats/lsblk.bats | 20 -------------- tests/bats/lscpu.bats | 10 ------- tests/bats/lspci.bats | 14 ---------- tests/bats/lsusb.bats | 10 ------- tests/bats/ps.bats | 16 ----------- tests/bats/pstree.bats | 10 ------- tests/bats/snap.bats | 18 ------------ tests/bats/sync.bats | 8 ------ tests/bats/systemd-ac-power.bats | 8 ------ tests/bats/systemd-analyze.bats | 11 +------- tests/bats/systemd-cat.bats | 8 ------ tests/bats/systemd-cgls.bats | 10 ------- tests/bats/systemd-detect-virt.bats | 9 +++--- tests/bats/systemd-id128.bats | 12 -------- tests/bats/systemd-sysusers.bats | 10 ------- tests/bats/uname.bats | 20 -------------- tests/bats/upower.bats | 10 ------- tests/bats/uptime.bats | 12 -------- tests/bats/useradd.bats | 17 ------------ tests/bats/userdbctl.bats | 14 ---------- tests/bats/users.bats | 8 ------ tests/bats/uuidd.bats | 11 -------- tests/bats/uuidgen.bats | 9 ------ tests/bats/w.bats | 8 ------ tests/bats/who.bats | 10 ------- tests/cmd/main.go | 7 ++++- tests/cmd/tests.go | 13 +++------ 46 files changed, 50 insertions(+), 502 deletions(-) diff --git a/Makefile b/Makefile index 68564911..b56d69c6 100644 --- a/Makefile +++ b/Makefile @@ -113,7 +113,7 @@ check: .PHONY: bats bats: - @bats --print-output-on-failure tests/bats/ + @bats --pretty --print-output-on-failure tests/bats/ .PHONY: manual manual: diff --git a/tests/bats/aa-enforce.bats b/tests/bats/aa-enforce.bats index 05f311ca..d6b549b1 100644 --- a/tests/bats/aa-enforce.bats +++ b/tests/bats/aa-enforce.bats @@ -10,26 +10,18 @@ setup_file() { skip } -# bats test_tags=aa-enforce @test "aa-enforce: Disable profile" { sudo aa-disable pass - aa_check } -# bats test_tags=aa-enforce @test "aa-enforce: Enforce a profile" { sudo aa-enforce pass - aa_check } -# bats test_tags=aa-enforce @test "aa-enforce: Complain a profile" { sudo aa-complain pass - aa_check } -# bats test_tags=aa-enforce @test "aa-enforce: Audit a profile" { sudo aa-audit pass - aa_check } diff --git a/tests/bats/aa-status.bats b/tests/bats/aa-status.bats index 8adcd158..fbfb6667 100644 --- a/tests/bats/aa-status.bats +++ b/tests/bats/aa-status.bats @@ -5,36 +5,22 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=aa-status @test "aa-status: Check status" { sudo aa-status - aa_check } -# bats test_tags=aa-status @test "aa-status: Display the number of loaded policies" { sudo aa-status --profiled - aa_check } -# bats test_tags=aa-status @test "aa-status: Display the number of loaded enforicing policies" { sudo aa-status --enforced - aa_check } -# bats test_tags=aa-status @test "aa-status: Display the number of loaded non-enforcing policies" { sudo aa-status --complaining - aa_check } -# bats test_tags=aa-status @test "aa-status: Display the number of loaded enforcing policies that kill tasks" { sudo aa-status --kill - aa_check } diff --git a/tests/bats/blkid.bats b/tests/bats/blkid.bats index 65160f18..6dcf4b4d 100644 --- a/tests/bats/blkid.bats +++ b/tests/bats/blkid.bats @@ -5,18 +5,10 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=blkid @test "blkid: List all partitions" { sudo blkid - aa_check } -# bats test_tags=blkid @test "blkid: List all partitions in a table, including current mountpoints" { sudo blkid -o list - aa_check } diff --git a/tests/bats/chsh.bats b/tests/bats/chsh.bats index f66eb1f9..a9f5a697 100644 --- a/tests/bats/chsh.bats +++ b/tests/bats/chsh.bats @@ -5,24 +5,15 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=chsh @test "chsh: [l]ist available shells" { chsh --list-shells || true - aa_check } -# bats test_tags=chsh @test "chsh: Set a specific login [s]hell for the current user" { echo "$PASSWORD" | chsh --shell /usr/bin/bash - aa_check } # bats test_tags=chsh @test "chsh: Set a login [s]hell for a specific user" { sudo chsh --shell /usr/bin/sh root - aa_check } diff --git a/tests/bats/common.bash b/tests/bats/common.bash index f99c3c19..556ef871 100644 --- a/tests/bats/common.bash +++ b/tests/bats/common.bash @@ -105,8 +105,18 @@ aa_check() { now=$(date +%s) duration=$((now - _START + 1)) logs=$(aa-log --raw --systemd --since "-${duration}s") + aa_start if [[ -n "$logs" ]]; then fail "profile $PROGRAM raised logs: $logs" fi - aa_start +} + +# Bats setup and teardown hooks + +setup_file() { + aa_setup +} + +teardown() { + aa_check } diff --git a/tests/bats/cpuid.bats b/tests/bats/cpuid.bats index 1b1226e2..0fe2da6a 100644 --- a/tests/bats/cpuid.bats +++ b/tests/bats/cpuid.bats @@ -5,24 +5,14 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=cpuid @test "cpuid: Display information for all CPUs" { cpuid - aa_check } -# bats test_tags=cpuid @test "cpuid: Display information only for the current CPU" { cpuid -1 - aa_check } -# bats test_tags=cpuid @test "cpuid: Display raw hex information with no decoding" { cpuid -r - aa_check } diff --git a/tests/bats/df.bats b/tests/bats/df.bats index ea9d3f44..a97ad53c 100644 --- a/tests/bats/df.bats +++ b/tests/bats/df.bats @@ -5,36 +5,22 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=df @test "df: Display all filesystems and their disk usage" { df - aa_check } -# bats test_tags=df @test "df: Display all filesystems and their disk usage in human-readable form" { df -h - aa_check } -# bats test_tags=df @test "df: Display the filesystem and its disk usage containing the given file or directory" { df apparmor.d/ - aa_check } -# bats test_tags=df @test "df: Include statistics on the number of free inodes" { df --inodes - aa_check } -# bats test_tags=df @test "df: Display filesystem types" { df --print-type - aa_check } diff --git a/tests/bats/dfc.bats b/tests/bats/dfc.bats index 8a1d1891..56871f16 100644 --- a/tests/bats/dfc.bats +++ b/tests/bats/dfc.bats @@ -5,30 +5,18 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=dfc @test "dfc: Display filesystems and their disk usage in human-readable form with colors and graphs" { dfc - aa_check } -# bats test_tags=dfc @test "dfc: Display all filesystems including pseudo, duplicate and inaccessible filesystems" { dfc -a - aa_check } -# bats test_tags=dfc @test "dfc: Display filesystems without color" { dfc -c never - aa_check } -# bats test_tags=dfc @test "dfc: Display filesystems containing "ext" in the filesystem type" { dfc -t ext - aa_check } diff --git a/tests/bats/fc-cache.bats b/tests/bats/fc-cache.bats index 7ad92d94..05b8f193 100644 --- a/tests/bats/fc-cache.bats +++ b/tests/bats/fc-cache.bats @@ -5,25 +5,14 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=fc-cache @test "fc-cache: Generate font cache files" { fc-cache - aa_check } -# bats test_tags=fc-cache @test "fc-cache: Force a rebuild of all font cache files, without checking if cache is up-to-date" { fc-cache -f - aa_check } -# bats test_tags=fc-cache @test "fc-cache: Erase font cache files, then generate new font cache files" { fc-cache -r - aa_check } - diff --git a/tests/bats/fc-list.bats b/tests/bats/fc-list.bats index b85b1037..52ed4388 100644 --- a/tests/bats/fc-list.bats +++ b/tests/bats/fc-list.bats @@ -5,12 +5,6 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=fc-list @test "fc-list: Return a list of installed fonts in your system" { fc-list - aa_check } diff --git a/tests/bats/flatpak.bats b/tests/bats/flatpak.bats index 23647c93..e549e01a 100644 --- a/tests/bats/flatpak.bats +++ b/tests/bats/flatpak.bats @@ -5,48 +5,30 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=flatpak @test "flatpak: List installed applications, ignoring runtimes" { flatpak list --app - aa_check } -# bats test_tags=flatpak @test "flatpak: Install an application from a remote source" { flatpak install --noninteractive org.vim.Vim - aa_check } -# bats test_tags=flatpak @test "flatpak: Show information about an installed application" { flatpak info org.vim.Vim - aa_check } -# bats test_tags=flatpak @test "flatpak: Run an installed application" { flatpak run org.vim.Vim - aa_check } -# bats test_tags=flatpak @test "flatpak: Update all installed applications and runtimes" { flatpak update --noninteractive - aa_check } -# bats test_tags=flatpak @test "flatpak: Remove an installed application" { flatpak remove --noninteractive org.vim.Vim - aa_check } -# bats test_tags=flatpak @test "flatpak: Remove all unused applications" { flatpak remove --unused - aa_check } diff --git a/tests/bats/gpgconf.bats b/tests/bats/gpgconf.bats index 7d522d85..7155c5aa 100644 --- a/tests/bats/gpgconf.bats +++ b/tests/bats/gpgconf.bats @@ -5,44 +5,30 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=gpgconf @test "gpgconf: List all components" { gpgconf --list-components - aa_check } -# bats test_tags=gpgconf @test "gpgconf: List the directories used by gpgconf" { gpgconf --list-dirs - aa_check } -# bats test_tags=gpgconf @test "gpgconf: List all options of a component" { gpgconf --list-options gpg gpgconf --list-options gpgsm gpgconf --list-options gpg-agent gpgconf --list-options scdaemon || true gpgconf --list-options dirmngr - aa_check } -# bats test_tags=gpgconf @test "gpgconf: List programs and test whether they are runnable" { gpgconf --check-programs || true - aa_check } -# bats test_tags=gpgconf @test "gpgconf: Reload a component" { gpgconf --reload gpg gpgconf --reload gpgsm gpgconf --reload gpg-agent gpgconf --reload scdaemon || true gpgconf --reload dirmngr - aa_check } diff --git a/tests/bats/groupadd.bats b/tests/bats/groupadd.bats index f5557959..cbc0aa57 100644 --- a/tests/bats/groupadd.bats +++ b/tests/bats/groupadd.bats @@ -5,32 +5,20 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=groupadd @test "groupadd: Create a new group" { sudo groupadd user2 - aa_check } -# bats test_tags=groupadd @test "groupadd: Create a new system group" { sudo groupadd --system system2 - aa_check } -# bats test_tags=groupadd @test "groupadd: Create a new group with the specific groupid" { sudo groupadd --gid 3000 user3 - aa_check } -# bats test_tags=groupadd @test "groupdel: Delete newly created group" { sudo groupdel user2 sudo groupdel system2 sudo groupdel user3 - aa_check } diff --git a/tests/bats/groups.bats b/tests/bats/groups.bats index 829e2393..60bf6ea4 100644 --- a/tests/bats/groups.bats +++ b/tests/bats/groups.bats @@ -5,19 +5,11 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=groups @test "groups: Print group memberships for the current user" { groups - aa_check } -# bats test_tags=groups @test "groups: Print group memberships for a list of users" { groups root - aa_check } diff --git a/tests/bats/homectl.bats b/tests/bats/homectl.bats index 2ce62214..32ff3e57 100644 --- a/tests/bats/homectl.bats +++ b/tests/bats/homectl.bats @@ -10,50 +10,34 @@ setup_file() { skip } -# bats test_tags=homectl @test "homectl: Display help" { homectl --no-pager --help - aa_check } -# bats test_tags=homectl @test "homectl: Create a user account and their associated home directory" { sudo homectl create user2 - aa_check } -# bats test_tags=homectl @test "homectl: List user accounts and their associated home directories" { homectl list - aa_check } -# bats test_tags=homectl @test "homectl: Change the password for a specific user" { sudo homectl passwd user2 - aa_check } -# bats test_tags=homectl @test "homectl: Run a shell or a command with access to a specific home directory" { sudo homectl with user2 -- ls -al /home/user2 - aa_check } -# bats test_tags=homectl @test "homectl: Lock or unlock a specific home directory" { sudo homectl lock user2 - aa_check } -# bats test_tags=homectl @test "homectl: Change the disk space assigned to a specific home directory to 100 GiB" { sudo homectl resize user2 1G - aa_check } -# bats test_tags=homectl @test "homectl: Remove a specific user and the associated home directory" { sudo homectl remove user2 - aa_check } diff --git a/tests/bats/hostnamectl.bats b/tests/bats/hostnamectl.bats index dd410257..2c15658a 100644 --- a/tests/bats/hostnamectl.bats +++ b/tests/bats/hostnamectl.bats @@ -5,21 +5,14 @@ load common -setup() { - aa_setup -} - -# bats test_tags=hostnamectl @test "hostnamectl: Get the hostname of the computer" { hostnamectl } -# bats test_tags=hostnamectl @test "hostnamectl: Get the location of the computer" { hostnamectl location } -# bats test_tags=hostnamectl @test "hostnamectl: Set the hostname of the computer" { name=$(hostnamectl hostname) sudo hostnamectl set-hostname "new" diff --git a/tests/bats/id.bats b/tests/bats/id.bats index 5a7b58c5..a09def4a 100644 --- a/tests/bats/id.bats +++ b/tests/bats/id.bats @@ -5,41 +5,26 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=id @test "id: Display current user's ID (UID), group ID (GID) and groups to which they belong" { id - aa_check } -# bats test_tags=id @test "id: Display the current user identity" { id -un - aa_check } -# bats test_tags=id @test "id: Display the current user identity as a number" { id -u - aa_check } -# bats test_tags=id @test "id: Display the current primary group identity" { id -gn - aa_check } -# bats test_tags=id @test "id: Display the current primary group identity as a number" { id -g - aa_check } -# bats test_tags=id @test "id: Display an arbitrary user ID (UID), group ID (GID) and groups to which they belong" { id root } diff --git a/tests/bats/ip.bats b/tests/bats/ip.bats index 47f16ccd..6d5508c8 100644 --- a/tests/bats/ip.bats +++ b/tests/bats/ip.bats @@ -5,41 +5,42 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=ip -@test "ip: List interfaces with detailed info" { +@test "ip-address: List network interfaces and their associated IP addresses" { ip address - aa_check } -# bats test_tags=ip -@test "ip: List interfaces with brief link layer info" { - ip link - aa_check +@test "ip-address: Filter to show only active network interfaces" { + ip address show up } -# bats test_tags=ip -@test "ip: Display the routing table" { +@test "ip-route: Display the routing table" { ip route - aa_check } -# bats test_tags=ip -@test "ip: Show neighbors (ARP table)" { +@test "ip-route-get: Print route to a destination" { + ip route get 1.1.1.1 +} + +@test "ip link: Show information about all network interfaces" { + ip link +} + +@test "ip neighbour: Display the neighbour/ARP table entries" { ip neighbour - aa_check } -# bats test_tags=ip +@test "ip rule: Display the routing policy" { + ip rule show + ip rule list +} + +@test "ip rule: Flush all deleted rules" { + ip rule flush +} + @test "ip: Manage network namespace" { sudo ip netns add foo sudo ip netns list sudo ip netns exec foo bash -c "pwd" sudo ip netns delete foo - aa_check } - - diff --git a/tests/bats/lsblk.bats b/tests/bats/lsblk.bats index 4fecf42a..4dc3e20b 100644 --- a/tests/bats/lsblk.bats +++ b/tests/bats/lsblk.bats @@ -5,54 +5,34 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=lsblk @test "lsblk: List all storage devices in a tree-like format" { lsblk - aa_check } -# bats test_tags=lsblk @test "lsblk: Also list empty devices" { lsblk -a - aa_check } -# bats test_tags=lsblk @test "lsblk: Print the SIZE column in bytes rather than in a human-readable format" { lsblk -b - aa_check } -# bats test_tags=lsblk @test "lsblk: Output info about filesystems" { lsblk -f - aa_check } -# bats test_tags=lsblk @test "lsblk: Use ASCII characters for tree formatting" { lsblk -i - aa_check } -# bats test_tags=lsblk @test "lsblk: Output info about block-device topology" { lsblk -t - aa_check } -# bats test_tags=lsblk @test "lsblk: Exclude the devices specified by the comma-separated list of major device numbers" { lsblk -e 1 - aa_check } -# bats test_tags=lsblk @test "lsblk: Display a customized summary using a comma-separated list of columns" { lsblk --output NAME,SERIAL,MODEL,TRAN,TYPE,SIZE,FSTYPE,MOUNTPOINT - aa_check } diff --git a/tests/bats/lscpu.bats b/tests/bats/lscpu.bats index ef09cfbb..d0959906 100644 --- a/tests/bats/lscpu.bats +++ b/tests/bats/lscpu.bats @@ -5,24 +5,14 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=lscpu @test "lscpu: Display information about all CPUs" { lscpu - aa_check } -# bats test_tags=lscpu @test "lscpu: Display information in a table" { lscpu --extended - aa_check } -# bats test_tags=lscpu @test "lscpu: Display only information about offline CPUs in a table" { lscpu --extended --offline - aa_check } diff --git a/tests/bats/lspci.bats b/tests/bats/lspci.bats index bc6ea201..02190660 100644 --- a/tests/bats/lspci.bats +++ b/tests/bats/lspci.bats @@ -5,36 +5,22 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=lspci @test "lspci: Show a brief list of devices" { lspci - aa_check } -# bats test_tags=lspci @test "lspci: Display additional info" { lspci -v - aa_check } -# bats test_tags=lspci @test "lspci: Display drivers and modules handling each device" { lspci -k - aa_check } -# bats test_tags=lspci @test "lspci: Show a specific device" { lspci -s 00:00.0 - aa_check } -# bats test_tags=lspci @test "lspci: Dump info in a readable form" { lspci -vm - aa_check } diff --git a/tests/bats/lsusb.bats b/tests/bats/lsusb.bats index 8f646d89..f5444fce 100644 --- a/tests/bats/lsusb.bats +++ b/tests/bats/lsusb.bats @@ -5,24 +5,14 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=lsusb @test "lsusb: List all the USB devices available" { lsusb || true - aa_check } -# bats test_tags=lsusb @test "lsusb: List the USB hierarchy as a tree" { lsusb -t || true - aa_check } -# bats test_tags=lsusb @test "lsusb: List verbose information about USB devices" { lsusb --verbose || true - aa_check } diff --git a/tests/bats/ps.bats b/tests/bats/ps.bats index 4be301f7..bcdfbe1b 100644 --- a/tests/bats/ps.bats +++ b/tests/bats/ps.bats @@ -5,42 +5,26 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=ps @test "ps: List all running processes" { ps aux - aa_check } -# bats test_tags=ps @test "ps: List all running processes including the full command string" { ps auxww - aa_check } -# bats test_tags=ps @test "ps: List all processes of the current user in extra full format" { ps --user "$(id -u)" -F - aa_check } -# bats test_tags=ps @test "ps: List all processes of the current user as a tree" { ps --user "$(id -u)" -f - aa_check } -# bats test_tags=ps @test "ps: Get the parent PID of a process" { ps -o ppid= -p 1 - aa_check } -# bats test_tags=ps @test "ps: Sort processes by memory consumption" { ps auxww --sort size - aa_check } diff --git a/tests/bats/pstree.bats b/tests/bats/pstree.bats index e3ed5fa8..23094478 100644 --- a/tests/bats/pstree.bats +++ b/tests/bats/pstree.bats @@ -5,25 +5,15 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=pstree @test "pstree: Display a tree of processes" { pstree - aa_check } -# bats test_tags=pstree @test "pstree: Display a tree of processes with PIDs" { pstree -p - aa_check } -# bats test_tags=pstree @test "pstree: Display all process trees rooted at processes owned by specified user" { pstree root - aa_check } diff --git a/tests/bats/snap.bats b/tests/bats/snap.bats index ef6a292d..1eff200a 100644 --- a/tests/bats/snap.bats +++ b/tests/bats/snap.bats @@ -5,48 +5,30 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=snap @test "snap: Search for a package" { snap find vim - aa_check } -# bats test_tags=snap @test "snap: Install a package" { sudo snap install nano-strict - aa_check } -# bats test_tags=snap @test "snap: Update a package to another channel (track, risk, or branch)" { sudo snap refresh nano-strict --channel=edge - aa_check } -# bats test_tags=snap @test "snap: Update all packages" { sudo snap refresh - aa_check } -# bats test_tags=snap @test "snap: Display basic information about installed snap software" { sudo snap list - aa_check } -# bats test_tags=snap @test "snap: Check for recent snap changes in the system" { sudo snap changes - aa_check } -# bats test_tags=snap @test "snap: Uninstall a package" { sudo snap remove nano-strict - aa_check } diff --git a/tests/bats/sync.bats b/tests/bats/sync.bats index fba657ff..9f2e2688 100644 --- a/tests/bats/sync.bats +++ b/tests/bats/sync.bats @@ -5,18 +5,10 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=sync @test "sync: Flush all pending write operations on all disks" { sync - aa_check } -# bats test_tags=sync @test "sync: Flush all pending write operations on a single file to disk" { sudo sync / - aa_check } diff --git a/tests/bats/systemd-ac-power.bats b/tests/bats/systemd-ac-power.bats index 78f68d13..30019825 100644 --- a/tests/bats/systemd-ac-power.bats +++ b/tests/bats/systemd-ac-power.bats @@ -5,19 +5,11 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=systemd-ac-power @test "systemd-ac-power: Report whether we are connected to an external power source." { systemd-ac-power || true - aa_check } -# bats test_tags=systemd-ac-power @test "systemd-ac-power: Check if battery is discharging and low" { systemd-ac-power --low || true - aa_check } diff --git a/tests/bats/systemd-analyze.bats b/tests/bats/systemd-analyze.bats index 3f6144a7..6bb275bb 100644 --- a/tests/bats/systemd-analyze.bats +++ b/tests/bats/systemd-analyze.bats @@ -5,25 +5,16 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=systemd-analyze @test "systemd-analyze: List all running units, ordered by the time they took to initialize" { systemd-analyze --no-pager blame - aa_check } -# bats test_tags=systemd-analyze @test "systemd-analyze: Print a tree of the time-critical chain of units" { systemd-analyze --no-pager critical-chain - aa_check } -# bats test_tags=systemd-analyze @test "systemd-analyze: Show security scores of running units" { systemd-analyze --no-pager security - aa_check } + diff --git a/tests/bats/systemd-cat.bats b/tests/bats/systemd-cat.bats index 595a6002..da634982 100644 --- a/tests/bats/systemd-cat.bats +++ b/tests/bats/systemd-cat.bats @@ -5,18 +5,10 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=systemd-cat @test "systemd-cat: Write the output of the specified command to the journal (both output streams are captured)" { systemd-cat pwd - aa_check } -# bats test_tags=systemd-cat @test "systemd-cat: Write the output of a pipeline to the journal (`stderr` stays connected to the terminal)" { echo apparmor.d-test-suite | systemd-cat - aa_check } diff --git a/tests/bats/systemd-cgls.bats b/tests/bats/systemd-cgls.bats index b5bb89de..dca00b62 100644 --- a/tests/bats/systemd-cgls.bats +++ b/tests/bats/systemd-cgls.bats @@ -5,25 +5,15 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=systemd-cgls @test "systemd-cgls: Display the whole control group hierarchy on your system" { systemd-cgls --no-pager - aa_check } -# bats test_tags=systemd-cgls @test "systemd-cgls: Display a control group tree of a specific resource controller" { systemd-cgls --no-pager io - aa_check } -# bats test_tags=systemd-cgls @test "systemd-cgls: Display the control group hierarchy of one or more systemd units" { systemd-cgls --no-pager --unit systemd-logind - aa_check } diff --git a/tests/bats/systemd-detect-virt.bats b/tests/bats/systemd-detect-virt.bats index 0ea5fae3..41150ef7 100644 --- a/tests/bats/systemd-detect-virt.bats +++ b/tests/bats/systemd-detect-virt.bats @@ -3,23 +3,24 @@ # Copyright (C) 2024 Alexandre Pujol # SPDX-License-Identifier: GPL-2.0-only -# bats test_tags=systemd-detect-virt +load common + @test "systemd-detect-virt: List detectable virtualization technologies" { systemd-detect-virt --list } # bats test_tags=systemd-detect-virt @test "systemd-detect-virt: Detect virtualization, print the result and return a zero status code when running in a VM or a container, and a non-zero code otherwise" { - systemd-detect-virt + systemd-detect-virt || true } # bats test_tags=systemd-detect-virt @test "systemd-detect-virt: Silently check without printing anything" { - systemd-detect-virt --quiet + systemd-detect-virt --quiet || true } # bats test_tags=systemd-detect-virt @test "systemd-detect-virt: Only detect hardware virtualization" { - systemd-detect-virt --vm + systemd-detect-virt --vm || true } diff --git a/tests/bats/systemd-id128.bats b/tests/bats/systemd-id128.bats index 9a9def4d..67bf5907 100644 --- a/tests/bats/systemd-id128.bats +++ b/tests/bats/systemd-id128.bats @@ -5,31 +5,19 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=systemd-id128 @test "systemd-id128: Generate a new random identifier" { systemd-id128 new - aa_check } -# bats test_tags=systemd-id128 @test "systemd-id128: Print the identifier of the current machine" { systemd-id128 machine-id - aa_check } -# bats test_tags=systemd-id128 @test "systemd-id128: Print the identifier of the current boot" { systemd-id128 boot-id - aa_check } -# bats test_tags=systemd-id128 @test "systemd-id128: Generate a new random identifier and print it as a UUID (five groups of digits separated by hyphens)" { systemd-id128 new --uuid - aa_check } diff --git a/tests/bats/systemd-sysusers.bats b/tests/bats/systemd-sysusers.bats index f4230d6b..0816fd45 100644 --- a/tests/bats/systemd-sysusers.bats +++ b/tests/bats/systemd-sysusers.bats @@ -5,24 +5,14 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=systemd-sysusers @test "systemd-sysusers: Print the contents of all configuration files (before each file, its name is printed as a comment)" { systemd-sysusers --cat-config - aa_check } -# bats test_tags=systemd-sysusers @test "systemd-sysusers: Process configuration files and print what would be done without actually doing anything" { systemd-sysusers --dry-run - aa_check } -# bats test_tags=systemd-sysusers @test "systemd-sysusers: Create users and groups from all configuration file" { sudo systemd-sysusers - aa_check } diff --git a/tests/bats/uname.bats b/tests/bats/uname.bats index 683cef11..8723b9fe 100644 --- a/tests/bats/uname.bats +++ b/tests/bats/uname.bats @@ -5,55 +5,35 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=uname @test "uname: Print all information" { uname --all - aa_check } -# bats test_tags=uname @test "uname: Print the current kernel name" { uname --kernel-name - aa_check } -# bats test_tags=uname @test "uname: Print the current network node host name" { uname --nodename - aa_check } -# bats test_tags=uname @test "uname: Print the current kernel release" { uname --kernel-release - aa_check } -# bats test_tags=uname @test "uname: Print the current kernel version" { uname --kernel-version - aa_check } -# bats test_tags=uname @test "uname: Print the current machine hardware name" { uname --machine - aa_check } -# bats test_tags=uname @test "uname: Print the current processor type" { uname --processor - aa_check } -# bats test_tags=uname @test "uname: Print the current operating system name" { uname --operating-system - aa_check } diff --git a/tests/bats/upower.bats b/tests/bats/upower.bats index 73afc18e..3917621b 100644 --- a/tests/bats/upower.bats +++ b/tests/bats/upower.bats @@ -5,25 +5,15 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=upower @test "upower: Display power and battery information" { upower --dump - aa_check } -# bats test_tags=upower @test "upower: List all power devices" { upower --enumerate - aa_check } -# bats test_tags=upower @test "upower: Display version" { upower --version - aa_check } diff --git a/tests/bats/uptime.bats b/tests/bats/uptime.bats index 846342f4..7b64e8d2 100644 --- a/tests/bats/uptime.bats +++ b/tests/bats/uptime.bats @@ -5,31 +5,19 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=uptime @test "uptime: Print current time, uptime, number of logged-in users and other information" { uptime - aa_check } -# bats test_tags=uptime @test "uptime: Show only the amount of time the system has been booted for" { uptime --pretty - aa_check } -# bats test_tags=uptime @test "uptime: Print the date and time the system booted up at" { uptime --since - aa_check } -# bats test_tags=uptime @test "uptime: Display version" { uptime --version - aa_check } diff --git a/tests/bats/useradd.bats b/tests/bats/useradd.bats index 833e0160..5ac024f1 100644 --- a/tests/bats/useradd.bats +++ b/tests/bats/useradd.bats @@ -5,45 +5,28 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=useradd @test "useradd: Create a new user with the specified shell" { sudo useradd --shell /bin/bash --create-home user2 - aa_check } -# bats test_tags=useradd @test "useradd: Create a new user with the specified user ID" { sudo useradd --uid 3000 user3 - aa_check } -# bats test_tags=useradd @test "useradd: Create a new user belonging to additional groups (mind the lack of whitespace)" { sudo useradd --groups adm user4 - aa_check } - -# bats test_tags=useradd @test "useradd: Create a new system user without the home directory" { sudo useradd --system sys2 - aa_check } -# bats test_tags=userdel @test "userdel: Remove a user" { sudo userdel user3 sudo userdel user4 sudo userdel sys2 - aa_check } -# bats test_tags=userdel @test "userdel: Remove a user along with the home directory and mail spool" { sudo userdel --remove user2 - aa_check } diff --git a/tests/bats/userdbctl.bats b/tests/bats/userdbctl.bats index 6169de44..065dba5f 100644 --- a/tests/bats/userdbctl.bats +++ b/tests/bats/userdbctl.bats @@ -5,37 +5,23 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=userdbctl @test "userdbctl: List all known user records" { userdbctl --no-pager user - aa_check } -# bats test_tags=userdbctl @test "userdbctl: Show details of a specific user" { userdbctl --no-pager user "$USER" - aa_check } -# bats test_tags=userdbctl @test "userdbctl: List all known groups" { userdbctl --no-pager group - aa_check } -# bats test_tags=userdbctl @test "userdbctl: Show details of a specific group" { sudo userdbctl --no-pager group "$USER" - aa_check } -# bats test_tags=userdbctl @test "userdbctl: List all services currently providing user/group definitions to the system" { userdbctl --no-pager services - aa_check } diff --git a/tests/bats/users.bats b/tests/bats/users.bats index 097870ab..8f8ad383 100644 --- a/tests/bats/users.bats +++ b/tests/bats/users.bats @@ -5,19 +5,11 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=users @test "users: Print logged in usernames" { users - aa_check } -# bats test_tags=users @test "users: Print logged in usernames according to a given file" { users /var/log/wmtp - aa_check } diff --git a/tests/bats/uuidd.bats b/tests/bats/uuidd.bats index e13653e3..9e3ac5ef 100644 --- a/tests/bats/uuidd.bats +++ b/tests/bats/uuidd.bats @@ -5,25 +5,14 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=uuidd @test "uuidd: Generate a random UUID" { uuidd --random - aa_check } -# bats test_tags=uuidd @test "uuidd: Generate a bulk number of random UUIDs" { uuidd --random --uuids 10 - aa_check } -# bats test_tags=uuidd @test "uuidd: Generate a time-based UUID, based on the current time and MAC address of the system" { uuidd --time - aa_check } - diff --git a/tests/bats/uuidgen.bats b/tests/bats/uuidgen.bats index 8caa4186..eb6465c0 100644 --- a/tests/bats/uuidgen.bats +++ b/tests/bats/uuidgen.bats @@ -5,19 +5,10 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=uuidgen @test "uuidgen: Create a random UUIDv4" { uuidgen --random - aa_check } -# bats test_tags=uuidgen @test "uuidgen: Create a UUIDv1 based on the current time" { uuidgen --time - aa_check } - diff --git a/tests/bats/w.bats b/tests/bats/w.bats index 7f358aac..1b97ba44 100644 --- a/tests/bats/w.bats +++ b/tests/bats/w.bats @@ -5,18 +5,10 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=w @test "w: Display information about all users who are currently logged in" { w - aa_check } -# bats test_tags=w @test "w: Display information about a specific user" { w root - aa_check } diff --git a/tests/bats/who.bats b/tests/bats/who.bats index f8aaf5a1..c05995d0 100644 --- a/tests/bats/who.bats +++ b/tests/bats/who.bats @@ -5,25 +5,15 @@ load common -setup_file() { - aa_setup -} - -# bats test_tags=who @test "who: Display the username, line, and time of all currently logged-in sessions" { who - aa_check } -# bats test_tags=who @test "who: Display all available information" { who -a - aa_check } -# bats test_tags=who @test "who: Display all available information with table headers" { who -a -H - aa_check } diff --git a/tests/cmd/main.go b/tests/cmd/main.go index 5ca94819..eb88de1e 100644 --- a/tests/cmd/main.go +++ b/tests/cmd/main.go @@ -68,7 +68,6 @@ func run() error { if err != nil { return err } - tests = tests.Filter() if err := cfg.BatsDir.RemoveAll(); err != nil { return err @@ -76,6 +75,12 @@ func run() error { if err := cfg.BatsDir.MkdirAll(); err != nil { return err } + if err := cfg.BatsDir.Join("profiled").MkdirAll(); err != nil { + return err + } + if err := cfg.BatsDir.Join("unprofiled").MkdirAll(); err != nil { + return err + } for _, test := range tests { if err := test.Write(cfg.BatsDir); err != nil { return err diff --git a/tests/cmd/tests.go b/tests/cmd/tests.go index 2d37324e..1c5f55ae 100644 --- a/tests/cmd/tests.go +++ b/tests/cmd/tests.go @@ -20,16 +20,10 @@ const tmplTest = `#!/usr/bin/env bats # SPDX-License-Identifier: GPL-2.0-only load common - -setup_file() { - aa_setup -} {{ $name := .Name -}} {{ range .Commands }} -# bats test_tags={{ $name }} @test "{{ $name }}: {{ .Description }}" { {{ .Cmd }} - aa_check } {{ end }} ` @@ -77,13 +71,14 @@ func (t Test) IsInstalled() bool { } func (t Test) Write(dir *paths.Path) error { + dstDir := dir.Join("profiled") if !t.HasProfile() { - return nil + dstDir = dir.Join("unprofiled") } + path := dstDir.Join(t.Name + ".bats") - path := dir.Join(t.Name + ".bats") if paths.New("tests/bats").Join(t.Name + ".bats").Exist() { - path = dir.Join("00." + t.Name + ".bats") + path = dstDir.Join("00." + t.Name + ".bats") } content := renderBatsFile(t) if err := path.WriteFile([]byte(content)); err != nil {