Skip to content

Commit 9d6d789

Browse files
committed
fixed unmarshall won't work for incorrect json object
1 parent 0cae1ca commit 9d6d789

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

internal/argocd-plugin/plugin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func ArgocdPlugin(kubeClient kubernetes.Interface, namespace string) func(w http
3636
}
3737

3838
args := executor.ExecuteTemplateArgs{}
39-
if err := json.Unmarshal(body, &args); err != nil {
39+
if err := json.Unmarshal(body, &args); err != nil || args.Workflow == nil || args.Template == nil {
4040
log.Print(ErrMarshallingBody)
4141
http.Error(w, ErrMarshallingBody.Error(), http.StatusBadRequest)
4242
return

internal/argocd-plugin/plugin_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func TestArgocdPlugin(t *testing.T) {
6363
},
6464
{
6565
name: "fail marshalling body",
66-
body: bytes.NewReader([]byte(`"lol": "test"`)),
66+
body: bytes.NewReader([]byte(`{"lol": "test"}`)),
6767
headers: headerContentJson,
6868
want: ErrMarshallingBody.Error(),
6969
status: http.StatusBadRequest,

0 commit comments

Comments
 (0)