Skip to content

Commit

Permalink
Add well-formed xml check for workflows controller
Browse files Browse the repository at this point in the history
We check for empty and well-formed xml, providing a better error
message output.

Co-authored-by: David Kang <dkang@suse.com>
  • Loading branch information
eduardoj and David Kang committed Nov 22, 2019
1 parent dfe65b9 commit c478364
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
9 changes: 3 additions & 6 deletions src/api/app/controllers/staging/workflows_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ class Staging::WorkflowsController < Staging::StagingController
before_action :set_project
before_action :check_staging_workflow, only: :create
before_action :set_staging_workflow, only: [:update, :destroy]
before_action :set_xml_hash, only: [:create, :update]
after_action :verify_authorized

def create
staging_workflow = @project.build_staging
authorize staging_workflow

staging_workflow.managers_group = Group.find_by!(title: xml_hash['managers'])
staging_workflow.managers_group = Group.find_by!(title: @parsed_xml[:managers])

if staging_workflow.save
render_ok
Expand All @@ -36,7 +37,7 @@ def destroy
def update
authorize @staging_workflow

@staging_workflow.managers_group = Group.find_by!(title: xml_hash['managers'])
@staging_workflow.managers_group = Group.find_by!(title: @parsed_xml[:managers])

if @staging_workflow.save
render_ok
Expand All @@ -60,8 +61,4 @@ def check_staging_workflow
message: "Project #{@project} already has an associated Staging Workflow with id: #{@project.staging.id}"
)
end

def xml_hash
Xmlhash.parse(request.body.read) || {}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
post :create, params: { staging_workflow_project: project, format: :xml }
end

it { expect(response).to have_http_status(:not_found) }
it { expect(response).to have_http_status(:bad_request) }
it { expect(project.staging).to be_nil }
end
end
Expand Down

0 comments on commit c478364

Please sign in to comment.