You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
runner-go/container/volume_test.go

44 lines
905 B
Go

// Copyright 2021 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by the Polyform License
// that can be found in the LICENSE file.
package container
import "testing"
func TestIsRestrictedVolume(t *testing.T) {
restrictedPaths := []string{
"/",
"../../../../../../../../../../../../var/run",
"/var/run",
"//var/run",
"/var/run/",
"/var/run/.",
"/var//run/",
"/var/run//",
"/var/run/test/..",
"/./var/run",
"/var/./run",
}
allowedPaths := []string{
"/drone",
"/drone/var/run",
"/development",
"/var/lib",
"/etc/ssh",
}
for _, path := range restrictedPaths {
if result := IsRestrictedVolume(path); result != true {
t.Errorf("Test failed for restricted path %q", path)
}
}
for _, path := range allowedPaths {
if result := IsRestrictedVolume(path); result != false {
t.Errorf("Test failed for allowed path %q", path)
}
}
}