diff --git a/src/pkg/utils/utils.go b/src/pkg/utils/utils.go index 358cb39f1..f5c77a788 100644 --- a/src/pkg/utils/utils.go +++ b/src/pkg/utils/utils.go @@ -250,10 +250,6 @@ func getDefaultImageForDistro(distro, release string) string { panic("distro not specified") } - if _, supportedDistro := supportedDistros[distro]; !supportedDistro { - distro = distroFallback - } - distroObj, supportedDistro := supportedDistros[distro] if !supportedDistro { panicMsg := fmt.Sprintf("failed to find %s in the list of supported distributions", distro) @@ -717,6 +713,10 @@ func ResolveContainerAndImageNames(container, distroCLI, imageCLI, releaseCLI st } } + if _, ok := supportedDistros[distro]; !ok { + return "", "", "", fmt.Errorf("distribution %s is unsupported", distro) + } + if distro != distroDefault && releaseCLI == "" && !viper.IsSet("general.release") { return "", "", "", fmt.Errorf("release not found for non-default distribution %s", distro) } diff --git a/test/system/101-create.bats b/test/system/101-create.bats index d52f02808..4abd869e2 100644 --- a/test/system/101-create.bats +++ b/test/system/101-create.bats @@ -71,6 +71,16 @@ teardown() { assert_output --regexp "Created[[:blank:]]+fedora-toolbox-32" } +@test "create: Try to create a container based on unsupported distribution" { + local distro="foo" + + run $TOOLBOX --assumeyes create --distro "$distro" + + assert_failure + assert_line --index 0 "Error: distribution $distro is unsupported" + assert [ ${#lines[@]} -eq 1 ] +} + @test "create: Try to create a container based on non-existent image" { run $TOOLBOX -y create -i foo.org/bar diff --git a/test/system/104-run.bats b/test/system/104-run.bats index 67c9b8a3b..628d0978f 100644 --- a/test/system/104-run.bats +++ b/test/system/104-run.bats @@ -48,6 +48,16 @@ teardown() { assert_line --index 2 "Run 'toolbox --help' for usage." } +@test "run: Try to run a command in a container based on unsupported distribution" { + local distro="foo" + + run $TOOLBOX --assumeyes run --distro "$distro" ls + + assert_failure + assert_line --index 0 "Error: distribution $distro is unsupported" + assert [ ${#lines[@]} -eq 1 ] +} + @test "run: Try to run a command in a container based on Fedora but with wrong version" { run $TOOLBOX run -d fedora -r foobar ls diff --git a/test/system/105-enter.bats b/test/system/105-enter.bats index d593ca0d1..3ecd4b951 100644 --- a/test/system/105-enter.bats +++ b/test/system/105-enter.bats @@ -54,6 +54,16 @@ teardown() { assert_line --index 2 "Run 'toolbox --help' for usage." } +@test "enter: Try to enter a container based on unsupported distribution" { + local distro="foo" + + run $TOOLBOX --assumeyes enter --distro "$distro" + + assert_failure + assert_line --index 0 "Error: distribution $distro is unsupported" + assert [ ${#lines[@]} -eq 1 ] +} + @test "enter: Try to enter a container based on Fedora but with wrong version" { run $TOOLBOX enter -d fedora -r foobar