From 5bef9b592953c7d3d561fab9e3a396a21ee2a036 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sat, 5 Jul 2025 05:33:06 +0300 Subject: [PATCH] Make duplicate tags test similar to update node tests --- test/controllers/api/nodes_controller_test.rb | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/test/controllers/api/nodes_controller_test.rb b/test/controllers/api/nodes_controller_test.rb index 2f0ded4a7..bddf48c1f 100644 --- a/test/controllers/api/nodes_controller_test.rb +++ b/test/controllers/api/nodes_controller_test.rb @@ -681,28 +681,25 @@ module Api end end - ## - # test adding tags to a node - def test_duplicate_tags - existing_tag = create(:node_tag) - assert existing_tag.node.changeset.user.data_public - # setup auth - auth_header = bearer_authorization_header existing_tag.node.changeset.user - - # add an identical tag to the node - tag_xml = XML::Node.new("tag") - tag_xml["k"] = existing_tag.k - tag_xml["v"] = existing_tag.v - - # add the tag into the existing xml - node_xml = xml_for_node(existing_tag.node) - node_xml.find("//osm/node").first << tag_xml - - # try and upload it - put api_node_path(existing_tag.node), :params => node_xml.to_s, :headers => auth_header - assert_response :bad_request, - "adding duplicate tags to a node should fail with 'bad request'" - assert_equal "Element node/#{existing_tag.node.id} has duplicate tags with key #{existing_tag.k}", @response.body + def test_update_with_duplicate_tags + with_unchanging(:node) do |node| + create(:node_tag, :node => node, :k => "key_to_duplicate", :v => "value_to_duplicate") + + with_unchanging_request do |headers, changeset| + tag_xml = XML::Node.new("tag") + tag_xml["k"] = "key_to_duplicate" + tag_xml["v"] = "value_to_duplicate" + + osm_xml = xml_for_node node + osm_xml.find("//osm/node").first << tag_xml + osm_xml = update_changeset osm_xml, changeset.id + + put api_node_path(node), :params => osm_xml.to_s, :headers => headers + + assert_response :bad_request, "adding duplicate tags to a node should fail with 'bad request'" + assert_equal "Element node/#{node.id} has duplicate tags with key key_to_duplicate", @response.body + end + end end # test whether string injection is possible -- 2.39.5