Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): Correct webhook event payload marshalling. Fixes #4572 #4594

Merged
merged 6 commits into from
Dec 2, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fattened up the test suite
Signed-off-by: Alex Collins <[email protected]>
  • Loading branch information
alexec committed Nov 24, 2020
commit f981156926a9320bef39948cefaba198de7d79e6
55 changes: 54 additions & 1 deletion server/event/dispatch/operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ func TestNewOperation(t *testing.T) {
&wfv1.WorkflowTemplate{
ObjectMeta: metav1.ObjectMeta{Name: "my-wft-2", Namespace: "my-ns", Labels: map[string]string{common.LabelKeyControllerInstanceID: "my-instanceid"}},
},
&wfv1.WorkflowTemplate{
ObjectMeta: metav1.ObjectMeta{Name: "my-wft-3", Namespace: "my-ns"},
},
)
ctx := context.WithValue(context.WithValue(context.Background(), auth.WfKey, client), auth.ClaimsKey, &types.Claims{Claims: jwt.Claims{Subject: "my-sub"}})
recorder := record.NewFakeRecorder(1)
recorder := record.NewFakeRecorder(6)

// act
operation, err := NewOperation(ctx, instanceid.NewService("my-instanceid"), recorder, []wfv1.WorkflowEventBinding{
Expand Down Expand Up @@ -98,6 +101,51 @@ func TestNewOperation(t *testing.T) {
},
},
},
// test a binding that errors due to missing workflow template
{
ObjectMeta: metav1.ObjectMeta{Name: "my-wfeb-4", Namespace: "my-ns"},
Spec: wfv1.WorkflowEventBindingSpec{
Event: wfv1.Event{Selector: "true"},
Submit: &wfv1.Submit{
WorkflowTemplateRef: wfv1.WorkflowTemplateRef{Name: "not-found"},
},
},
},
// test a binding that errors match due to wrong instance ID on template
{
ObjectMeta: metav1.ObjectMeta{Name: "my-wfeb-5", Namespace: "my-ns"},
Spec: wfv1.WorkflowEventBindingSpec{
Event: wfv1.Event{Selector: "true"},
Submit: &wfv1.Submit{
WorkflowTemplateRef: wfv1.WorkflowTemplateRef{Name: "my-wft-3"},
},
},
},
// test a binding with an invalid event selector
{
ObjectMeta: metav1.ObjectMeta{Name: "my-wfeb-6", Namespace: "my-ns"},
Spec: wfv1.WorkflowEventBindingSpec{
Event: wfv1.Event{Selector: "garbage!!!!!!"},
},
},
// test a binding with a non-bool event selector
{
ObjectMeta: metav1.ObjectMeta{Name: "my-wfeb-6", Namespace: "my-ns"},
Spec: wfv1.WorkflowEventBindingSpec{
Event: wfv1.Event{Selector: `"garbage"`},
},
},
// test a binding with an invalid param expression
{
ObjectMeta: metav1.ObjectMeta{Name: "my-wfeb-7", Namespace: "my-ns"},
Spec: wfv1.WorkflowEventBindingSpec{
Event: wfv1.Event{Selector: "true"},
Submit: &wfv1.Submit{
WorkflowTemplateRef: wfv1.WorkflowTemplateRef{Name: "my-wft"},
Arguments: &wfv1.Arguments{Parameters: []wfv1.Parameter{{Name: "my-param", ValueFrom: &wfv1.ValueFrom{Event: "rubbish!!!"}}}},
},
},
},
}, "my-ns", "my-discriminator", &wfv1.Item{Value: json.RawMessage(`{"foo": {"bar": "baz"}}`)})
assert.NoError(t, err)
operation.Dispatch()
Expand All @@ -114,6 +162,11 @@ func TestNewOperation(t *testing.T) {
}
}
assert.Equal(t, "Warning WorkflowEventBindingError failed to dispatch event: failed to evaluate workflow template expression: unexpected token EOF (1:1)", <-recorder.Events)
assert.Equal(t, "Warning WorkflowEventBindingError failed to dispatch event: failed to get workflow template: workflowtemplates.argoproj.io \"not-found\" not found", <-recorder.Events)
assert.Equal(t, "Warning WorkflowEventBindingError failed to dispatch event: failed to validate workflow template instanceid: 'my-wft-3' is not managed by the current Argo Server", <-recorder.Events)
assert.Equal(t, "Warning WorkflowEventBindingError failed to dispatch event: failed to evaluate workflow template expression: unexpected token Operator(\"!\") (1:8)\n | garbage!!!!!!\n | .......^", <-recorder.Events)
assert.Equal(t, "Warning WorkflowEventBindingError failed to dispatch event: malformed workflow template expression: did not evaluate to boolean", <-recorder.Events)
assert.Equal(t, "Warning WorkflowEventBindingError failed to dispatch event: failed to evaluate workflow template parameter \"my-param\" expression: unexpected token Operator(\"!\") (1:8)\n | rubbish!!!\n | .......^", <-recorder.Events)
}

func Test_expressionEnvironment(t *testing.T) {
Expand Down