From 9c9f390350cee8a526a908611e54511f8b048037 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sat, 17 Dec 2016 13:43:26 -0800 Subject: [PATCH] fs: validate filesystem path argument properly. (#3470) FS should fail for invalid paths like - file:/// - ftp:// - http:// --- cmd/server-main.go | 13 ++++++++----- cmd/server-main_test.go | 19 +++++++++++++++---- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/cmd/server-main.go b/cmd/server-main.go index 2e8ca8c1e..c020e240b 100644 --- a/cmd/server-main.go +++ b/cmd/server-main.go @@ -111,8 +111,7 @@ func parseStorageEndpoints(eps []string) (endpoints []*url.URL, err error) { // we return error as port is configurable only // using "--address :port" if port != "" { - errorIf(fmt.Errorf("Invalid argument %s, port configurable using --address :", u.Host), "") - return nil, errInvalidArgument + return nil, fmt.Errorf("Invalid Argument %s, port configurable using --address :", u.Host) } u.Host = net.JoinHostPort(u.Host, globalMinioPort) } else { @@ -120,8 +119,7 @@ func parseStorageEndpoints(eps []string) (endpoints []*url.URL, err error) { // i.e if "--address host:port" is specified // port info in u.Host is mandatory else return error. if port == "" { - errorIf(fmt.Errorf("Invalid argument %s, port mandatory when --address : is used", u.Host), "") - return nil, errInvalidArgument + return nil, fmt.Errorf("Invalid Argument %s, port mandatory when --address : is used", u.Host) } } } @@ -326,7 +324,12 @@ func checkServerSyntax(c *cli.Context) { if len(endpoints) > 1 { // Validate if we have sufficient disks for XL setup. err = checkSufficientDisks(endpoints) - fatalIf(err, "Storage endpoint error.") + fatalIf(err, "Invalid number of disks supplied.") + } else { + // Validate if we have invalid disk for FS setup. + if endpoints[0].Host != "" && endpoints[0].Scheme != "" { + fatalIf(errInvalidArgument, "%s, FS setup expects a filesystem path", endpoints[0]) + } } if !isDistributedSetup(endpoints) { diff --git a/cmd/server-main_test.go b/cmd/server-main_test.go index d990764b2..d666d31c9 100644 --- a/cmd/server-main_test.go +++ b/cmd/server-main_test.go @@ -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 : is used"), + }, + { + "", + "http://localhost:9000/export", + errors.New("Invalid Argument localhost:9000, port configurable using --address :"), + }, {"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.