2022-03-09 13:45:36 +00:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
# vim: ft=bats:list:ts=8:sts=4:sw=4:et:ai:si:
|
|
|
|
|
|
|
|
set -u
|
|
|
|
|
|
|
|
setup_file() {
|
2022-03-18 09:13:12 +00:00
|
|
|
load "../lib/setup_file.sh"
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
teardown_file() {
|
2022-03-18 09:13:12 +00:00
|
|
|
load "../lib/teardown_file.sh"
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
load "../lib/setup.sh"
|
|
|
|
./instance-data load
|
|
|
|
./instance-crowdsec start
|
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
|
|
|
./instance-crowdsec stop
|
|
|
|
}
|
|
|
|
|
|
|
|
#----------
|
|
|
|
|
2022-08-16 08:17:21 +00:00
|
|
|
@test "we have exactly one machine" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli machines list -o json
|
|
|
|
rune -0 jq -c '[. | length, .[0].machineId[0:32], .[0].isValidated]' <(output)
|
2022-08-16 08:17:21 +00:00
|
|
|
assert_output '[1,"githubciXXXXXXXXXXXXXXXXXXXXXXXX",true]'
|
2022-03-09 13:45:36 +00:00
|
|
|
}
|
|
|
|
|
2023-12-04 21:59:52 +00:00
|
|
|
@test "don't overwrite local credentials by default" {
|
|
|
|
rune -1 cscli machines add local -a -o json
|
|
|
|
rune -0 jq -r '.msg' <(stderr)
|
|
|
|
assert_output --partial 'already exists: please remove it, use "--force" or specify a different file with "-f"'
|
|
|
|
rune -0 cscli machines add local -a --force
|
2024-02-01 16:22:52 +00:00
|
|
|
assert_stderr --partial "Machine 'local' successfully added to the local API."
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "passwords have a size limit" {
|
|
|
|
rune -1 cscli machines add local --password "$(printf '%73s' '' | tr ' ' x)"
|
|
|
|
assert_stderr --partial "password too long (max 72 characters)"
|
2023-12-04 21:59:52 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "add a new machine and delete it" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli machines add -a -f /dev/null CiTestMachine -o human
|
2024-02-01 16:22:52 +00:00
|
|
|
assert_stderr --partial "Machine 'CiTestMachine' successfully added to the local API"
|
|
|
|
assert_stderr --partial "API credentials written to '/dev/null'"
|
2022-03-09 13:45:36 +00:00
|
|
|
|
|
|
|
# we now have two machines
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli machines list -o json
|
|
|
|
rune -0 jq -c '[. | length, .[-1].machineId, .[0].isValidated]' <(output)
|
2022-03-09 13:45:36 +00:00
|
|
|
assert_output '[2,"CiTestMachine",true]'
|
|
|
|
|
|
|
|
# delete the test machine
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli machines delete CiTestMachine -o human
|
|
|
|
assert_stderr --partial "machine 'CiTestMachine' deleted successfully"
|
2022-03-09 13:45:36 +00:00
|
|
|
|
|
|
|
# we now have one machine again
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli machines list -o json
|
|
|
|
rune -0 jq '. | length' <(output)
|
2022-03-09 13:45:36 +00:00
|
|
|
assert_output 1
|
|
|
|
}
|
|
|
|
|
2022-07-01 09:03:40 +00:00
|
|
|
@test "register, validate and then remove a machine" {
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli lapi register --machine CiTestMachineRegister -f /dev/null -o human
|
|
|
|
assert_stderr --partial "Successfully registered to Local API (LAPI)"
|
2023-12-04 21:59:52 +00:00
|
|
|
assert_stderr --partial "Local API credentials written to '/dev/null'"
|
2022-03-09 13:45:36 +00:00
|
|
|
|
2022-10-31 09:02:51 +00:00
|
|
|
# the machine is not validated yet
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli machines list -o json
|
|
|
|
rune -0 jq '.[-1].isValidated' <(output)
|
2022-03-09 13:45:36 +00:00
|
|
|
assert_output 'null'
|
|
|
|
|
2022-10-31 09:02:51 +00:00
|
|
|
# validate the machine
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli machines validate CiTestMachineRegister -o human
|
|
|
|
assert_stderr --partial "machine 'CiTestMachineRegister' validated successfully"
|
2022-03-09 13:45:36 +00:00
|
|
|
|
|
|
|
# the machine is now validated
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli machines list -o json
|
|
|
|
rune -0 jq '.[-1].isValidated' <(output)
|
2022-03-09 13:45:36 +00:00
|
|
|
assert_output 'true'
|
|
|
|
|
|
|
|
# delete the test machine again
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli machines delete CiTestMachineRegister -o human
|
|
|
|
assert_stderr --partial "machine 'CiTestMachineRegister' deleted successfully"
|
2022-03-09 13:45:36 +00:00
|
|
|
|
|
|
|
# we now have one machine, again
|
2023-06-01 07:42:27 +00:00
|
|
|
rune -0 cscli machines list -o json
|
|
|
|
rune -0 jq '. | length' <(output)
|
2022-03-09 13:45:36 +00:00
|
|
|
assert_output 1
|
|
|
|
}
|