Skip to content

Commit

Permalink
Merge pull request #2239 from bgeuken/api_test_
Browse files Browse the repository at this point in the history
Api tests for orderkiwirepos
  • Loading branch information
bgeuken committed Oct 19, 2016
2 parents 279d465 + a3f52f6 commit 02a2373
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 2 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions src/api/spec/controllers/source_controller_spec.rb
@@ -0,0 +1,27 @@
require 'rails_helper'

RSpec.describe SourceController, vcr: true do
describe "POST #global_command_orderkiwirepos" do
it "is accessible anonymously and forwards backend errors" do
post :global_command_orderkiwirepos, params: { cmd: "orderkiwirepos" }
expect(response).to have_http_status(:bad_request)
expect(Xmlhash.parse(response.body)["summary"]).to eq("read_file: no content attached")
end
end

describe "POST #global_command_branch" do
it "is not accessible anonymously" do
post :global_command_branch, params: { cmd: "branch" }
expect(flash[:error]).to eq("anonymous_user(Anonymous user is not allowed here - please login): ")
expect(response).to redirect_to(root_path)
end
end

describe "POST #global_command_createmaintenanceincident" do
it "is not accessible anonymously" do
post :global_command_createmaintenanceincident, params: { cmd: "createmaintenanceincident" }
expect(flash[:error]).to eq("anonymous_user(Anonymous user is not allowed here - please login): ")
expect(response).to redirect_to(root_path)
end
end
end
20 changes: 20 additions & 0 deletions src/api/spec/routing/api_matcher_spec.rb
Expand Up @@ -27,4 +27,24 @@
file: 'file'
)
end

it 'routes requests to global_command_* correctly' do
expect(post('/source?cmd=orderkiwirepos')).to route_to(
controller: 'source',
action: 'global_command_orderkiwirepos',
cmd: 'orderkiwirepos'
)

expect(post('/source?cmd=branch')).to route_to(
controller: 'source',
action: 'global_command_branch',
cmd: 'branch'
)

expect(post('/source?cmd=createmaintenanceincident')).to route_to(
controller: 'source',
action: 'global_command_createmaintenanceincident',
cmd: 'createmaintenanceincident'
)
end
end
4 changes: 2 additions & 2 deletions src/api/test/functional/source_controller_test.rb
Expand Up @@ -60,15 +60,15 @@ def test_get_packagelist
:children => { :count => 2, :only => { :tag => 'entry' } }
end

def test_post_orderkiwirepos
def test_post_orderkiwirepos # spec/controllers/source_controller_spec.rb
login_tom
post '/source?cmd=orderkiwirepos'
assert_response 400
assert_xml_tag tag: 'status', attributes: { code: "400", origin: "backend" }
# api handed it over to backend, enough tested here
end

def test_anonymous_access_for_global_commands
def test_anonymous_access_for_global_commands # spec/controllers/source_controller_spec.rb
post '/source?cmd=orderkiwirepos'
# anonymous access allowed here, just forwarding the request to backend fails
assert_response 400
Expand Down

0 comments on commit 02a2373

Please sign in to comment.