storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/cmd/xl-storage_windows_test.go (about) 1 //go:build windows 2 // +build windows 3 4 /* 5 * MinIO Cloud Storage, (C) 2016-2020 MinIO, Inc. 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 */ 19 20 package cmd 21 22 import ( 23 "bytes" 24 "context" 25 "fmt" 26 "io/ioutil" 27 "os" 28 "testing" 29 ) 30 31 // Test if various paths work as expected when converted to UNC form 32 func TestUNCPaths(t *testing.T) { 33 var testCases = []struct { 34 objName string 35 pass bool 36 }{ 37 {"/abcdef", true}, 38 {"/a/b/c/d/e/f/g", true}, 39 {string(bytes.Repeat([]byte("界"), 85)), true}, 40 // Each path component must be <= 255 bytes long. 41 {string(bytes.Repeat([]byte("界"), 280)), false}, 42 {`/p/q/r/s/t`, true}, 43 } 44 dir, err := ioutil.TempDir("", "testdisk-") 45 if err != nil { 46 t.Fatal(err) 47 } 48 // Cleanup on exit of test 49 defer os.RemoveAll(dir) 50 51 // Instantiate posix object to manage a disk 52 var fs StorageAPI 53 fs, err = newLocalXLStorage(dir) 54 if err != nil { 55 t.Fatal(err) 56 } 57 58 // Create volume to use in conjunction with other StorageAPI's file API(s) 59 err = fs.MakeVol(context.Background(), "voldir") 60 if err != nil { 61 t.Fatal(err) 62 } 63 64 for i, test := range testCases { 65 t.Run(fmt.Sprint(i), func(t *testing.T) { 66 err = fs.AppendFile(context.Background(), "voldir", test.objName, []byte("hello")) 67 if err != nil && test.pass { 68 t.Error(err) 69 } else if err == nil && !test.pass { 70 t.Error(err) 71 } 72 fs.Delete(context.Background(), "voldir", test.objName, false) 73 }) 74 } 75 } 76 77 // Test to validate xlStorage behavior on windows when a non-final path component is a file. 78 func TestUNCPathENOTDIR(t *testing.T) { 79 // Instantiate posix object to manage a disk 80 dir, err := ioutil.TempDir("", "testdisk-") 81 if err != nil { 82 t.Fatal(err) 83 } 84 // Cleanup on exit of test 85 defer os.RemoveAll(dir) 86 87 var fs StorageAPI 88 fs, err = newLocalXLStorage(dir) 89 if err != nil { 90 t.Fatal(err) 91 } 92 93 // Create volume to use in conjunction with other StorageAPI's file API(s) 94 err = fs.MakeVol(context.Background(), "voldir") 95 if err != nil { 96 t.Fatal(err) 97 } 98 99 err = fs.AppendFile(context.Background(), "voldir", "/file", []byte("hello")) 100 if err != nil { 101 t.Fatal(err) 102 } 103 104 // Try to create a file that includes a file in its path components. 105 // In *nix, this returns syscall.ENOTDIR while in windows we receive the following error. 106 err = fs.AppendFile(context.Background(), "voldir", "/file/obj1", []byte("hello")) 107 if err != errFileAccessDenied { 108 t.Errorf("expected: %s, got: %s", errFileAccessDenied, err) 109 } 110 }