1
0
mirror of https://github.com/containers/netavark.git synced 2026-02-06 09:45:04 +01:00
Files
netavark/test/001-basic.bats
Paul Holzinger d49f979ff2 use OsString/Path over String for file paths
Rust String type has a pretty well documented difference to most string
types in many other languages. A rust string must be valid utf-8.
However linux itself does not care about the char encoding in paths, it
is simply a non zero byte array. This means that technically netavark
will not accept all valid paths. While it unlikely that anyone is using
non utf-8 paths in the real world it is still a non great to deny that.

Rust actually offers the OsString/OsStr types that do not enforce the
utf-8 requirement. And there is also PathBuf/Path types that futher
abstract file paths. So to fix this just use these types instead.

See the added test which checks for it, without this patch we would see
a `error: invalid UTF-8 was detected in one or more arguments` message.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-11-17 14:40:45 +01:00

36 lines
1.3 KiB
Bash

#!/usr/bin/env bats -*- bats -*-
#
# basic netavark tests
#
load helpers
@test "netavark version" {
run_netavark --version
assert "$output" =~ "netavark 1\.[0-9]+\.[0-9]+(-rc|-dev)?" "expected version"
run_netavark version
json="$output"
assert_json "$json" ".version" =~ "^1\.[0-9]+\.[0-9]+(-rc[0-9]|-dev)?" "correct version"
assert_json "$json" ".commit" =~ "[0-9a-f]{40}" "shows commit sha"
assert_json "$json" ".build_time" =~ "20.*" "show build date"
assert_json "$json" ".target" =~ ".*" "contains target string"
}
@test "netavark error - invalid ns path" {
expected_rc=1 run_netavark -f ${TESTSDIR}/testfiles/simplebridge.json setup /test/1
assert_json ".error" "invalid namespace path: IO error: No such file or directory (os error 2)" "Namespace path does not exists"
}
@test "netavark error - invalid config path" {
expected_rc=1 run_netavark -f /test/1 setup $(get_container_netns_path)
assert_json ".error" "failed to load network options: IO error: No such file or directory (os error 2)" "Config file does not exists"
}
@test "netavark - check non utf-8 paths" {
# do not use run_netavark here as it sets --config
run_helper $NETAVARK --config $'/tmp/\xff.test' version
json="$output"
assert_json "$json" ".version" =~ "^1\.[0-9]+\.[0-9]+(-rc[0-9]|-dev)?" "correct version"
}