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

FS should fail for invalid paths like

 - file:///
 - ftp://
 - http://
master
Harshavardhana 8 years ago committed by GitHub
parent 1b2b16998f
commit 9c9f390350
  1. 13
      cmd/server-main.go
  2. 19
      cmd/server-main_test.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 :<port>", u.Host), "")
return nil, errInvalidArgument
return nil, fmt.Errorf("Invalid Argument %s, port configurable using --address :<port>", 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 <host>:<port> is used", u.Host), "")
return nil, errInvalidArgument
return nil, fmt.Errorf("Invalid Argument %s, port mandatory when --address <host>:<port> 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) {

@ -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.

Loading…
Cancel
Save