mirror of
https://github.com/minio/minio.git
synced 2024-12-25 06:35:56 -05:00
fs: validate filesystem path argument properly. (#3470)
FS should fail for invalid paths like - file:/// - ftp:// - http://
This commit is contained in:
parent
1b2b16998f
commit
9c9f390350
@ -111,8 +111,7 @@ func parseStorageEndpoints(eps []string) (endpoints []*url.URL, err error) {
|
|||||||
// we return error as port is configurable only
|
// we return error as port is configurable only
|
||||||
// using "--address :port"
|
// using "--address :port"
|
||||||
if port != "" {
|
if port != "" {
|
||||||
errorIf(fmt.Errorf("Invalid argument %s, port configurable using --address :<port>", u.Host), "")
|
return nil, fmt.Errorf("Invalid Argument %s, port configurable using --address :<port>", u.Host)
|
||||||
return nil, errInvalidArgument
|
|
||||||
}
|
}
|
||||||
u.Host = net.JoinHostPort(u.Host, globalMinioPort)
|
u.Host = net.JoinHostPort(u.Host, globalMinioPort)
|
||||||
} else {
|
} else {
|
||||||
@ -120,8 +119,7 @@ func parseStorageEndpoints(eps []string) (endpoints []*url.URL, err error) {
|
|||||||
// i.e if "--address host:port" is specified
|
// i.e if "--address host:port" is specified
|
||||||
// port info in u.Host is mandatory else return error.
|
// port info in u.Host is mandatory else return error.
|
||||||
if port == "" {
|
if port == "" {
|
||||||
errorIf(fmt.Errorf("Invalid argument %s, port mandatory when --address <host>:<port> is used", u.Host), "")
|
return nil, fmt.Errorf("Invalid Argument %s, port mandatory when --address <host>:<port> is used", u.Host)
|
||||||
return nil, errInvalidArgument
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -326,7 +324,12 @@ func checkServerSyntax(c *cli.Context) {
|
|||||||
if len(endpoints) > 1 {
|
if len(endpoints) > 1 {
|
||||||
// Validate if we have sufficient disks for XL setup.
|
// Validate if we have sufficient disks for XL setup.
|
||||||
err = checkSufficientDisks(endpoints)
|
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) {
|
if !isDistributedSetup(endpoints) {
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -182,17 +183,27 @@ func TestParseStorageEndpoints(t *testing.T) {
|
|||||||
expectedErr error
|
expectedErr error
|
||||||
}{
|
}{
|
||||||
{"", "http://localhost/export", nil},
|
{"", "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},
|
{"testhost", "http://localhost:9000/export", nil},
|
||||||
}
|
}
|
||||||
for i, test := range testCases {
|
for i, test := range testCases {
|
||||||
globalMinioHost = test.globalMinioHost
|
globalMinioHost = test.globalMinioHost
|
||||||
_, err := parseStorageEndpoints([]string{test.host})
|
_, err := parseStorageEndpoints([]string{test.host})
|
||||||
if 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)
|
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.
|
// Should be reset back to "" so that we don't affect other tests.
|
||||||
globalMinioHost = ""
|
globalMinioHost = ""
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user