mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-30 17:22:33 +00:00
config: validate proxy path
Like shim, we should validate the proxy path if it is provided. Fixes: #1424 Signed-off-by: Peng Tao <bergwolf@hyper.sh>
This commit is contained in:
parent
4f712b0657
commit
dca7a6f98b
@ -357,12 +357,13 @@ func (h hypervisor) getInitrdAndImage() (initrd string, image string, err error)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p proxy) path() string {
|
func (p proxy) path() (string, error) {
|
||||||
if p.Path == "" {
|
path := p.Path
|
||||||
return defaultProxyPath
|
if path == "" {
|
||||||
|
path = defaultProxyPath
|
||||||
}
|
}
|
||||||
|
|
||||||
return p.Path
|
return ResolvePath(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p proxy) debug() bool {
|
func (p proxy) debug() bool {
|
||||||
@ -606,8 +607,13 @@ func updateRuntimeConfigProxy(configPath string, tomlConf tomlConfig, config *oc
|
|||||||
config.ProxyType = vc.KataProxyType
|
config.ProxyType = vc.KataProxyType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
path, err := proxy.path()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
config.ProxyConfig = vc.ProxyConfig{
|
config.ProxyConfig = vc.ProxyConfig{
|
||||||
Path: proxy.path(),
|
Path: path,
|
||||||
Debug: proxy.debug(),
|
Debug: proxy.debug(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1122,13 +1122,43 @@ func TestHypervisorDefaultsGuestHookPath(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestProxyDefaults(t *testing.T) {
|
func TestProxyDefaults(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
tmpdir, err := ioutil.TempDir(testDir, "")
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
|
testProxyPath := filepath.Join(tmpdir, "proxy")
|
||||||
|
testProxyLinkPath := filepath.Join(tmpdir, "proxy-link")
|
||||||
|
|
||||||
|
err = createEmptyFile(testProxyPath)
|
||||||
|
assert.NoError(err)
|
||||||
|
|
||||||
|
err = syscall.Symlink(testProxyPath, testProxyLinkPath)
|
||||||
|
assert.NoError(err)
|
||||||
|
|
||||||
|
savedProxyPath := defaultProxyPath
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
defaultProxyPath = savedProxyPath
|
||||||
|
}()
|
||||||
|
|
||||||
|
defaultProxyPath = testProxyPath
|
||||||
p := proxy{}
|
p := proxy{}
|
||||||
|
path, err := p.path()
|
||||||
|
assert.NoError(err)
|
||||||
|
assert.Equal(path, defaultProxyPath, "default proxy path wrong")
|
||||||
|
|
||||||
assert.Equal(t, p.path(), defaultProxyPath, "default proxy path wrong")
|
// test path resolution
|
||||||
|
defaultProxyPath = testProxyLinkPath
|
||||||
|
p = proxy{}
|
||||||
|
path, err = p.path()
|
||||||
|
assert.NoError(err)
|
||||||
|
assert.Equal(path, testProxyPath)
|
||||||
|
|
||||||
path := "/foo/bar/baz/proxy"
|
assert.False(p.debug())
|
||||||
p.Path = path
|
p.Debug = true
|
||||||
assert.Equal(t, p.path(), path, "custom proxy path wrong")
|
assert.True(p.debug())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestShimDefaults(t *testing.T) {
|
func TestShimDefaults(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user