|
@@ -58,15 +58,55 @@ teardown() {
|
|
|
refute_line "crowdsecurity/mysql"
|
|
|
}
|
|
|
|
|
|
-@test "cannot remove a collection twice" {
|
|
|
- run -0 cscli collections install crowdsecurity/mysql -o human
|
|
|
- run -0 --separate-stderr cscli collections remove crowdsecurity/mysql
|
|
|
- run -1 --separate-stderr cscli collections remove crowdsecurity/mysql -o json
|
|
|
- run -0 jq -r '.level' <(stderr)
|
|
|
- assert_output 'fatal'
|
|
|
- run -0 jq -r '.msg' <(stderr)
|
|
|
- assert_output --partial "unable to disable crowdsecurity/mysql"
|
|
|
- assert_output --partial "doesn't exist"
|
|
|
+@test "must use --force to remove a collection that belongs to another, which becomes tainted" {
|
|
|
+ # we expect no error since we may have multiple collections, some removed and some not
|
|
|
+ run -0 --separate-stderr cscli collections remove crowdsecurity/sshd
|
|
|
+ assert_stderr --partial "crowdsecurity/sshd belongs to other collections"
|
|
|
+ assert_stderr --partial "[crowdsecurity/linux]"
|
|
|
+
|
|
|
+ run -0 --separate-stderr cscli collections remove crowdsecurity/sshd --force
|
|
|
+ assert_stderr --partial "Removed symlink [crowdsecurity/sshd]"
|
|
|
+ run -0 cscli collections inspect crowdsecurity/linux -o json
|
|
|
+ run -0 jq -r '.tainted' <(output)
|
|
|
+ assert_output "true"
|
|
|
+}
|
|
|
+
|
|
|
+@test "can remove a collection" {
|
|
|
+ run -0 cscli collections remove crowdsecurity/linux
|
|
|
+ assert_output --partial "Removed"
|
|
|
+ assert_output --regexp ".*for the new configuration to be effective."
|
|
|
+ run -0 cscli collections inspect crowdsecurity/linux -o human
|
|
|
+ assert_line 'installed: false'
|
|
|
+}
|
|
|
+
|
|
|
+@test "collections delete is an alias for collections remove" {
|
|
|
+ run -0 cscli collections delete crowdsecurity/linux
|
|
|
+ assert_output --partial "Removed"
|
|
|
+ assert_output --regexp ".*for the new configuration to be effective."
|
|
|
+}
|
|
|
+
|
|
|
+@test "removing a collection that does not exist is noop" {
|
|
|
+ run -0 cscli collections remove crowdsecurity/apache2
|
|
|
+ refute_output --partial "Removed"
|
|
|
+ assert_output --regexp ".*for the new configuration to be effective."
|
|
|
+}
|
|
|
+
|
|
|
+@test "can remove a removed collection" {
|
|
|
+ run -0 cscli collections install crowdsecurity/mysql
|
|
|
+ run -0 cscli collections remove crowdsecurity/mysql
|
|
|
+ assert_output --partial "Removed"
|
|
|
+ run -0 cscli collections remove crowdsecurity/mysql
|
|
|
+ refute_output --partial "Removed"
|
|
|
+}
|
|
|
+
|
|
|
+@test "can remove all collections" {
|
|
|
+ run -0 cscli collections remove --all
|
|
|
+ assert_output --partial "Removed symlink [crowdsecurity/sshd]"
|
|
|
+ assert_output --partial "Removed symlink [crowdsecurity/linux]"
|
|
|
+ run -0 cscli hub list -o json
|
|
|
+ assert_json '{collections:[],parsers:[],postoverflows:[],scenarios:[]}'
|
|
|
+ run -0 cscli collections remove --all
|
|
|
+ assert_output --partial 'Disabled 0 items'
|
|
|
}
|
|
|
|
|
|
# TODO test download-only
|