2020-07-27 13:35:17 +00:00
|
|
|
|
#!/usr/bin/env bats
|
2022-11-29 12:54:13 +00:00
|
|
|
|
#
|
|
|
|
|
# Copyright © 2021 – 2022 Red Hat, Inc.
|
|
|
|
|
#
|
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
|
#
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
#
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
|
# limitations under the License.
|
|
|
|
|
#
|
2020-07-27 13:35:17 +00:00
|
|
|
|
|
|
|
|
|
load 'libs/bats-support/load'
|
|
|
|
|
load 'libs/bats-assert/load'
|
|
|
|
|
load 'libs/helpers'
|
|
|
|
|
|
|
|
|
|
setup() {
|
2021-11-11 00:46:21 +00:00
|
|
|
|
_setup_environment
|
2020-07-27 13:35:17 +00:00
|
|
|
|
cleanup_containers
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
teardown() {
|
|
|
|
|
cleanup_containers
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 15:28:07 +00:00
|
|
|
|
@test "run: Smoke test with true(1)" {
|
2022-11-08 18:58:25 +00:00
|
|
|
|
create_default_container
|
|
|
|
|
|
|
|
|
|
run $TOOLBOX run true
|
|
|
|
|
|
|
|
|
|
assert_success
|
|
|
|
|
assert_output ""
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 18:59:14 +00:00
|
|
|
|
@test "run: Smoke test with false(1)" {
|
|
|
|
|
create_default_container
|
|
|
|
|
|
|
|
|
|
run -1 $TOOLBOX run false
|
|
|
|
|
|
|
|
|
|
assert_failure
|
|
|
|
|
assert_output ""
|
|
|
|
|
}
|
|
|
|
|
|
cmd/run: Ensure that 'run' has the same container environment as 'enter'
Currently, commands invoked using 'toolbox run' have a different
environment than the interactive environment offered by 'toolbox enter'.
This is because 'toolbox run' was invoking the commands using something
like this:
$ bash -c 'exec "$@"' bash [COMMAND]
... whereas, 'toolbox enter' was using something like this:
$ bash -c 'exec "$@"' bash bash --login
In the first case, the helper Bash shell is a non-interactive non-login
shell. This means that it doesn't read any of the usual start-up files,
and, hence, it doesn't pick up anything that's specified in them. It
runs with the default environment variables set up by Podman and the
Toolbx image, plus the environment variables set by Toolbx itself.
In the second case, even though the helper Bash shell is still the same
as the first, it eventually invokes a login shell, which runs the usual
set of start-up files and picks up everything that's specified in them.
Therefore, to ensure parity, 'toolbox run' should always have a login
shell in the call chain inside the Toolbx container.
The easiest option is to always use a helper shell that's a login shell
with 'toolbox run', but not 'toolbox enter' so as to avoid reading the
same start-up files twice, due to two login shells in the call chain.
It will still end up reading the same start-up files twice, if someone
tried to invoke a login shell through 'toolbox run', which is fine.
It's very difficult to be sure that the user is invoking a login shell
through 'toolbox run', and it's not what most users will be doing.
https://github.com/containers/toolbox/issues/1076
2022-10-25 09:07:23 +00:00
|
|
|
|
@test "run: Ensure that a login shell is used to invoke the command" {
|
|
|
|
|
create_default_container
|
|
|
|
|
|
|
|
|
|
cp "$HOME"/.bash_profile "$HOME"/.bash_profile.orig
|
|
|
|
|
echo "echo \"~/.bash_profile read\"" >>"$HOME"/.bash_profile
|
|
|
|
|
|
|
|
|
|
run $TOOLBOX run true
|
|
|
|
|
|
|
|
|
|
mv "$HOME"/.bash_profile.orig "$HOME"/.bash_profile
|
|
|
|
|
|
|
|
|
|
assert_success
|
|
|
|
|
assert_line --index 0 "~/.bash_profile read"
|
|
|
|
|
assert [ ${#lines[@]} -eq 1 ]
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 15:28:07 +00:00
|
|
|
|
@test "run: 'echo \"Hello World\"' inside the default container" {
|
2022-11-08 18:58:25 +00:00
|
|
|
|
create_default_container
|
|
|
|
|
|
2022-11-10 18:03:26 +00:00
|
|
|
|
run $TOOLBOX --verbose run echo "Hello World"
|
2022-11-08 18:58:25 +00:00
|
|
|
|
|
|
|
|
|
assert_success
|
|
|
|
|
assert_line --index $((${#lines[@]}-1)) "Hello World"
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 15:28:07 +00:00
|
|
|
|
@test "run: 'echo \"Hello World\"' inside a restarted container" {
|
2022-11-08 18:58:25 +00:00
|
|
|
|
create_container running
|
|
|
|
|
|
|
|
|
|
start_container running
|
|
|
|
|
stop_container running
|
|
|
|
|
|
2022-11-10 18:03:26 +00:00
|
|
|
|
run $TOOLBOX --verbose run --container running echo "Hello World"
|
2022-11-08 18:58:25 +00:00
|
|
|
|
|
|
|
|
|
assert_success
|
|
|
|
|
assert_line --index $((${#lines[@]}-1)) "Hello World"
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 15:28:07 +00:00
|
|
|
|
@test "run: 'sudo id' inside the default container" {
|
2022-11-10 17:06:41 +00:00
|
|
|
|
create_default_container
|
|
|
|
|
|
|
|
|
|
output="$($TOOLBOX --verbose run sudo id 2>$BATS_TMPDIR/stderr)"
|
|
|
|
|
status="$?"
|
|
|
|
|
|
|
|
|
|
echo "# stderr"
|
|
|
|
|
cat $BATS_TMPDIR/stderr
|
|
|
|
|
echo "# stdout"
|
|
|
|
|
echo $output
|
|
|
|
|
|
|
|
|
|
assert_success
|
|
|
|
|
assert_output --partial "uid=0(root)"
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 19:32:37 +00:00
|
|
|
|
@test "run: Ensure that /run/.containerenv exists" {
|
|
|
|
|
create_default_container
|
|
|
|
|
|
|
|
|
|
run --separate-stderr $TOOLBOX run cat /run/.containerenv
|
|
|
|
|
|
|
|
|
|
assert_success
|
|
|
|
|
assert [ ${#lines[@]} -gt 0 ]
|
|
|
|
|
assert [ ${#stderr_lines[@]} -eq 0 ]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "run: Ensure that /run/.toolboxenv exists" {
|
|
|
|
|
create_default_container
|
|
|
|
|
|
|
|
|
|
run --separate-stderr $TOOLBOX run test -f /run/.toolboxenv
|
|
|
|
|
|
|
|
|
|
assert_success
|
|
|
|
|
assert [ ${#lines[@]} -eq 0 ]
|
|
|
|
|
assert [ ${#stderr_lines[@]} -eq 0 ]
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 19:35:18 +00:00
|
|
|
|
@test "run: Ensure that the default container is used" {
|
|
|
|
|
run echo "$name"
|
|
|
|
|
|
|
|
|
|
assert_success
|
|
|
|
|
assert_output ""
|
|
|
|
|
|
|
|
|
|
local default_container_name="$(get_system_id)-toolbox-$(get_system_version)"
|
|
|
|
|
create_default_container
|
|
|
|
|
create_container other-container
|
|
|
|
|
|
|
|
|
|
run --separate-stderr $TOOLBOX run cat /run/.containerenv
|
|
|
|
|
|
|
|
|
|
assert_success
|
|
|
|
|
assert [ ${#lines[@]} -gt 0 ]
|
|
|
|
|
assert [ ${#stderr_lines[@]} -eq 0 ]
|
|
|
|
|
|
|
|
|
|
source <(echo "$output")
|
|
|
|
|
run echo "$name"
|
|
|
|
|
|
|
|
|
|
assert_success
|
|
|
|
|
assert_output "$default_container_name"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "run: Ensure that a specific container is used" {
|
|
|
|
|
run echo "$name"
|
|
|
|
|
|
|
|
|
|
assert_success
|
|
|
|
|
assert_output ""
|
|
|
|
|
|
|
|
|
|
local default_container_name="$(get_system_id)-toolbox-$(get_system_version)"
|
|
|
|
|
create_default_container
|
|
|
|
|
create_container other-container
|
|
|
|
|
|
|
|
|
|
run --separate-stderr $TOOLBOX run --container other-container cat /run/.containerenv
|
|
|
|
|
|
|
|
|
|
assert_success
|
|
|
|
|
assert [ ${#lines[@]} -gt 0 ]
|
|
|
|
|
assert [ ${#stderr_lines[@]} -eq 0 ]
|
|
|
|
|
|
|
|
|
|
source <(echo "$output")
|
|
|
|
|
run echo "$name"
|
|
|
|
|
|
|
|
|
|
assert_success
|
|
|
|
|
assert_output "other-container"
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-08 22:18:53 +00:00
|
|
|
|
@test "run: Ensure that $HOME is used as a fallback working directory" {
|
|
|
|
|
local default_container_name="$(get_system_id)-toolbox-$(get_system_version)"
|
|
|
|
|
create_default_container
|
|
|
|
|
|
|
|
|
|
pushd /etc/kernel
|
|
|
|
|
run --separate-stderr $TOOLBOX run pwd
|
|
|
|
|
popd
|
|
|
|
|
|
|
|
|
|
assert_success
|
|
|
|
|
assert_line --index 0 "$HOME"
|
|
|
|
|
assert [ ${#lines[@]} -eq 1 ]
|
|
|
|
|
lines=("${stderr_lines[@]}")
|
|
|
|
|
assert_line --index $((${#stderr_lines[@]}-2)) "Error: directory /etc/kernel not found in container $default_container_name"
|
|
|
|
|
assert_line --index $((${#stderr_lines[@]}-1)) "Using $HOME instead."
|
|
|
|
|
assert [ ${#stderr_lines[@]} -gt 2 ]
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-14 14:15:10 +00:00
|
|
|
|
@test "run: Pass down 1 additional file descriptor" {
|
|
|
|
|
create_default_container
|
|
|
|
|
|
|
|
|
|
# File descriptors 3 and 4 are reserved by Bats.
|
|
|
|
|
run --separate-stderr $TOOLBOX run --preserve-fds 3 readlink /proc/self/fd/5 5>/dev/null
|
|
|
|
|
|
|
|
|
|
assert_success
|
|
|
|
|
assert_line --index 0 "/dev/null"
|
|
|
|
|
assert [ ${#lines[@]} -eq 1 ]
|
|
|
|
|
assert [ ${#stderr_lines[@]} -eq 0 ]
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 15:28:07 +00:00
|
|
|
|
@test "run: Try the non-existent default container with none other present" {
|
2021-11-07 11:40:42 +00:00
|
|
|
|
local default_container_name="$(get_system_id)-toolbox-$(get_system_version)"
|
2020-07-27 13:35:17 +00:00
|
|
|
|
|
2022-11-16 10:58:10 +00:00
|
|
|
|
run --separate-stderr $TOOLBOX run true
|
2020-07-27 13:35:17 +00:00
|
|
|
|
|
|
|
|
|
assert_failure
|
2022-11-16 11:49:31 +00:00
|
|
|
|
assert [ ${#lines[@]} -eq 0 ]
|
2022-11-16 10:58:10 +00:00
|
|
|
|
lines=("${stderr_lines[@]}")
|
2021-11-07 11:40:42 +00:00
|
|
|
|
assert_line --index 0 "Error: container $default_container_name not found"
|
|
|
|
|
assert_line --index 1 "Use the 'create' command to create a toolbox."
|
|
|
|
|
assert_line --index 2 "Run 'toolbox --help' for usage."
|
2022-11-16 11:49:31 +00:00
|
|
|
|
assert [ ${#stderr_lines[@]} -eq 3 ]
|
2021-11-07 11:40:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 15:28:07 +00:00
|
|
|
|
@test "run: Try the non-existent default container with another present" {
|
2021-11-07 11:40:42 +00:00
|
|
|
|
local default_container_name="$(get_system_id)-toolbox-$(get_system_version)"
|
|
|
|
|
|
|
|
|
|
create_container other-container
|
|
|
|
|
|
2022-11-16 10:58:10 +00:00
|
|
|
|
run --separate-stderr $TOOLBOX run true
|
2021-11-07 11:40:42 +00:00
|
|
|
|
|
|
|
|
|
assert_failure
|
2022-11-16 11:49:31 +00:00
|
|
|
|
assert [ ${#lines[@]} -eq 0 ]
|
2022-11-16 10:58:10 +00:00
|
|
|
|
lines=("${stderr_lines[@]}")
|
2021-11-07 11:40:42 +00:00
|
|
|
|
assert_line --index 0 "Error: container $default_container_name not found"
|
|
|
|
|
assert_line --index 1 "Use the 'create' command to create a toolbox."
|
|
|
|
|
assert_line --index 2 "Run 'toolbox --help' for usage."
|
2022-11-16 11:49:31 +00:00
|
|
|
|
assert [ ${#stderr_lines[@]} -eq 3 ]
|
2021-11-07 11:40:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 15:28:07 +00:00
|
|
|
|
@test "run: Try a specific non-existent container with another present" {
|
2021-11-07 11:40:42 +00:00
|
|
|
|
create_container other-container
|
|
|
|
|
|
2022-11-16 17:59:55 +00:00
|
|
|
|
run --separate-stderr $TOOLBOX run --container wrong-container true
|
2021-11-07 11:40:42 +00:00
|
|
|
|
|
|
|
|
|
assert_failure
|
2022-11-16 11:49:31 +00:00
|
|
|
|
assert [ ${#lines[@]} -eq 0 ]
|
2022-11-16 10:58:10 +00:00
|
|
|
|
lines=("${stderr_lines[@]}")
|
2021-11-07 11:40:42 +00:00
|
|
|
|
assert_line --index 0 "Error: container wrong-container not found"
|
|
|
|
|
assert_line --index 1 "Use the 'create' command to create a toolbox."
|
|
|
|
|
assert_line --index 2 "Run 'toolbox --help' for usage."
|
2022-11-16 11:49:31 +00:00
|
|
|
|
assert [ ${#stderr_lines[@]} -eq 3 ]
|
2020-07-27 13:35:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 15:28:07 +00:00
|
|
|
|
@test "run: Try an unsupported distribution" {
|
2022-07-30 17:38:32 +00:00
|
|
|
|
local distro="foo"
|
|
|
|
|
|
2022-11-16 10:58:10 +00:00
|
|
|
|
run --separate-stderr $TOOLBOX --assumeyes run --distro "$distro" ls
|
2022-07-30 17:38:32 +00:00
|
|
|
|
|
|
|
|
|
assert_failure
|
2022-11-16 11:49:31 +00:00
|
|
|
|
assert [ ${#lines[@]} -eq 0 ]
|
2022-11-16 10:58:10 +00:00
|
|
|
|
lines=("${stderr_lines[@]}")
|
2022-08-01 21:44:49 +00:00
|
|
|
|
assert_line --index 0 "Error: invalid argument for '--distro'"
|
|
|
|
|
assert_line --index 1 "Distribution $distro is unsupported."
|
|
|
|
|
assert_line --index 2 "Run 'toolbox --help' for usage."
|
2022-11-16 10:58:10 +00:00
|
|
|
|
assert [ ${#stderr_lines[@]} -eq 3 ]
|
2022-07-30 17:38:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 15:28:07 +00:00
|
|
|
|
@test "run: Try Fedora with an invalid release" {
|
2022-11-16 17:59:55 +00:00
|
|
|
|
run --separate-stderr $TOOLBOX run --distro fedora --release foobar ls
|
2021-12-17 14:27:21 +00:00
|
|
|
|
|
|
|
|
|
assert_failure
|
2022-11-16 11:49:31 +00:00
|
|
|
|
assert [ ${#lines[@]} -eq 0 ]
|
2022-11-16 10:58:10 +00:00
|
|
|
|
lines=("${stderr_lines[@]}")
|
2021-12-17 14:27:21 +00:00
|
|
|
|
assert_line --index 0 "Error: invalid argument for '--release'"
|
2022-07-30 18:16:57 +00:00
|
|
|
|
assert_line --index 1 "The release must be a positive integer."
|
|
|
|
|
assert_line --index 2 "Run 'toolbox --help' for usage."
|
2022-11-16 10:58:10 +00:00
|
|
|
|
assert [ ${#stderr_lines[@]} -eq 3 ]
|
2022-07-30 18:16:57 +00:00
|
|
|
|
|
2022-11-16 10:58:10 +00:00
|
|
|
|
run --separate-stderr $TOOLBOX run --distro fedora --release -3 ls
|
2022-07-30 18:16:57 +00:00
|
|
|
|
|
|
|
|
|
assert_failure
|
2022-11-16 11:49:31 +00:00
|
|
|
|
assert [ ${#lines[@]} -eq 0 ]
|
2022-11-16 10:58:10 +00:00
|
|
|
|
lines=("${stderr_lines[@]}")
|
2022-07-30 18:16:57 +00:00
|
|
|
|
assert_line --index 0 "Error: invalid argument for '--release'"
|
|
|
|
|
assert_line --index 1 "The release must be a positive integer."
|
|
|
|
|
assert_line --index 2 "Run 'toolbox --help' for usage."
|
2022-11-16 10:58:10 +00:00
|
|
|
|
assert [ ${#stderr_lines[@]} -eq 3 ]
|
2022-07-30 18:16:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 15:28:07 +00:00
|
|
|
|
@test "run: Try RHEL with an invalid release" {
|
2022-11-16 10:58:10 +00:00
|
|
|
|
run --separate-stderr $TOOLBOX run --distro rhel --release 8 ls
|
2022-07-30 18:16:57 +00:00
|
|
|
|
|
|
|
|
|
assert_failure
|
2022-11-16 11:49:31 +00:00
|
|
|
|
assert [ ${#lines[@]} -eq 0 ]
|
2022-11-16 10:58:10 +00:00
|
|
|
|
lines=("${stderr_lines[@]}")
|
2022-07-30 18:16:57 +00:00
|
|
|
|
assert_line --index 0 "Error: invalid argument for '--release'"
|
|
|
|
|
assert_line --index 1 "The release must be in the '<major>.<minor>' format."
|
|
|
|
|
assert_line --index 2 "Run 'toolbox --help' for usage."
|
2022-11-16 10:58:10 +00:00
|
|
|
|
assert [ ${#stderr_lines[@]} -eq 3 ]
|
2022-07-30 18:16:57 +00:00
|
|
|
|
|
2022-11-16 10:58:10 +00:00
|
|
|
|
run --separate-stderr $TOOLBOX run --distro rhel --release 8.2foo ls
|
2022-07-30 18:16:57 +00:00
|
|
|
|
|
|
|
|
|
assert_failure
|
2022-11-16 11:49:31 +00:00
|
|
|
|
assert [ ${#lines[@]} -eq 0 ]
|
2022-11-16 10:58:10 +00:00
|
|
|
|
lines=("${stderr_lines[@]}")
|
2022-07-30 18:16:57 +00:00
|
|
|
|
assert_line --index 0 "Error: invalid argument for '--release'"
|
|
|
|
|
assert_line --index 1 "The release must be in the '<major>.<minor>' format."
|
|
|
|
|
assert_line --index 2 "Run 'toolbox --help' for usage."
|
2022-11-16 10:58:10 +00:00
|
|
|
|
assert [ ${#stderr_lines[@]} -eq 3 ]
|
2022-07-30 18:16:57 +00:00
|
|
|
|
|
2022-11-16 10:58:10 +00:00
|
|
|
|
run --separate-stderr $TOOLBOX run --distro rhel --release -2.1 ls
|
2022-07-30 18:16:57 +00:00
|
|
|
|
|
|
|
|
|
assert_failure
|
2022-11-16 11:49:31 +00:00
|
|
|
|
assert [ ${#lines[@]} -eq 0 ]
|
2022-11-16 10:58:10 +00:00
|
|
|
|
lines=("${stderr_lines[@]}")
|
2022-07-30 18:16:57 +00:00
|
|
|
|
assert_line --index 0 "Error: invalid argument for '--release'"
|
|
|
|
|
assert_line --index 1 "The release must be a positive number."
|
|
|
|
|
assert_line --index 2 "Run 'toolbox --help' for usage."
|
2022-11-16 10:58:10 +00:00
|
|
|
|
assert [ ${#stderr_lines[@]} -eq 3 ]
|
2021-12-17 14:27:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 15:28:07 +00:00
|
|
|
|
@test "run: Try a non-default distro without a release" {
|
2021-12-17 14:27:21 +00:00
|
|
|
|
local distro="fedora"
|
|
|
|
|
local system_id="$(get_system_id)"
|
|
|
|
|
|
|
|
|
|
if [ "$system_id" = "fedora" ]; then
|
|
|
|
|
distro="rhel"
|
|
|
|
|
fi
|
|
|
|
|
|
2022-11-16 17:59:55 +00:00
|
|
|
|
run --separate-stderr $TOOLBOX run --distro "$distro" ls
|
2021-12-17 14:27:21 +00:00
|
|
|
|
|
|
|
|
|
assert_failure
|
2022-11-16 11:49:31 +00:00
|
|
|
|
assert [ ${#lines[@]} -eq 0 ]
|
2022-11-16 10:58:10 +00:00
|
|
|
|
lines=("${stderr_lines[@]}")
|
2022-08-01 21:44:49 +00:00
|
|
|
|
assert_line --index 0 "Error: option '--release' is needed"
|
|
|
|
|
assert_line --index 1 "Distribution $distro doesn't match the host."
|
|
|
|
|
assert_line --index 2 "Run 'toolbox --help' for usage."
|
2022-11-16 10:58:10 +00:00
|
|
|
|
assert [ ${#stderr_lines[@]} -eq 3 ]
|
2021-12-17 14:27:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 15:28:07 +00:00
|
|
|
|
@test "run: Smoke test with 'exit 2'" {
|
2021-08-30 13:47:45 +00:00
|
|
|
|
create_default_container
|
|
|
|
|
|
2022-11-16 12:19:21 +00:00
|
|
|
|
run -2 $TOOLBOX run /bin/sh -c 'exit 2'
|
2021-08-30 13:47:45 +00:00
|
|
|
|
assert_failure
|
|
|
|
|
assert_output ""
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 12:34:06 +00:00
|
|
|
|
@test "run: Pass down 1 invalid file descriptor" {
|
|
|
|
|
local default_container_name="$(get_system_id)-toolbox-$(get_system_version)"
|
2021-08-30 13:47:45 +00:00
|
|
|
|
create_default_container
|
|
|
|
|
|
2022-11-16 12:34:06 +00:00
|
|
|
|
# File descriptors 3 and 4 are reserved by Bats.
|
|
|
|
|
run -125 --separate-stderr $TOOLBOX run --preserve-fds 3 readlink /proc/self/fd/5
|
2021-08-30 13:47:45 +00:00
|
|
|
|
|
|
|
|
|
assert_failure
|
2022-11-16 11:49:31 +00:00
|
|
|
|
assert [ ${#lines[@]} -eq 0 ]
|
2022-11-16 10:58:10 +00:00
|
|
|
|
lines=("${stderr_lines[@]}")
|
2022-11-16 12:34:06 +00:00
|
|
|
|
assert_line --index 0 "Error: file descriptor 5 is not available - the preserve-fds option requires that file descriptors must be passed"
|
|
|
|
|
assert_line --index 1 "Error: failed to invoke 'podman exec' in container $default_container_name"
|
2022-11-16 10:58:10 +00:00
|
|
|
|
assert [ ${#stderr_lines[@]} -eq 2 ]
|
2021-08-30 13:47:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 15:28:07 +00:00
|
|
|
|
@test "run: Try /etc as a command" {
|
2021-08-30 13:47:45 +00:00
|
|
|
|
create_default_container
|
|
|
|
|
|
2022-11-16 12:19:21 +00:00
|
|
|
|
run -126 --separate-stderr $TOOLBOX run /etc
|
2021-08-30 13:47:45 +00:00
|
|
|
|
|
|
|
|
|
assert_failure
|
2022-11-16 11:49:31 +00:00
|
|
|
|
assert [ ${#lines[@]} -eq 0 ]
|
2022-11-16 10:58:10 +00:00
|
|
|
|
lines=("${stderr_lines[@]}")
|
cmd/run: Fix the name of the shell for running commands in containers
For the most part, this fixes a minor cosmetic issue for users, but it
does make the code less misleading to read for those hacking on Toolbx.
Further details below.
Commands are invoked inside a Toolbx from a helper shell invoked by
capsh(1). Unless capsh(1) is built with custom options, the helper
shell is always bash, not /bin/sh:
$ capsh --caps="" -- -c 'echo "$(readlink /proc/$$/exe)"'
/usr/bin/bash
( The possibility of capsh(1) using a different shell, other than Bash,
through a custom build option is ignored for the time being. If there
really are downstream distributors who do that, then this can be
addressed one way or another. )
Secondly, the name assigned to the embedded command string's '$0' should
only be the basename of the helper shell's binary, not the full path, to
match the usual behaviour:
$ bash -c 'exec foo'
bash: line 1: exec: foo: not found
With 'toolbox run' it was:
$ toolbox run foo
/bin/sh: line 1: exec: foo: not found
Error: command foo not found in container fedora-toolbox-36
https://github.com/containers/toolbox/pull/1147
2022-10-24 13:36:53 +00:00
|
|
|
|
assert_line --index 0 "bash: line 1: /etc: Is a directory"
|
|
|
|
|
assert_line --index 1 "bash: line 1: exec: /etc: cannot execute: Is a directory"
|
2021-08-30 13:47:45 +00:00
|
|
|
|
assert_line --index 2 "Error: failed to invoke command /etc in container $(get_latest_container_name)"
|
2022-11-16 10:58:10 +00:00
|
|
|
|
assert [ ${#stderr_lines[@]} -eq 3 ]
|
2021-08-30 13:47:45 +00:00
|
|
|
|
}
|
2022-11-14 14:15:10 +00:00
|
|
|
|
|
2022-11-16 15:28:07 +00:00
|
|
|
|
@test "run: Try a non-existent command" {
|
2022-11-16 12:34:06 +00:00
|
|
|
|
local cmd="non-existent-command"
|
|
|
|
|
|
2022-11-14 14:15:10 +00:00
|
|
|
|
create_default_container
|
|
|
|
|
|
2022-11-16 12:34:06 +00:00
|
|
|
|
run -127 --separate-stderr $TOOLBOX run $cmd
|
2022-11-14 14:15:10 +00:00
|
|
|
|
|
|
|
|
|
assert_failure
|
|
|
|
|
assert [ ${#lines[@]} -eq 0 ]
|
|
|
|
|
lines=("${stderr_lines[@]}")
|
2022-11-16 12:34:06 +00:00
|
|
|
|
assert_line --index 0 "bash: line 1: exec: $cmd: not found"
|
|
|
|
|
assert_line --index 1 "Error: command $cmd not found in container $(get_latest_container_name)"
|
2022-11-14 14:15:10 +00:00
|
|
|
|
assert [ ${#stderr_lines[@]} -eq 2 ]
|
|
|
|
|
}
|