github.com/vmware/go-vcloud-director/v2@v2.24.0/util/tar_test.go (about) 1 /* 2 * Copyright 2018 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. 3 */ 4 5 package util 6 7 import ( 8 "testing" 9 ) 10 11 // Tests function sanitizedName providing bad paths and expects them be cleaned. 12 // Possible security issue https://github.com/vmware/pyvcloud/pull/268 13 func TestSanitizedName(t *testing.T) { 14 tables := []struct { 15 badPath string 16 goodPath string 17 }{ 18 {"\\..\\1.txt", "1.txt"}, 19 {"///foo/bar", "foo/bar"}, 20 {"C:/loo/bar2", "loo/bar2"}, 21 {"C:\\loo\\bar2", "loo\\bar2"}, 22 {"../../foo../../ba..r", "foo../ba..r"}, 23 {"../my.file", "my.file"}, 24 } 25 for _, table := range tables { 26 fixedPath := sanitizedName(table.badPath) 27 if fixedPath != table.goodPath { 28 t.Errorf("expected and fixedPath didn't match - %s : %s", table.goodPath, fixedPath) 29 } 30 } 31 }