2016-06-22 03:44:24 -04:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
/*
|
2020-06-12 23:04:01 -04:00
|
|
|
* MinIO Cloud Storage, (C) 2016-2020 MinIO, Inc.
|
2016-06-22 03:44:24 -04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2016-08-18 19:23:42 -04:00
|
|
|
package cmd
|
2016-06-22 03:44:24 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2020-09-04 12:45:06 -04:00
|
|
|
"context"
|
2020-05-14 02:55:38 -04:00
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
2016-06-22 03:44:24 -04:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2016-06-22 18:30:15 -04:00
|
|
|
// Test if various paths work as expected when converted to UNC form
|
2016-06-22 03:44:24 -04:00
|
|
|
func TestUNCPaths(t *testing.T) {
|
|
|
|
var testCases = []struct {
|
|
|
|
objName string
|
|
|
|
pass bool
|
|
|
|
}{
|
|
|
|
{"/abcdef", true},
|
|
|
|
{"/a/b/c/d/e/f/g", true},
|
|
|
|
{string(bytes.Repeat([]byte("界"), 85)), true},
|
2016-06-22 18:30:15 -04:00
|
|
|
// Each path component must be <= 255 bytes long.
|
2020-05-14 02:55:38 -04:00
|
|
|
{string(bytes.Repeat([]byte("界"), 280)), false},
|
2016-10-26 20:14:05 -04:00
|
|
|
{`/p/q/r/s/t`, true},
|
2016-06-22 03:44:24 -04:00
|
|
|
}
|
2020-05-14 02:55:38 -04:00
|
|
|
dir, err := ioutil.TempDir("", "testdisk-")
|
2016-09-02 02:10:50 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-06-22 18:30:15 -04:00
|
|
|
// Cleanup on exit of test
|
2020-05-14 02:55:38 -04:00
|
|
|
defer os.RemoveAll(dir)
|
2016-06-22 18:30:15 -04:00
|
|
|
|
2020-05-14 02:55:38 -04:00
|
|
|
// Instantiate posix object to manage a disk
|
2016-06-22 03:44:24 -04:00
|
|
|
var fs StorageAPI
|
2020-08-25 13:55:15 -04:00
|
|
|
fs, err = newLocalXLStorage(dir)
|
2016-06-22 03:44:24 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-06-22 18:30:15 -04:00
|
|
|
// Create volume to use in conjunction with other StorageAPI's file API(s)
|
2020-09-04 12:45:06 -04:00
|
|
|
err = fs.MakeVol(context.Background(), "voldir")
|
2016-06-22 03:44:24 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-05-14 02:55:38 -04:00
|
|
|
for i, test := range testCases {
|
|
|
|
t.Run(fmt.Sprint(i), func(t *testing.T) {
|
2020-09-04 12:45:06 -04:00
|
|
|
err = fs.AppendFile(context.Background(), "voldir", test.objName, []byte("hello"))
|
2020-05-14 02:55:38 -04:00
|
|
|
if err != nil && test.pass {
|
|
|
|
t.Error(err)
|
|
|
|
} else if err == nil && !test.pass {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2020-10-28 12:18:35 -04:00
|
|
|
fs.Delete(context.Background(), "voldir", test.objName, false)
|
2020-05-14 02:55:38 -04:00
|
|
|
})
|
2016-06-22 03:44:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// Test to validate xlStorage behavior on windows when a non-final path component is a file.
|
2016-06-22 03:44:24 -04:00
|
|
|
func TestUNCPathENOTDIR(t *testing.T) {
|
2016-06-22 18:30:15 -04:00
|
|
|
// Instantiate posix object to manage a disk
|
2020-05-14 02:55:38 -04:00
|
|
|
dir, err := ioutil.TempDir("", "testdisk-")
|
2016-09-02 02:10:50 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-06-22 18:30:15 -04:00
|
|
|
// Cleanup on exit of test
|
2020-05-14 02:55:38 -04:00
|
|
|
defer os.RemoveAll(dir)
|
2016-10-27 06:30:52 -04:00
|
|
|
|
2016-06-22 03:44:24 -04:00
|
|
|
var fs StorageAPI
|
2020-08-25 13:55:15 -04:00
|
|
|
fs, err = newLocalXLStorage(dir)
|
2016-06-22 03:44:24 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-06-22 18:30:15 -04:00
|
|
|
// Create volume to use in conjunction with other StorageAPI's file API(s)
|
2020-09-04 12:45:06 -04:00
|
|
|
err = fs.MakeVol(context.Background(), "voldir")
|
2016-06-22 03:44:24 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
err = fs.AppendFile(context.Background(), "voldir", "/file", []byte("hello"))
|
2016-06-22 03:44:24 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-06-22 18:30:15 -04:00
|
|
|
// Try to create a file that includes a file in its path components.
|
|
|
|
// In *nix, this returns syscall.ENOTDIR while in windows we receive the following error.
|
2020-09-04 12:45:06 -04:00
|
|
|
err = fs.AppendFile(context.Background(), "voldir", "/file/obj1", []byte("hello"))
|
2016-07-03 14:17:08 -04:00
|
|
|
if err != errFileAccessDenied {
|
|
|
|
t.Errorf("expected: %s, got: %s", errFileAccessDenied, err)
|
2016-06-22 03:44:24 -04:00
|
|
|
}
|
|
|
|
}
|