| 
									
										
										
										
											2016-06-22 15:44:24 +08:00
										 |  |  | // +build windows
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							|  |  |  |  * Minio Cloud Storage, (C) 2016 Minio, Inc. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 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-19 07:23:42 +08:00
										 |  |  | package cmd | 
					
						
							| 
									
										
										
										
											2016-06-22 15:44:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"bytes" | 
					
						
							|  |  |  | 	"os" | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-23 06:30:15 +08:00
										 |  |  | // Test if various paths work as expected when converted to UNC form
 | 
					
						
							| 
									
										
										
										
											2016-06-22 15:44:24 +08: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-23 06:30:15 +08:00
										 |  |  | 		// Each path component must be <= 255 bytes long.
 | 
					
						
							| 
									
										
										
										
											2016-06-22 15:44:24 +08:00
										 |  |  | 		{string(bytes.Repeat([]byte("界"), 100)), false}, | 
					
						
							| 
									
										
										
										
											2016-10-27 08:14:05 +08:00
										 |  |  | 		{`/p/q/r/s/t`, true}, | 
					
						
							| 
									
										
										
										
											2016-06-22 15:44:24 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-06-23 06:30:15 +08:00
										 |  |  | 	// Instantiate posix object to manage a disk
 | 
					
						
							| 
									
										
										
										
											2016-06-22 15:44:24 +08:00
										 |  |  | 	var err error | 
					
						
							|  |  |  | 	err = os.Mkdir("c:\\testdisk", 0700) | 
					
						
							| 
									
										
										
										
											2016-09-02 14:10:50 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-06-23 06:30:15 +08:00
										 |  |  | 	// Cleanup on exit of test
 | 
					
						
							| 
									
										
										
										
											2016-06-22 15:44:24 +08:00
										 |  |  | 	defer os.RemoveAll("c:\\testdisk") | 
					
						
							| 
									
										
										
										
											2016-06-23 06:30:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-22 15:44:24 +08:00
										 |  |  | 	var fs StorageAPI | 
					
						
							| 
									
										
										
										
											2016-10-27 18:30:52 +08:00
										 |  |  | 	fs, err = newPosix(`c:\testdisk`) | 
					
						
							| 
									
										
										
										
											2016-06-22 15:44:24 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-23 06:30:15 +08:00
										 |  |  | 	// Create volume to use in conjunction with other StorageAPI's file API(s)
 | 
					
						
							| 
									
										
										
										
											2016-06-22 15:44:24 +08:00
										 |  |  | 	err = fs.MakeVol("voldir") | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for _, test := range testCases { | 
					
						
							|  |  |  | 		err = fs.AppendFile("voldir", test.objName, []byte("hello")) | 
					
						
							|  |  |  | 		if err != nil && test.pass { | 
					
						
							|  |  |  | 			t.Error(err) | 
					
						
							|  |  |  | 		} else if err == nil && !test.pass { | 
					
						
							|  |  |  | 			t.Error(err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		fs.DeleteFile("voldir", test.objName) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-29 07:02:02 +08:00
										 |  |  | // Test to validate posix behavior on windows when a non-final path component is a file.
 | 
					
						
							| 
									
										
										
										
											2016-06-22 15:44:24 +08:00
										 |  |  | func TestUNCPathENOTDIR(t *testing.T) { | 
					
						
							|  |  |  | 	var err error | 
					
						
							| 
									
										
										
										
											2016-06-23 06:30:15 +08:00
										 |  |  | 	// Instantiate posix object to manage a disk
 | 
					
						
							| 
									
										
										
										
											2016-06-22 15:44:24 +08:00
										 |  |  | 	err = os.Mkdir("c:\\testdisk", 0700) | 
					
						
							| 
									
										
										
										
											2016-09-02 14:10:50 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-06-23 06:30:15 +08:00
										 |  |  | 	// Cleanup on exit of test
 | 
					
						
							| 
									
										
										
										
											2016-06-22 15:44:24 +08:00
										 |  |  | 	defer os.RemoveAll("c:\\testdisk") | 
					
						
							| 
									
										
										
										
											2016-10-27 18:30:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-22 15:44:24 +08:00
										 |  |  | 	var fs StorageAPI | 
					
						
							| 
									
										
										
										
											2016-10-27 18:30:52 +08:00
										 |  |  | 	fs, err = newPosix(`c:\testdisk`) | 
					
						
							| 
									
										
										
										
											2016-06-22 15:44:24 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-23 06:30:15 +08:00
										 |  |  | 	// Create volume to use in conjunction with other StorageAPI's file API(s)
 | 
					
						
							| 
									
										
										
										
											2016-06-22 15:44:24 +08:00
										 |  |  | 	err = fs.MakeVol("voldir") | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = fs.AppendFile("voldir", "/file", []byte("hello")) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-23 06:30:15 +08: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.
 | 
					
						
							| 
									
										
										
										
											2016-06-22 15:44:24 +08:00
										 |  |  | 	err = fs.AppendFile("voldir", "/file/obj1", []byte("hello")) | 
					
						
							| 
									
										
										
										
											2016-07-04 02:17:08 +08:00
										 |  |  | 	if err != errFileAccessDenied { | 
					
						
							|  |  |  | 		t.Errorf("expected: %s, got: %s", errFileAccessDenied, err) | 
					
						
							| 
									
										
										
										
											2016-06-22 15:44:24 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } |