Client should validate the incoming host value

Convert host:port and URLs passed to client.New() into the proper
values, and return an error if the value is invalid.  Change CLI
to return an error if -master is invalid.  Remove Client.rawRequest
which was not in use, and fix the involved tests. Add NewOrDie

Preserves the behavior of the client to not auth when a non-https
URL is passed (although in the future this should be corrected).
This commit is contained in:
Clayton Coleman
2014-08-28 09:56:38 -04:00
parent fa17697194
commit 818f357128
15 changed files with 203 additions and 172 deletions

View File

@@ -24,6 +24,7 @@ import (
verflag "github.com/GoogleCloudPlatform/kubernetes/pkg/version/flag"
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler"
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/factory"
"github.com/golang/glog"
)
var (
@@ -38,7 +39,10 @@ func main() {
verflag.PrintAndExitIfRequested()
// TODO: security story for plugins!
kubeClient := client.New("http://"+*master, nil)
kubeClient, err := client.New(*master, nil)
if err != nil {
glog.Fatalf("Invalid -master: %v", err)
}
configFactory := &factory.ConfigFactory{Client: kubeClient}
config := configFactory.Create()

View File

@@ -37,7 +37,8 @@ func TestCreate(t *testing.T) {
T: t,
}
server := httptest.NewServer(&handler)
factory := ConfigFactory{client.New(server.URL, nil)}
client := client.NewOrDie(server.URL, nil)
factory := ConfigFactory{client}
factory.Create()
}
@@ -87,7 +88,7 @@ func TestCreateWatches(t *testing.T) {
T: t,
}
server := httptest.NewServer(&handler)
factory.Client = client.New(server.URL, nil)
factory.Client = client.NewOrDie(server.URL, nil)
// This test merely tests that the correct request is made.
item.watchFactory(item.rv)
handler.ValidateRequest(t, item.location, "GET", nil)
@@ -114,7 +115,8 @@ func TestPollMinions(t *testing.T) {
T: t,
}
server := httptest.NewServer(&handler)
cf := ConfigFactory{client.New(server.URL, nil)}
client := client.NewOrDie(server.URL, nil)
cf := ConfigFactory{client}
ce, err := cf.pollMinions()
if err != nil {
@@ -137,7 +139,7 @@ func TestDefaultErrorFunc(t *testing.T) {
T: t,
}
server := httptest.NewServer(&handler)
factory := ConfigFactory{client.New(server.URL, nil)}
factory := ConfigFactory{client.NewOrDie(server.URL, nil)}
queue := cache.NewFIFO()
errFunc := factory.makeDefaultErrorFunc(queue)
@@ -242,10 +244,10 @@ func TestBind(t *testing.T) {
T: t,
}
server := httptest.NewServer(&handler)
b := binder{client.New(server.URL, nil)}
client := client.NewOrDie(server.URL, nil)
b := binder{client}
err := b.Bind(item.binding)
if err != nil {
if err := b.Bind(item.binding); err != nil {
t.Errorf("Unexpected error: %v", err)
continue
}