Skip to content

Commit 2a3c4b8

Browse files
authored
improve tests (#140)
* improve tests
1 parent dd17f16 commit 2a3c4b8

File tree

43 files changed

+2156
-12
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2156
-12
lines changed

shellfirm/checks/fs-strict.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
description: "Are you sure that you want to change permissions?"
44
id: fs-strict:change_permissions
55
- from: fs-strict
6-
test: ^rm\s{1,}(?:-Rf|-rf|-fR|-fr|-r|-R|-f)?\s*(.*)
6+
test: ^rm\s{1,}(?:-Rf|-rf|-fR|-fr|-r|-R|-f)?\s*(.*)\r?
77
description: "Are you sure you want to continue with deletion?"
88
id: fs-strict:any_deletion
99
filters:

shellfirm/checks/fs.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
- from: fs
2-
test: 'rm\s{1,}(-R|-r|-fR|-fr|-Rf|-rf)\s*(\*|\.{1,}|/)\s*$'
2+
test: 'rm\s{1,}(?:-R|-r|-fR|-fr|-Rf|-rf|-v|--force|--verbose|--preserve-root)\s*(?:-R|-r|-fR|-fr|-Rf|-rf|-v|--force|--verbose|--preserve-root)?\s*(?:\*|\.{1,}|/)\s*$'
33
description: "You are going to delete everything in the path."
44
id: fs:recursively_delete
55
filters:
66
IsExists: "3"
77
- from: fs
8-
test: mv\s{1,}([a-zA-Z0-9.!@/#$%^&*()']+)\s*/dev/null
8+
test: mv\s+(?:-[a-zA-Z]+\s+)?(?:--[a-zA-Z-]+\s+)?(?:[^\s]+\s+)+/dev/null
99
description: "The files will be discarded and destroyed."
1010
id: fs:move_to_dev_null
1111
filters:
@@ -65,7 +65,7 @@
6565
description: "Are you sure you want to mount this device? This could affect system stability."
6666
id: fs:mount_operations
6767
- from: fs
68-
test: '(?:lvremove|pvremove|vgremove)\s+.*(/dev/([hs]d[a-z]|mmcblk[0-9]))'
68+
test: '(?:sudo\s+)?(?:lvremove|pvremove|vgremove)\s+(?:-[a-zA-Z]+\s+)?(?:--[a-zA-Z-]+\s+)?(?:/dev/(?:[hs]d[a-z]|mmcblk[0-9])|/dev/mapper/[^\s]+|[^\s]+)'
6969
description: "Are you sure you want to remove this logical volume/volume group? This will delete all data."
7070
id: fs:lvm_operations
7171
- from: fs
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
---
22
source: shellfirm/src/bin/cmd/command.rs
33
expression: "execute(\"rm -rf /\", &settings, &settings.get_active_checks().unwrap(), true)"
4+
snapshot_kind: text
45
---
56
Ok(
67
CmdExit {
78
code: 0,
89
message: Some(
9-
"---\n- id: \"fs:recursively_delete\"\n test: \"rm\\\\s{1,}(-R|-r|-fR|-fr|-Rf|-rf)\\\\s*(\\\\*|\\\\.{1,}|/)\\\\s*$\"\n description: You are going to delete everything in the path.\n from: fs\n challenge: Math\n filters:\n IsExists: \"3\"\n",
10+
"---\n- id: \"fs:recursively_delete\"\n test: \"rm\\\\s{1,}(?:-R|-r|-fR|-fr|-Rf|-rf|-v|--force|--verbose|--preserve-root)\\\\s*(?:-R|-r|-fR|-fr|-Rf|-rf|-v|--force|--verbose|--preserve-root)?\\\\s*(?:\\\\*|\\\\.{1,}|/)\\\\s*$\"\n description: You are going to delete everything in the path.\n from: fs\n challenge: Math\n filters:\n IsExists: \"3\"\n",
1011
),
1112
},
1213
)

shellfirm/tests/checks/base-delete_all_cron_tasks.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
description: match command
44
- test: crontab -r
55
description: match command with multiple spaces
6+
- test: " crontab -r"
7+
description: match command with multiple spaces
68
- test: crontab-r
79
description: invalid command

shellfirm/tests/checks/base-reboot_machine.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
description: match command with flag
66
- test: reboot -r now
77
description: match command with flag value
8+
- test: reboot -r now
9+
description: match command with spaces
810
- test: reboot
911
description: match command with spaces
12+
- test: reboot now -r
13+
description: match command with flag value
1014
- test: reboott
1115
description: not match

shellfirm/tests/checks/base-shutdown_machine.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
description: match command with flag
66
- test: shutdown -r now
77
description: match command with flag value
8+
- test: shutdown -r now
9+
description: match command with spaces
10+
- test: shutdown now -r
11+
description: match command with spaces
812
- test: shutdown
913
description: match command with spaces
1014
- test: shutdownn

shellfirm/tests/checks/fs-blockdev_disk_modify.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
---
22
- test: blockdev --setro /dev/sda
33
description: match setting read-only mode
4+
- test: blockdev --setro /dev/sda
5+
description: match setting read-only mode with spaces
46
- test: blockdev --setrw /dev/sda
57
description: match setting read-write mode
8+
- test: blockdev --setrw /dev/sda
9+
description: match setting read-write mode with spaces
610
- test: blockdev --flushbufs /dev/sda
711
description: match flushing buffers
812
- test: blockdev --rereadpt /dev/sda
913
description: match rereading partition table
14+
- test: blockdev --rereadpt /dev/sda
15+
description: match rereading partition table with spaces
1016
- test: blockdev --report /dev/sda
1117
description: match reporting device information
1218
- test: blockdev --getro /dev/sda

shellfirm/tests/checks/fs-dd_advanced_disk_write.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
---
22
- test: dd if=file of=/dev/sda seek=1
33
description: match writing at specific sector
4+
- test: dd if=file of=/dev/sda seek=1
5+
description: match writing at specific sector with spaces
6+
- test: dd seek=1 of=/dev/sda if=file
7+
description: match writing at specific sector with spaces
48
- test: dd if=file of=/dev/sda conv=notrunc
59
description: match writing without truncating
610
- test: dd if=/dev/sda of=file skip=1

shellfirm/tests/checks/fs-dd_block_device.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
---
22
- test: dd if=image.img of=/dev/sda
33
description: match command writing to hard disk
4+
- test: dd if=image.img of=/dev/sda
5+
description: match command writing to hard disk with spaces
6+
- test: dd of=/dev/sda if=image.img
7+
description: match command writing to hard disk with spaces
48
- test: dd if=image.img of=/dev/sdb
59
description: match command writing to second hard disk
610
- test: dd if=image.img of=/dev/mmcblk0
@@ -13,3 +17,29 @@
1317
description: should not match reading from disk
1418
- test: dd if=file.txt of=output.txt
1519
description: should not match regular file operations
20+
- test: "dd if=image.img of=/dev/sda"
21+
description: "match command with extra spaces"
22+
- test: "dd of=/dev/sda if=image.img"
23+
description: "match command with extra spaces"
24+
- test: "sudo dd if=image.img of=/dev/sda"
25+
description: "match command with sudo"
26+
- test: "sudo dd of=/dev/sda if=image.img"
27+
description: "match command with sudo"
28+
- test: "dd if=image.img of=/dev/sda bs=4M count=1"
29+
description: "match command with count parameter"
30+
- test: "dd if=image.img of=/dev/sda bs=4M seek=1"
31+
description: "match command with seek parameter"
32+
- test: "dd if=image.img of=/dev/sda bs=4M conv=notrunc"
33+
description: "match command with conv parameter"
34+
- test: "dd if=image.img of=/dev/sda2"
35+
description: "match command with different partition"
36+
- test: "dd if=image.img of=/dev/sdb"
37+
description: "match command with different disk"
38+
- test: "dd if=image.img of=/dev/mmcblk0p2"
39+
description: "match command with different SD card partition"
40+
- test: "dd if=image.img of=/dev/sda status=progress"
41+
description: "match command with progress status"
42+
- test: "dd if=image.img of=/dev/sda status=none"
43+
description: "match command with no status"
44+
- test: "dd if=image.img of=/dev/sda status=noxfer"
45+
description: "match command with no transfer status"

shellfirm/tests/checks/fs-delete_find_files.yaml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,33 @@
33
description: match command
44
- test: find / | -delete
55
description: match command
6+
- test: find / | -delete
7+
description: match command with spaves
68
- test: findd / | -delete
7-
description: invalid command
9+
description: invalid command
10+
- test: "find . -delete"
11+
description: "match command with extra spaces"
12+
- test: "find / -delete"
13+
description: "match command with extra spaces"
14+
- test: "sudo find . -delete"
15+
description: "match command with sudo"
16+
- test: "sudo find / -delete"
17+
description: "match command with sudo"
18+
- test: "find . -type f -delete"
19+
description: "match command with type option"
20+
- test: "find / -name '*.txt' -delete"
21+
description: "match command with name pattern"
22+
- test: "find . -mtime +7 -delete"
23+
description: "match command with time option"
24+
- test: "find /home -delete"
25+
description: "match command with home directory"
26+
- test: "find /var -delete"
27+
description: "match command with var directory"
28+
- test: "find /usr -delete"
29+
description: "match command with usr directory"
30+
- test: "find . -type f -name '*.log' -delete"
31+
description: "match command with multiple conditions"
32+
- test: "find / -type d -empty -delete"
33+
description: "match command with empty directory condition"
34+
- test: "find . -type f -size +100M -delete"
35+
description: "match command with size condition"

0 commit comments

Comments
 (0)