From 38cb1a951d7dce7675fce88a71bfb765141319ed Mon Sep 17 00:00:00 2001 From: Daniel Smith Date: Wed, 24 May 2017 15:31:34 -0700 Subject: [PATCH] Implement dynamic admission webhooks Also fix a bug in rest client Kubernetes-commit: d6e1140b5d3c5c9d8696b7ccda0a5f92f36033df --- rest/request.go | 3 +++ rest/request_test.go | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/rest/request.go b/rest/request.go index b87ddaff..cfb4511b 100644 --- a/rest/request.go +++ b/rest/request.go @@ -1148,6 +1148,9 @@ func (r Result) Into(obj runtime.Object) error { if r.decoder == nil { return fmt.Errorf("serializer for %s doesn't exist", r.contentType) } + if len(r.body) == 0 { + return fmt.Errorf("0-length response") + } out, _, err := r.decoder.Decode(r.body, nil, obj) if err != nil || out == obj { diff --git a/rest/request_test.go b/rest/request_test.go index 15bf851d..cedac794 100755 --- a/rest/request_test.go +++ b/rest/request_test.go @@ -329,6 +329,16 @@ func TestResultIntoWithErrReturnsErr(t *testing.T) { } } +func TestResultIntoWithNoBodyReturnsErr(t *testing.T) { + res := Result{ + body: []byte{}, + decoder: scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), + } + if err := res.Into(&v1.Pod{}); err == nil || !strings.Contains(err.Error(), "0-length") { + t.Errorf("should have complained about 0 length body") + } +} + func TestURLTemplate(t *testing.T) { uri, _ := url.Parse("http://localhost") r := NewRequest(nil, "POST", uri, "", ContentConfig{GroupVersion: &schema.GroupVersion{Group: "test"}}, Serializers{}, nil, nil)