X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/d8a2794c2c0be24cf78945cdbf4af57c4468499c..5285f69a8aa41eff217734f1d4051b7cc75428e5:/test/controllers/api/changesets_controller_test.rb?ds=sidebyside diff --git a/test/controllers/api/changesets_controller_test.rb b/test/controllers/api/changesets_controller_test.rb index d2e8db7c4..cfb424169 100644 --- a/test/controllers/api/changesets_controller_test.rb +++ b/test/controllers/api/changesets_controller_test.rb @@ -396,7 +396,7 @@ module Api # check that a changeset that doesn't exist returns an appropriate message def test_show_not_found [0, -32, 233455644, "afg", "213"].each do |id| - get changeset_show_path(:id => id) + get changeset_show_path(id) assert_response :not_found, "should get a not found" rescue ActionController::UrlGenerationError => e assert_match(/No route matches/, e.to_s) @@ -424,7 +424,7 @@ module Api auth_header = basic_authorization_header user.email, "test" cs_id = changeset.id - put changeset_close_path(:id => cs_id), :headers => auth_header + put changeset_close_path(cs_id), :headers => auth_header assert_response :success # test that it really is closed now @@ -470,7 +470,7 @@ module Api # First try to do it with no auth cs_ids.each do |id| - put changeset_close_path(:id => id) + put changeset_close_path(id) assert_response :unauthorized, "Shouldn't be able close the non-existant changeset #{id}, when not authorized" rescue ActionController::UrlGenerationError => e assert_match(/No route matches/, e.to_s) @@ -479,7 +479,7 @@ module Api # Now try with auth auth_header = basic_authorization_header create(:user).email, "test" cs_ids.each do |id| - put changeset_close_path(:id => id), :headers => auth_header + put changeset_close_path(id), :headers => auth_header assert_response :not_found, "The changeset #{id} doesn't exist, so can't be closed" rescue ActionController::UrlGenerationError => e assert_match(/No route matches/, e.to_s) @@ -749,7 +749,11 @@ module Api end def test_upload_large_changeset - auth_header = basic_authorization_header create(:user).email, "test" + user = create(:user) + auth_header = basic_authorization_header user.email, "test" + + # create an old changeset to ensure we have the maximum rate limit + create(:changeset, :user => user, :created_at => Time.now.utc - 28.days) # create a changeset put changeset_create_path, :params => "", :headers => auth_header @@ -784,7 +788,7 @@ module Api # upload it, which used to cause an error like "PGError: ERROR: # integer out of range" (bug #2152). but shouldn't any more. - post changeset_upload_path(:id => changeset_id), :params => diff, :headers => auth_header + post changeset_upload_path(changeset_id), :params => diff, :headers => auth_header assert_response :success, "can't upload a spatially-large diff to changeset: #{@response.body}" @@ -1048,14 +1052,14 @@ module Api diff = <<~CHANGESET - - - - - - - - + + + + + + + + CHANGESET @@ -1329,9 +1333,9 @@ module Api diff = <<~CHANGESET - - - + + + @@ -1352,9 +1356,9 @@ module Api diff = <<~CHANGESET - - - + + + @@ -1384,9 +1388,9 @@ module Api diff = <<~CHANGESET - - - + + + @@ -1407,9 +1411,9 @@ module Api diff = <<~CHANGESET - - - + + + @@ -1453,7 +1457,7 @@ module Api diff.root << modify # upload it - post changeset_upload_path(:id => changeset_id), :params => diff.to_s, :headers => auth_header + post changeset_upload_path(changeset_id), :params => diff.to_s, :headers => auth_header assert_response :success, "diff should have uploaded OK" @@ -1478,30 +1482,30 @@ module Api changeset_id = @response.body.to_i old_way = create(:way) - create(:way_node, :way => old_way, :node => create(:node, :lat => 1, :lon => 1)) + create(:way_node, :way => old_way, :node => create(:node, :lat => 0.1, :lon => 0.1)) diff = XML::Document.new diff.root = XML::Node.new "osmChange" modify = XML::Node.new "modify" xml_old_way = xml_node_for_way(old_way) nd_ref = XML::Node.new "nd" - nd_ref["ref"] = create(:node, :lat => 3, :lon => 3).id.to_s + nd_ref["ref"] = create(:node, :lat => 0.3, :lon => 0.3).id.to_s xml_old_way << nd_ref xml_old_way["changeset"] = changeset_id.to_s modify << xml_old_way diff.root << modify # upload it - post changeset_upload_path(:id => changeset_id), :params => diff.to_s, :headers => auth_header + post changeset_upload_path(changeset_id), :params => diff.to_s, :headers => auth_header assert_response :success, "diff should have uploaded OK" # check the bbox changeset = Changeset.find(changeset_id) - assert_equal 1 * GeoRecord::SCALE, changeset.min_lon, "min_lon should be 1 degree" - assert_equal 3 * GeoRecord::SCALE, changeset.max_lon, "max_lon should be 3 degrees" - assert_equal 1 * GeoRecord::SCALE, changeset.min_lat, "min_lat should be 1 degree" - assert_equal 3 * GeoRecord::SCALE, changeset.max_lat, "max_lat should be 3 degrees" + assert_equal 0.1 * GeoRecord::SCALE, changeset.min_lon, "min_lon should be 0.1 degree" + assert_equal 0.3 * GeoRecord::SCALE, changeset.max_lon, "max_lon should be 0.3 degrees" + assert_equal 0.1 * GeoRecord::SCALE, changeset.min_lat, "min_lat should be 0.1 degree" + assert_equal 0.3 * GeoRecord::SCALE, changeset.max_lat, "max_lat should be 0.3 degrees" end ## @@ -1798,6 +1802,71 @@ module Api assert_response :too_many_requests, "upload did not hit rate limit" end + ## + # test initial size limit + def test_upload_initial_size_limit + # create a user + user = create(:user) + + # create a changeset that puts us near the initial size limit + changeset = create(:changeset, :user => user, + :min_lat => (-0.5 * GeoRecord::SCALE).round, :min_lon => (0.5 * GeoRecord::SCALE).round, + :max_lat => (0.5 * GeoRecord::SCALE).round, :max_lon => (2.5 * GeoRecord::SCALE).round) + + # create authentication header + auth_header = basic_authorization_header user.email, "test" + + # simple diff to create a node + diff = <<~CHANGESET + + + + + + + + + CHANGESET + + # upload it + post changeset_upload_path(changeset), :params => diff, :headers => auth_header + assert_response :payload_too_large, "upload did not hit size limit" + end + + ## + # test size limit after one week + def test_upload_week_size_limit + # create a user + user = create(:user) + + # create a changeset to establish our initial edit time + create(:changeset, :user => user, :created_at => Time.now.utc - 7.days) + + # create a changeset that puts us near the initial size limit + changeset = create(:changeset, :user => user, + :min_lat => (-0.5 * GeoRecord::SCALE).round, :min_lon => (0.5 * GeoRecord::SCALE).round, + :max_lat => (0.5 * GeoRecord::SCALE).round, :max_lon => (2.5 * GeoRecord::SCALE).round) + + # create authentication header + auth_header = basic_authorization_header user.email, "test" + + # simple diff to create a node way and relation using placeholders + diff = <<~CHANGESET + + + + + + + + + CHANGESET + + # upload it + post changeset_upload_path(changeset), :params => diff, :headers => auth_header + assert_response :payload_too_large, "upload did not hit size limit" + end + ## # when we make some simple changes we get the same changes back from the # diff download. @@ -1829,24 +1898,24 @@ module Api diff = <<~CHANGESET - - - - - - - - + + + + + + + + CHANGESET # upload it - post changeset_upload_path(:id => changeset_id), :params => diff, :headers => auth_header + post changeset_upload_path(changeset_id), :params => diff, :headers => auth_header assert_response :success, "can't upload multiple versions of an element in a diff: #{@response.body}" - get changeset_download_path(:id => changeset_id) + get changeset_download_path(changeset_id) assert_response :success assert_select "osmChange", 1 @@ -1900,11 +1969,11 @@ module Api OSMFILE # upload it - post changeset_upload_path(:id => changeset_id), :params => diff, :headers => auth_header + post changeset_upload_path(changeset_id), :params => diff, :headers => auth_header assert_response :success, "can't upload a diff from JOSM: #{@response.body}" - get changeset_download_path(:id => changeset_id) + get changeset_download_path(changeset_id) assert_response :success assert_select "osmChange", 1 @@ -1935,15 +2004,15 @@ module Api diff = <<~CHANGESET - + - - - + + + - + @@ -1955,11 +2024,11 @@ module Api CHANGESET # upload it - post changeset_upload_path(:id => changeset_id), :params => diff, :headers => auth_header + post changeset_upload_path(changeset_id), :params => diff, :headers => auth_header assert_response :success, "can't upload multiple versions of an element in a diff: #{@response.body}" - get changeset_download_path(:id => changeset_id) + get changeset_download_path(changeset_id) assert_response :success assert_select "osmChange", 1 @@ -2034,7 +2103,7 @@ module Api # FIXME: This should really be moded to a integration test due to the with_controller def test_changeset_bbox way = create(:way) - create(:way_node, :way => way, :node => create(:node, :lat => 3, :lon => 3)) + create(:way_node, :way => way, :node => create(:node, :lat => 0.3, :lon => 0.3)) auth_header = basic_authorization_header create(:user).email, "test" @@ -2046,33 +2115,33 @@ module Api # add a single node to it with_controller(NodesController.new) do - xml = "" + xml = "" put node_create_path, :params => xml, :headers => auth_header assert_response :success, "Couldn't create node." end # get the bounding box back from the changeset - get changeset_show_path(:id => changeset_id) + get changeset_show_path(changeset_id) assert_response :success, "Couldn't read back changeset." - assert_select "osm>changeset[min_lon='1.0000000']", 1 - assert_select "osm>changeset[max_lon='1.0000000']", 1 - assert_select "osm>changeset[min_lat='2.0000000']", 1 - assert_select "osm>changeset[max_lat='2.0000000']", 1 + assert_select "osm>changeset[min_lon='0.1000000']", 1 + assert_select "osm>changeset[max_lon='0.1000000']", 1 + assert_select "osm>changeset[min_lat='0.2000000']", 1 + assert_select "osm>changeset[max_lat='0.2000000']", 1 # add another node to it with_controller(NodesController.new) do - xml = "" + xml = "" put node_create_path, :params => xml, :headers => auth_header assert_response :success, "Couldn't create second node." end # get the bounding box back from the changeset - get changeset_show_path(:id => changeset_id) + get changeset_show_path(changeset_id) assert_response :success, "Couldn't read back changeset for the second time." - assert_select "osm>changeset[min_lon='1.0000000']", 1 - assert_select "osm>changeset[max_lon='2.0000000']", 1 - assert_select "osm>changeset[min_lat='1.0000000']", 1 - assert_select "osm>changeset[max_lat='2.0000000']", 1 + assert_select "osm>changeset[min_lon='0.1000000']", 1 + assert_select "osm>changeset[max_lon='0.2000000']", 1 + assert_select "osm>changeset[min_lat='0.1000000']", 1 + assert_select "osm>changeset[max_lat='0.2000000']", 1 # add (delete) a way to it, which contains a point at (3,3) with_controller(WaysController.new) do @@ -2082,12 +2151,12 @@ module Api end # get the bounding box back from the changeset - get changeset_show_path(:id => changeset_id) + get changeset_show_path(changeset_id) assert_response :success, "Couldn't read back changeset for the third time." - assert_select "osm>changeset[min_lon='1.0000000']", 1 - assert_select "osm>changeset[max_lon='3.0000000']", 1 - assert_select "osm>changeset[min_lat='1.0000000']", 1 - assert_select "osm>changeset[max_lat='3.0000000']", 1 + assert_select "osm>changeset[min_lon='0.1000000']", 1 + assert_select "osm>changeset[max_lon='0.3000000']", 1 + assert_select "osm>changeset[min_lat='0.1000000']", 1 + assert_select "osm>changeset[max_lat='0.3000000']", 1 end ## @@ -2436,7 +2505,7 @@ module Api assert_response :success, "can't create a new node" node_id = @response.body.to_i - get api_node_path(:id => node_id) + get api_node_path(node_id) assert_response :success, "can't read back new node" node_doc = XML::Parser.string(@response.body).parse node_xml = node_doc.find("//osm/node").first @@ -2447,7 +2516,7 @@ module Api node_xml["lon"] = rand.to_s node_xml["version"] = (i + 1).to_s - put api_node_path(:id => node_id), :params => node_doc.to_s, :headers => auth_header + put api_node_path(node_id), :params => node_doc.to_s, :headers => auth_header assert_response :success, "attempt #{i} should have succeeded" end @@ -2456,7 +2525,7 @@ module Api node_xml["lon"] = rand.to_s node_xml["version"] = offset.to_s - put api_node_path(:id => node_id), :params => node_doc.to_s, :headers => auth_header + put api_node_path(node_id), :params => node_doc.to_s, :headers => auth_header assert_response :conflict, "final attempt should have failed" end @@ -2523,7 +2592,7 @@ module Api # bad changeset id assert_no_difference "changeset.subscribers.count" do - post api_changeset_subscribe_path(:id => 999111), :headers => auth_header + post api_changeset_subscribe_path(999111), :headers => auth_header end assert_response :not_found @@ -2573,7 +2642,7 @@ module Api # bad changeset id assert_no_difference "changeset.subscribers.count" do - post api_changeset_unsubscribe_path(:id => 999111), :headers => auth_header + post api_changeset_unsubscribe_path(999111), :headers => auth_header end assert_response :not_found