tests: add more integration tests for core tools.

This commit is contained in:
Alexandre Pujol 2024-11-12 21:42:31 +00:00
parent c741f74323
commit 5611001e5b
Failed to generate hash of commit
19 changed files with 484 additions and 9 deletions

View file

@ -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
}

View file

@ -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"

28
tests/bats/cpuid.bats Normal file
View file

@ -0,0 +1,28 @@
#!/usr/bin/env bats
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <alexandre@pujol.io>
# 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
}

View file

@ -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

34
tests/bats/dfc.bats Normal file
View file

@ -0,0 +1,34 @@
#!/usr/bin/env bats
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <alexandre@pujol.io>
# 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 &#34;ext&#34; in the filesystem type" {
dfc -t ext
aa_check
}

58
tests/bats/homectl.bats Normal file
View file

@ -0,0 +1,58 @@
#!/usr/bin/env bats
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <alexandre@pujol.io>
# 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
}

View file

@ -0,0 +1,27 @@
#!/usr/bin/env bats
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <alexandre@pujol.io>
# 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"
}

View file

@ -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
}

22
tests/bats/sync.bats Normal file
View file

@ -0,0 +1,22 @@
#!/usr/bin/env bats
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <alexandre@pujol.io>
# 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
}

View file

@ -0,0 +1,23 @@
#!/usr/bin/env bats
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <alexandre@pujol.io>
# 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
}

View file

@ -0,0 +1,29 @@
#!/usr/bin/env bats
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <alexandre@pujol.io>
# 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
}

View file

@ -0,0 +1,22 @@
#!/usr/bin/env bats
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <alexandre@pujol.io>
# 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
}

View file

@ -0,0 +1,29 @@
#!/usr/bin/env bats
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <alexandre@pujol.io>
# 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
}

View file

@ -0,0 +1,41 @@
#!/usr/bin/env bats
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <alexandre@pujol.io>
# 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
}

View file

@ -0,0 +1,28 @@
#!/usr/bin/env bats
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <alexandre@pujol.io>
# 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
}

29
tests/bats/upower.bats Normal file
View file

@ -0,0 +1,29 @@
#!/usr/bin/env bats
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <alexandre@pujol.io>
# 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
}

41
tests/bats/userdbctl.bats Normal file
View file

@ -0,0 +1,41 @@
#!/usr/bin/env bats
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <alexandre@pujol.io>
# 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
}

29
tests/bats/uuidd.bats Normal file
View file

@ -0,0 +1,29 @@
#!/usr/bin/env bats
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <alexandre@pujol.io>
# 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
}

22
tests/bats/w.bats Normal file
View file

@ -0,0 +1,22 @@
#!/usr/bin/env bats
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <alexandre@pujol.io>
# 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
}