From a7ed682520fd5d50f50188954a6803befc3c59e0 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sun, 6 Jul 2025 20:44:56 +0300 Subject: [PATCH] Split create way with duplicate tags tests "Use unicode decoding ambiguities" in the deleted comment was referring to code long gone since c3785ff278f605fc6c98ac0bdcd3dc3c79de05a4. --- test/controllers/api/ways_controller_test.rb | 91 +++++++++----------- 1 file changed, 41 insertions(+), 50 deletions(-) diff --git a/test/controllers/api/ways_controller_test.rb b/test/controllers/api/ways_controller_test.rb index 3d5da8690..35adca7d1 100644 --- a/test/controllers/api/ways_controller_test.rb +++ b/test/controllers/api/ways_controller_test.rb @@ -369,6 +369,47 @@ module Api end end + def test_create_with_duplicate_tags_by_private_user + node = create(:node) + + with_unchanging_request([:data_public => false]) do |headers, changeset| + osm = <<~OSM + + + + + + + + OSM + + post api_ways_path, :params => osm, :headers => headers + + assert_response :forbidden, "adding new duplicate tags to a way with a non-public user should fail with 'forbidden'" + end + end + + def test_create_with_duplicate_tags + node = create(:node) + + with_unchanging_request do |headers, changeset| + osm = <<~OSM + + + + + + + + OSM + + post api_ways_path, :params => osm, :headers => headers + + assert_response :bad_request, "adding new duplicate tags to a way should fail with 'bad request'" + assert_equal "Element way/ has duplicate tags with key addr:housenumber", @response.body + end + end + # ------------------------------------- # Test deleting ways. # ------------------------------------- @@ -963,56 +1004,6 @@ module Api end end - ## - # Try adding a new duplicate tags to a way. - # But be a bit subtle - use unicode decoding ambiguities to use different - # binary strings which have the same decoding. - def test_invalid_duplicate_tags - private_user = create(:user, :data_public => false) - private_changeset = create(:changeset, :user => private_user) - user = create(:user) - changeset = create(:changeset, :user => user) - - ## First make sure that you can't with a non-public user - # setup auth - auth_header = bearer_authorization_header private_user - - # add the tag into the existing xml - way_str = <<~OSM - - - - - - - OSM - - # try and upload it - post api_ways_path, :params => way_str, :headers => auth_header - assert_response :forbidden, - "adding new duplicate tags to a way with a non-public user should fail with 'forbidden'" - - ## Now do it with a public user - # setup auth - auth_header = bearer_authorization_header user - - # add the tag into the existing xml - way_str = <<~OSM - - - - - - - OSM - - # try and upload it - post api_ways_path, :params => way_str, :headers => auth_header - assert_response :bad_request, - "adding new duplicate tags to a way should fail with 'bad request'" - assert_equal "Element way/ has duplicate tags with key addr:housenumber", @response.body - end - ## # test initial rate limit def test_initial_rate_limit -- 2.39.5