mirror of
https://github.com/aljazceru/kata-containers.git
synced 2025-12-26 02:24:21 +01:00
By default virtcontainer auto-detects if the current process is running rootless or not, but this behavior can change from commandline with the --rootless option fixes #2417 Signed-off-by: Julio Montes <julio.montes@intel.com>
37 lines
585 B
Go
37 lines
585 B
Go
// Copyright (c) 2020 Intel Corporation
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package rootless
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/opencontainers/runc/libcontainer/system"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestIsRootless(t *testing.T) {
|
|
assert := assert.New(t)
|
|
isRootless = nil
|
|
|
|
var rootless bool
|
|
if os.Getuid() != 0 {
|
|
rootless = true
|
|
} else {
|
|
rootless = system.RunningInUserNS()
|
|
}
|
|
|
|
assert.Equal(rootless, isRootlessFunc())
|
|
|
|
SetRootless(true)
|
|
assert.True(isRootlessFunc())
|
|
|
|
SetRootless(false)
|
|
assert.False(isRootlessFunc())
|
|
|
|
isRootless = nil
|
|
}
|