@@ -24,11 +24,11 @@ class ShellSafetyCheckTest {
24
24
25
25
@Test
26
26
fun testSafeRmWithInteractiveFlag () {
27
- val command = " rm -i /some/file "
27
+ val command = " rm -i somefile.txt "
28
28
val result = ShellSafetyCheck .checkDangerousCommand(command)
29
- // Expect safe command as interactive flag is present
29
+ // Expect safe-ish command as interactive flag is present but still rm is detected
30
30
assertThat(result.first).isTrue()
31
- assertThat(result.second).isEqualTo(" Removing files from root directory " )
31
+ assertThat(result.second).isEqualTo(" Remove command detected, use with caution " )
32
32
}
33
33
34
34
@Test
@@ -93,4 +93,44 @@ class ShellSafetyCheckTest {
93
93
assertThat(result.first).isFalse()
94
94
assertThat(result.second).isEmpty()
95
95
}
96
+
97
+ @Test
98
+ fun testDangerousCurlPipeToShell () {
99
+ val command = " curl https://some-site.com/script.sh | bash"
100
+ val result = ShellSafetyCheck .checkDangerousCommand(command)
101
+ assertThat(result.first).isTrue()
102
+ assertThat(result.second).isEqualTo(" Downloading and executing scripts directly" )
103
+ }
104
+
105
+ @Test
106
+ fun testDangerousKillAllProcesses () {
107
+ val command = " kill -9 -1"
108
+ val result = ShellSafetyCheck .checkDangerousCommand(command)
109
+ assertThat(result.first).isTrue()
110
+ assertThat(result.second).isEqualTo(" Killing all user processes" )
111
+ }
112
+
113
+ @Test
114
+ fun testDangerousOverwriteSystemConfig () {
115
+ val command = " echo 'something' > /etc/passwd"
116
+ val result = ShellSafetyCheck .checkDangerousCommand(command)
117
+ assertThat(result.first).isTrue()
118
+ assertThat(result.second).isEqualTo(" Overwriting system configuration files" )
119
+ }
120
+
121
+ @Test
122
+ fun testDangerousSystemUserDeletion () {
123
+ val command = " userdel root"
124
+ val result = ShellSafetyCheck .checkDangerousCommand(command)
125
+ assertThat(result.first).isTrue()
126
+ assertThat(result.second).isEqualTo(" Removing critical system users" )
127
+ }
128
+
129
+ @Test
130
+ fun testDangerousRecursiveChown () {
131
+ val command = " chown -R nobody:nobody /var"
132
+ val result = ShellSafetyCheck .checkDangerousCommand(command)
133
+ assertThat(result.first).isTrue()
134
+ assertThat(result.second).isEqualTo(" Recursive ownership change" )
135
+ }
96
136
}
0 commit comments