github.com/drone/runner-go@v1.12.0/container/volume_test.go (about) 1 // Copyright 2021 Drone.IO Inc. All rights reserved. 2 // Use of this source code is governed by the Polyform License 3 // that can be found in the LICENSE file. 4 5 package container 6 7 import "testing" 8 9 func TestIsRestrictedVolume(t *testing.T) { 10 restrictedPaths := []string{ 11 "/", 12 "../../../../../../../../../../../../var/run", 13 "/var/run", 14 "//var/run", 15 "/var/run/", 16 "/var/run/.", 17 "/var//run/", 18 "/var/run//", 19 "/var/run/test/..", 20 "/./var/run", 21 "/var/./run", 22 } 23 24 allowedPaths := []string{ 25 "/drone", 26 "/drone/var/run", 27 "/development", 28 "/var/lib", 29 "/etc/ssh", 30 } 31 32 for _, path := range restrictedPaths { 33 if result := IsRestrictedVolume(path); result != true { 34 t.Errorf("Test failed for restricted path %q", path) 35 } 36 } 37 38 for _, path := range allowedPaths { 39 if result := IsRestrictedVolume(path); result != false { 40 t.Errorf("Test failed for allowed path %q", path) 41 } 42 } 43 }