fix package tests for 1.5.6-rc2 (#2652)

* fix go deps for test
* fix package tests for 1.5.6-rc2
* fix context func tests
* docker: pin build image version for alpine

---------

Co-authored-by: sabban <github@sabban.eu>
This commit is contained in:
mmetc 2023-12-11 10:07:09 +01:00 committed by GitHub
parent 04f3dc09f9
commit 1b4ec66148
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 8 deletions

View file

@ -1,7 +1,7 @@
# vim: set ft=dockerfile: # vim: set ft=dockerfile:
ARG GOVERSION=1.21.5 ARG GOVERSION=1.21.5
FROM golang:${GOVERSION}-alpine AS build FROM golang:${GOVERSION}-alpine3.18 AS build
WORKDIR /go/src/crowdsec WORKDIR /go/src/crowdsec

View file

@ -8,8 +8,7 @@ roles:
name: geerlingguy.postgresql name: geerlingguy.postgresql
# these should be included as dependencies of crowdsecurity.testing, but sometime are not # these should be included as dependencies of crowdsecurity.testing, but sometime are not
- src: geerlingguy.repo-epel - src: geerlingguy.repo-epel
- src: gantsign.ansible-role-golang - src: gantsign.golang
name: gantsign.golang
collections: collections:
- name: ansible.posix - name: ansible.posix

View file

@ -1,5 +1,5 @@
# vim: set ft=yaml.ansible: # vim: set ft=yaml.ansible:
--- ---
golang_version: "1.21.5" golang_version: "1.21.4"
golang_install_dir: "/opt/go/{{ golang_version }}" golang_install_dir: "/opt/go/{{ golang_version }}"

View file

@ -232,6 +232,8 @@ teardown() {
ACQUIS_YAML=$(config_get '.crowdsec_service.acquisition_path') ACQUIS_YAML=$(config_get '.crowdsec_service.acquisition_path')
config_set "$ACQUIS_YAML" 'del(.filenames)' config_set "$ACQUIS_YAML" 'del(.filenames)'
# if filenames are missing, it won't be able to detect source type
config_set "$ACQUIS_YAML" '.source="file"'
rune -1 wait-for "${CROWDSEC}" rune -1 wait-for "${CROWDSEC}"
assert_stderr --partial "failed to configure datasource file: no filename or filenames configuration provided" assert_stderr --partial "failed to configure datasource file: no filename or filenames configuration provided"

View file

@ -62,7 +62,8 @@ teardown() {
@test "context file is good" { @test "context file is good" {
echo '{"source_ip":["evt.Parsed.source_ip"]}' > "$CONTEXT_YAML" echo '{"source_ip":["evt.Parsed.source_ip"]}' > "$CONTEXT_YAML"
rune -0 "$CROWDSEC" -t --debug rune -0 "$CROWDSEC" -t --debug
assert_stderr --partial 'console context to send: {"source_ip":["evt.Parsed.source_ip"]}' # the log content may have quotes escaped or not, depending on tty detection
assert_stderr --regexp 'console context to send: .*source_ip.*evt.Parsed.source_ip'
} }
@test "context file is from hub (local item)" { @test "context file is from hub (local item)" {
@ -71,7 +72,7 @@ teardown() {
echo '{"context":{"source_ip":["evt.Parsed.source_ip"]}}' > "$CONFIG_DIR/contexts/foobar.yaml" echo '{"context":{"source_ip":["evt.Parsed.source_ip"]}}' > "$CONFIG_DIR/contexts/foobar.yaml"
rune -0 "$CROWDSEC" -t --trace rune -0 "$CROWDSEC" -t --trace
assert_stderr --partial "loading console context from $CONFIG_DIR/contexts/foobar.yaml" assert_stderr --partial "loading console context from $CONFIG_DIR/contexts/foobar.yaml"
assert_stderr --partial 'console context to send: {"source_ip":["evt.Parsed.source_ip"]}' assert_stderr --regexp 'console context to send: .*source_ip.*evt.Parsed.source_ip'
} }
@test "merge multiple contexts" { @test "merge multiple contexts" {
@ -81,7 +82,7 @@ teardown() {
rune -0 "$CROWDSEC" -t --trace rune -0 "$CROWDSEC" -t --trace
assert_stderr --partial "loading console context from $CONFIG_DIR/contexts/one.yaml" assert_stderr --partial "loading console context from $CONFIG_DIR/contexts/one.yaml"
assert_stderr --partial "loading console context from $CONFIG_DIR/contexts/two.yaml" assert_stderr --partial "loading console context from $CONFIG_DIR/contexts/two.yaml"
assert_stderr --partial 'console context to send: {"one":["evt.Parsed.source_ip"],"two":["evt.Parsed.source_ip"]}' assert_stderr --regexp 'console context to send: .*one.*evt.Parsed.source_ip.*two.*evt.Parsed.source_ip'
} }
@test "merge contexts from hub and context.yaml file" { @test "merge contexts from hub and context.yaml file" {
@ -91,5 +92,5 @@ teardown() {
rune -0 "$CROWDSEC" -t --trace rune -0 "$CROWDSEC" -t --trace
assert_stderr --partial "loading console context from $CONFIG_DIR/contexts/one.yaml" assert_stderr --partial "loading console context from $CONFIG_DIR/contexts/one.yaml"
assert_stderr --partial "loading console context from $CONFIG_DIR/console/context.yaml" assert_stderr --partial "loading console context from $CONFIG_DIR/console/context.yaml"
assert_stderr --partial 'console context to send: {"one":["evt.Parsed.source_ip","evt.Parsed.source_ip_2"]}' assert_stderr --regexp 'console context to send: .*one.*evt.Parsed.source_ip.*evt.Parsed.source_ip_2'
} }

View file

@ -54,10 +54,18 @@ remove_init_data() {
# we need a separate function for initializing config when testing package # we need a separate function for initializing config when testing package
# because we want to test the configuration as well # because we want to test the configuration as well
config_prepare() {
# remove trailing slash from CONFIG_DIR
# since it's assumed to be missing during the tests
yq e -i '
.config_paths.config_dir |= sub("/$", "")
' "${CONFIG_DIR}/config.yaml"
}
make_init_data() { make_init_data() {
./bin/assert-crowdsec-not-running || die "Cannot create fixture data." ./bin/assert-crowdsec-not-running || die "Cannot create fixture data."
config_prepare
./instance-db config-yaml ./instance-db config-yaml
./instance-db setup ./instance-db setup