Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 5 additions & 3 deletions tavern/internal/c2/api_report_task_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ func (srv *Server) ReportTaskOutput(ctx context.Context, req *c2pb.ReportTaskOut
timestamp := req.Output.ExecFinishedAt.AsTime()
execFinishedAt = &timestamp
}
if req.Output.Error != nil {
taskErr = &req.Output.Error.Msg
}

// Load Task
t, err := srv.graph.Task.Get(ctx, int(req.Output.Id))
Expand All @@ -44,6 +41,11 @@ func (srv *Server) ReportTaskOutput(ctx context.Context, req *c2pb.ReportTaskOut
return nil, status.Errorf(codes.Internal, "failed to submit task result (id=%d): %v", req.Output.Id, err)
}

if req.Output.Error != nil {
e := fmt.Sprintf("%s%s", t.Error, req.Output.Error.Msg)
taskErr = &e
}

// Update Task
_, err = t.Update().
SetNillableExecStartedAt(execStartedAt).
Expand Down
25 changes: 25 additions & 0 deletions tavern/internal/c2/api_report_task_output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func TestReportTaskOutput(t *testing.T) {
wantResp *c2pb.ReportTaskOutputResponse
wantCode codes.Code
wantOutput string
wantError string
wantExecStartedAt *timestamppb.Timestamp
wantExecFinishedAt *timestamppb.Timestamp
}{
Expand All @@ -56,17 +57,39 @@ func TestReportTaskOutput(t *testing.T) {
wantOutput: "TestOutput",
wantExecStartedAt: now,
},
{
name: "First_error",
req: &c2pb.ReportTaskOutputRequest{
Output: &c2pb.TaskOutput{
Id: int64(existingTasks[0].ID),
Output: "",
Error: &c2pb.TaskError{
Msg: "hello error!",
},
ExecStartedAt: now,
},
},
wantResp: &c2pb.ReportTaskOutputResponse{},
wantCode: codes.OK,
wantOutput: "TestOutput",
wantError: "hello error!",
wantExecStartedAt: now,
},
{
name: "Append_Output",
req: &c2pb.ReportTaskOutputRequest{
Output: &c2pb.TaskOutput{
Id: int64(existingTasks[0].ID),
Output: "_AppendedOutput",
Error: &c2pb.TaskError{
Msg: "_AppendEror",
},
},
},
wantResp: &c2pb.ReportTaskOutputResponse{},
wantCode: codes.OK,
wantOutput: "TestOutput_AppendedOutput",
wantError: "hello error!_AppendEror",
wantExecStartedAt: now,
},
{
Expand All @@ -80,6 +103,7 @@ func TestReportTaskOutput(t *testing.T) {
wantResp: &c2pb.ReportTaskOutputResponse{},
wantCode: codes.OK,
wantOutput: "TestOutput_AppendedOutput",
wantError: "hello error!_AppendEror",
wantExecStartedAt: now,
wantExecFinishedAt: finishedAt,
},
Expand Down Expand Up @@ -128,6 +152,7 @@ func TestReportTaskOutput(t *testing.T) {

// Task Assertions
assert.Equal(t, tc.wantOutput, testTask.Output)
assert.Equal(t, tc.wantError, testTask.Error)
})
}

Expand Down
Loading