From c1ecdd1e3d951e54486adca28423877b541a300a Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Thu, 4 Dec 2014 16:56:55 -0800 Subject: [PATCH] remote: Test HTTP validation --- remote/http.go | 3 +++ remote/http_test.go | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/remote/http.go b/remote/http.go index 3953dbaec..e352cb8ad 100644 --- a/remote/http.go +++ b/remote/http.go @@ -34,6 +34,9 @@ func (c *HTTPRemoteClient) validateConfig(conf map[string]string) error { if err != nil { return fmt.Errorf("failed to parse url: %v", err) } + if url.Scheme != "http" && url.Scheme != "https" { + return fmt.Errorf("invalid url: %s", url) + } c.url = url return nil } diff --git a/remote/http_test.go b/remote/http_test.go index ef23d9097..e9a26c3c2 100644 --- a/remote/http_test.go +++ b/remote/http_test.go @@ -19,6 +19,23 @@ func TestHTTPRemote_Interface(t *testing.T) { } } +func TestHTTPRemote_Validate(t *testing.T) { + conf := map[string]string{} + if _, err := NewHTTPRemoteClient(conf); err == nil { + t.Fatalf("expect error") + } + + conf["url"] = "" + if _, err := NewHTTPRemoteClient(conf); err == nil { + t.Fatalf("expect error") + } + + conf["url"] = "http://cool.com" + if _, err := NewHTTPRemoteClient(conf); err != nil { + t.Fatalf("err: %v", err) + } +} + func TestHTTPRemote_GetState(t *testing.T) { type tcase struct { Code int