diff --git a/tests/bats/chsh.bats b/tests/bats/chsh.bats index 5365fea6..f66eb1f9 100644 --- a/tests/bats/chsh.bats +++ b/tests/bats/chsh.bats @@ -17,7 +17,7 @@ setup_file() { # bats test_tags=chsh @test "chsh: Set a specific login [s]hell for the current user" { - chsh --shell /usr/bin/bash + echo "$PASSWORD" | chsh --shell /usr/bin/bash aa_check } diff --git a/tests/bats/common.bash b/tests/bats/common.bash index c08d1375..f99c3c19 100644 --- a/tests/bats/common.bash +++ b/tests/bats/common.bash @@ -6,6 +6,9 @@ export BATS_LIB_PATH=${BATS_LIB_PATH:-/usr/lib/bats} load "$BATS_LIB_PATH/bats-support/load" +# User password for sudo commands +export PASSWORD=${PASSWORD:-user} + export XDG_CACHE_DIR=".cache" export XDG_CONFIG_DIR=".config" export XDG_DATA_DIR=".local/share" @@ -100,7 +103,7 @@ aa_check() { local now duration logs now=$(date +%s) - duration=$((now - _START + 2)) + duration=$((now - _START + 1)) logs=$(aa-log --raw --systemd --since "-${duration}s") if [[ -n "$logs" ]]; then fail "profile $PROGRAM raised logs: $logs" diff --git a/tests/bats/cpuid.bats b/tests/bats/cpuid.bats new file mode 100644 index 00000000..1b1226e2 --- /dev/null +++ b/tests/bats/cpuid.bats @@ -0,0 +1,28 @@ +#!/usr/bin/env bats +# apparmor.d - Full set of apparmor profiles +# Copyright (C) 2024 Alexandre Pujol +# SPDX-License-Identifier: GPL-2.0-only + +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 be284321..ea9d3f44 100644 --- a/tests/bats/df.bats +++ b/tests/bats/df.bats @@ -21,6 +21,12 @@ setup_file() { 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 diff --git a/tests/bats/dfc.bats b/tests/bats/dfc.bats new file mode 100644 index 00000000..8a1d1891 --- /dev/null +++ b/tests/bats/dfc.bats @@ -0,0 +1,34 @@ +#!/usr/bin/env bats +# apparmor.d - Full set of apparmor profiles +# Copyright (C) 2024 Alexandre Pujol +# SPDX-License-Identifier: GPL-2.0-only + +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/homectl.bats b/tests/bats/homectl.bats new file mode 100644 index 00000000..2fee7907 --- /dev/null +++ b/tests/bats/homectl.bats @@ -0,0 +1,58 @@ +#!/usr/bin/env bats +# apparmor.d - Full set of apparmor profiles +# Copyright (C) 2024 Alexandre Pujol +# SPDX-License-Identifier: GPL-2.0-only + +load common + +setup_file() { + aa_setup +} + +# 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 new file mode 100644 index 00000000..dd410257 --- /dev/null +++ b/tests/bats/hostnamectl.bats @@ -0,0 +1,27 @@ +#!/usr/bin/env bats +# apparmor.d - Full set of apparmor profiles +# Copyright (C) 2024 Alexandre Pujol +# SPDX-License-Identifier: GPL-2.0-only + +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" + sudo hostnamectl set-hostname "$name" +} diff --git a/tests/bats/ip.bats b/tests/bats/ip.bats index 980495d2..47f16ccd 100644 --- a/tests/bats/ip.bats +++ b/tests/bats/ip.bats @@ -15,15 +15,9 @@ setup_file() { aa_check } -# bats test_tags=ip -@test "ip: List interfaces with brief network layer info" { - ip -brief address - aa_check -} - # bats test_tags=ip @test "ip: List interfaces with brief link layer info" { - ip -brief link + ip link aa_check } @@ -39,3 +33,13 @@ setup_file() { aa_check } +# bats test_tags=ip +@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/sync.bats b/tests/bats/sync.bats new file mode 100644 index 00000000..fba657ff --- /dev/null +++ b/tests/bats/sync.bats @@ -0,0 +1,22 @@ +#!/usr/bin/env bats +# apparmor.d - Full set of apparmor profiles +# Copyright (C) 2024 Alexandre Pujol +# SPDX-License-Identifier: GPL-2.0-only + +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 new file mode 100644 index 00000000..78f68d13 --- /dev/null +++ b/tests/bats/systemd-ac-power.bats @@ -0,0 +1,23 @@ +#!/usr/bin/env bats +# apparmor.d - Full set of apparmor profiles +# Copyright (C) 2024 Alexandre Pujol +# SPDX-License-Identifier: GPL-2.0-only + +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 new file mode 100644 index 00000000..3f6144a7 --- /dev/null +++ b/tests/bats/systemd-analyze.bats @@ -0,0 +1,29 @@ +#!/usr/bin/env bats +# apparmor.d - Full set of apparmor profiles +# Copyright (C) 2024 Alexandre Pujol +# SPDX-License-Identifier: GPL-2.0-only + +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 new file mode 100644 index 00000000..595a6002 --- /dev/null +++ b/tests/bats/systemd-cat.bats @@ -0,0 +1,22 @@ +#!/usr/bin/env bats +# apparmor.d - Full set of apparmor profiles +# Copyright (C) 2024 Alexandre Pujol +# SPDX-License-Identifier: GPL-2.0-only + +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 new file mode 100644 index 00000000..b5bb89de --- /dev/null +++ b/tests/bats/systemd-cgls.bats @@ -0,0 +1,29 @@ +#!/usr/bin/env bats +# apparmor.d - Full set of apparmor profiles +# Copyright (C) 2024 Alexandre Pujol +# SPDX-License-Identifier: GPL-2.0-only + +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-id128.bats b/tests/bats/systemd-id128.bats new file mode 100644 index 00000000..3b18bd03 --- /dev/null +++ b/tests/bats/systemd-id128.bats @@ -0,0 +1,41 @@ +#!/usr/bin/env bats +# apparmor.d - Full set of apparmor profiles +# Copyright (C) 2024 Alexandre Pujol +# SPDX-License-Identifier: GPL-2.0-only + +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: Print the identifier of the current service invocation (this is available in systemd services)" { + systemd-id128 invocation-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 new file mode 100644 index 00000000..f4230d6b --- /dev/null +++ b/tests/bats/systemd-sysusers.bats @@ -0,0 +1,28 @@ +#!/usr/bin/env bats +# apparmor.d - Full set of apparmor profiles +# Copyright (C) 2024 Alexandre Pujol +# SPDX-License-Identifier: GPL-2.0-only + +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/upower.bats b/tests/bats/upower.bats new file mode 100644 index 00000000..73afc18e --- /dev/null +++ b/tests/bats/upower.bats @@ -0,0 +1,29 @@ +#!/usr/bin/env bats +# apparmor.d - Full set of apparmor profiles +# Copyright (C) 2024 Alexandre Pujol +# SPDX-License-Identifier: GPL-2.0-only + +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/userdbctl.bats b/tests/bats/userdbctl.bats new file mode 100644 index 00000000..6169de44 --- /dev/null +++ b/tests/bats/userdbctl.bats @@ -0,0 +1,41 @@ +#!/usr/bin/env bats +# apparmor.d - Full set of apparmor profiles +# Copyright (C) 2024 Alexandre Pujol +# SPDX-License-Identifier: GPL-2.0-only + +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/uuidd.bats b/tests/bats/uuidd.bats new file mode 100644 index 00000000..e13653e3 --- /dev/null +++ b/tests/bats/uuidd.bats @@ -0,0 +1,29 @@ +#!/usr/bin/env bats +# apparmor.d - Full set of apparmor profiles +# Copyright (C) 2024 Alexandre Pujol +# SPDX-License-Identifier: GPL-2.0-only + +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/w.bats b/tests/bats/w.bats new file mode 100644 index 00000000..7f358aac --- /dev/null +++ b/tests/bats/w.bats @@ -0,0 +1,22 @@ +#!/usr/bin/env bats +# apparmor.d - Full set of apparmor profiles +# Copyright (C) 2024 Alexandre Pujol +# SPDX-License-Identifier: GPL-2.0-only + +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 +}