X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/bf29550db840c97cafffbe1e836750bef6c7942d..3ed0c9db20b2062bd22b524f66fdc1e03279ff88:/test/functional/node_controller_test.rb diff --git a/test/functional/node_controller_test.rb b/test/functional/node_controller_test.rb index 9e5621f8b..8d019bf79 100644 --- a/test/functional/node_controller_test.rb +++ b/test/functional/node_controller_test.rb @@ -1,12 +1,11 @@ require File.dirname(__FILE__) + '/../test_helper' -require 'node_controller' class NodeControllerTest < ActionController::TestCase api_fixtures def test_create # cannot read password from fixture as it is stored as MD5 digest - basic_authorization(users(:normal_user).email, "test"); + basic_authorization(users(:normal_user).email, "test") # create a node with random lat/lon lat = rand(100)-50 + rand @@ -30,6 +29,32 @@ class NodeControllerTest < ActionController::TestCase assert_equal true, checknode.visible, "saved node is not visible" end + def test_create_invalid_xml + # Initial setup + basic_authorization(users(:normal_user).email, "test") + # normal user has a changeset open, so we'll use that. + changeset = changesets(:normal_user_first_change) + lat = 3.434 + lon = 3.23 + + # test that the upload is rejected when no lat is supplied + # create a minimal xml file + content("") + put :create + # hope for success + assert_response :bad_request, "node upload did not return bad_request status" + assert_equal 'Cannot parse valid node from xml string . lat missing', @response.body + + # test that the upload is rejected when no lon is supplied + # create a minimal xml file + content("") + put :create + # hope for success + assert_response :bad_request, "node upload did not return bad_request status" + assert_equal 'Cannot parse valid node from xml string . lon missing', @response.body + + end + def test_read # check that a visible node is returned properly get :read, :id => current_nodes(:visible_node).id @@ -194,7 +219,8 @@ class NodeControllerTest < ActionController::TestCase content node_xml put :update, :id => current_nodes(:visible_node).id assert_response :bad_request, - "adding duplicate tags to a node should fail with 'bad request'" + "adding duplicate tags to a node should fail with 'bad request'" + assert_equal "Element node/#{current_nodes(:visible_node).id} has duplicate tags with key #{current_node_tags(:t1).k}.", @response.body end # test whether string injection is possible @@ -250,8 +276,7 @@ class NodeControllerTest < ActionController::TestCase ## # parse some xml def xml_parse(xml) - parser = XML::Parser.new - parser.string = xml + parser = XML::Parser.string(xml) parser.parse end end