Skip to content

Commit

Permalink
tests: add more integration tests for core tools.
Browse files Browse the repository at this point in the history
  • Loading branch information
roddhjav committed Nov 12, 2024
1 parent c741f74 commit 5611001
Show file tree
Hide file tree
Showing 19 changed files with 484 additions and 9 deletions.
2 changes: 1 addition & 1 deletion tests/bats/chsh.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
5 changes: 4 additions & 1 deletion tests/bats/common.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
28 changes: 28 additions & 0 deletions tests/bats/cpuid.bats
Original file line number Diff line number Diff line change
@@ -0,0 1,28 @@
#!/usr/bin/env bats
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <[email protected]>
# 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
}
6 changes: 6 additions & 0 deletions tests/bats/df.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions tests/bats/dfc.bats
Original file line number Diff line number Diff line change
@@ -0,0 1,34 @@
#!/usr/bin/env bats
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <[email protected]>
# 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 changes: 58 additions & 0 deletions tests/bats/homectl.bats
Original file line number Diff line number Diff line change
@@ -0,0 1,58 @@
#!/usr/bin/env bats
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <[email protected]>
# 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
}
27 changes: 27 additions & 0 deletions tests/bats/hostnamectl.bats
Original file line number Diff line number Diff line change
@@ -0,0 1,27 @@
#!/usr/bin/env bats
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <[email protected]>
# 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"
}
18 changes: 11 additions & 7 deletions tests/bats/ip.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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 changes: 22 additions & 0 deletions tests/bats/sync.bats
Original file line number Diff line number Diff line change
@@ -0,0 1,22 @@
#!/usr/bin/env bats
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <[email protected]>
# 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
}
23 changes: 23 additions & 0 deletions tests/bats/systemd-ac-power.bats
Original file line number Diff line number Diff line change
@@ -0,0 1,23 @@
#!/usr/bin/env bats
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <[email protected]>
# 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
}

29 changes: 29 additions & 0 deletions tests/bats/systemd-analyze.bats
Original file line number Diff line number Diff line change
@@ -0,0 1,29 @@
#!/usr/bin/env bats
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <[email protected]>
# 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
}

22 changes: 22 additions & 0 deletions tests/bats/systemd-cat.bats
Original file line number Diff line number Diff line change
@@ -0,0 1,22 @@
#!/usr/bin/env bats
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <[email protected]>
# 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
}
29 changes: 29 additions & 0 deletions tests/bats/systemd-cgls.bats
Original file line number Diff line number Diff line change
@@ -0,0 1,29 @@
#!/usr/bin/env bats
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <[email protected]>
# 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
}

41 changes: 41 additions & 0 deletions tests/bats/systemd-id128.bats
Original file line number Diff line number Diff line change
@@ -0,0 1,41 @@
#!/usr/bin/env bats
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <[email protected]>
# 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
}

Loading

0 comments on commit 5611001

Please sign in to comment.