mirror of
https://github.com/siderolabs/talos.git
synced 2025-08-18 04:27:06 +02:00
Using `SafePath` function from `runc` (but had to create local copy as `runc` doesn't build on OS X). Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
package safepath_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/talos-systems/talos/pkg/safepath"
|
|
)
|
|
|
|
func TestCleanPath(t *testing.T) {
|
|
path := safepath.CleanPath("")
|
|
if path != "" {
|
|
t.Errorf("expected to receive empty string and received %s", path)
|
|
}
|
|
|
|
path = safepath.CleanPath("rootfs")
|
|
if path != "rootfs" {
|
|
t.Errorf("expected to receive 'rootfs' and received %s", path)
|
|
}
|
|
|
|
path = safepath.CleanPath("../../../var")
|
|
if path != "var" {
|
|
t.Errorf("expected to receive 'var' and received %s", path)
|
|
}
|
|
|
|
path = safepath.CleanPath("/../../../var")
|
|
if path != "/var" {
|
|
t.Errorf("expected to receive '/var' and received %s", path)
|
|
}
|
|
|
|
path = safepath.CleanPath("/foo/bar/")
|
|
if path != "/foo/bar" {
|
|
t.Errorf("expected to receive '/foo/bar' and received %s", path)
|
|
}
|
|
|
|
path = safepath.CleanPath("/foo/bar/../")
|
|
if path != "/foo" {
|
|
t.Errorf("expected to receive '/foo' and received %s", path)
|
|
}
|
|
}
|