fs: validate filesystem path argument properly. (#3470)

FS should fail for invalid paths like

 - file:///
 - ftp://
 - http://
This commit is contained in:
Harshavardhana
2016-12-17 13:43:26 -08:00
committed by GitHub
parent 1b2b16998f
commit 9c9f390350
2 changed files with 23 additions and 9 deletions

View File

@@ -17,6 +17,7 @@
package cmd
import (
"errors"
"flag"
"net/http"
"os"
@@ -182,15 +183,25 @@ func TestParseStorageEndpoints(t *testing.T) {
expectedErr error
}{
{"", "http://localhost/export", nil},
{"testhost", "http://localhost/export", errInvalidArgument},
{"", "http://localhost:9000/export", errInvalidArgument},
{
"testhost",
"http://localhost/export",
errors.New("Invalid Argument localhost, port mandatory when --address <host>:<port> is used"),
},
{
"",
"http://localhost:9000/export",
errors.New("Invalid Argument localhost:9000, port configurable using --address :<port>"),
},
{"testhost", "http://localhost:9000/export", nil},
}
for i, test := range testCases {
globalMinioHost = test.globalMinioHost
_, err := parseStorageEndpoints([]string{test.host})
if err != test.expectedErr {
t.Errorf("Test %d : got %v, expected %v", i+1, err, test.expectedErr)
if err != nil {
if err.Error() != test.expectedErr.Error() {
t.Errorf("Test %d : got %v, expected %v", i+1, err, test.expectedErr)
}
}
}
// Should be reset back to "" so that we don't affect other tests.