From 46113c9cbaa821632eb3a5b63700607e6c7941e6 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sun, 9 Feb 2025 18:27:01 +0300 Subject: [PATCH] Test api old element index accessed as moderator --- .../api/old_nodes_controller_test.rb | 34 ++++++++++--------- .../api/old_relations_controller_test.rb | 34 ++++++++++--------- .../api/old_ways_controller_test.rb | 34 ++++++++++--------- 3 files changed, 54 insertions(+), 48 deletions(-) diff --git a/test/controllers/api/old_nodes_controller_test.rb b/test/controllers/api/old_nodes_controller_test.rb index 2dea49d4c..e24693a41 100644 --- a/test/controllers/api/old_nodes_controller_test.rb +++ b/test/controllers/api/old_nodes_controller_test.rb @@ -86,6 +86,24 @@ module Api "redacted node #{node.id} version 1 shouldn't be present in the history, even when logged in and passing flag." end + def test_index_redacted_moderator + node = create(:node, :with_history, :version => 2) + node.old_nodes.find_by(:version => 1).redact!(create(:redaction)) + auth_header = bearer_authorization_header create(:moderator_user) + + get api_node_versions_path(node), :headers => auth_header + + assert_response :success, "Redaction shouldn't have stopped history working." + assert_dom "osm node[id='#{node.id}'][version='1']", 0, + "node #{node.id} version 1 should not be present in the history for moderators when not passing flag." + + get api_node_versions_path(node, :show_redactions => "true"), :headers => auth_header + + assert_response :success, "Redaction shouldn't have stopped history working." + assert_dom "osm node[id='#{node.id}'][version='1']", 1, + "node #{node.id} version 1 should still be present in the history for moderators when passing flag." + end + def test_show node = create(:node, :version => 2) create(:old_node, :node_id => node.id, :version => 1, :latitude => 60 * OldNode::SCALE, :longitude => 30 * OldNode::SCALE) @@ -238,16 +256,6 @@ module Api assert_response :forbidden, "After redaction, node should be gone for moderator, when flag not passed." get api_node_version_path(node_v3.node_id, node_v3.version, :show_redactions => "true"), :headers => auth_header assert_response :success, "After redaction, node should not be gone for moderator, when flag passed." - - # and when accessed via history - get api_node_versions_path(node) - assert_response :success, "Redaction shouldn't have stopped history working." - assert_select "osm node[id='#{node_v3.node_id}'][version='#{node_v3.version}']", 0, - "node #{node_v3.node_id} version #{node_v3.version} should not be present in the history for moderators when not passing flag." - get api_node_versions_path(node, :show_redactions => "true"), :headers => auth_header - assert_response :success, "Redaction shouldn't have stopped history working." - assert_select "osm node[id='#{node_v3.node_id}'][version='#{node_v3.version}']", 1, - "node #{node_v3.node_id} version #{node_v3.version} should still be present in the history for moderators when passing flag." end # testing that if the moderator drops auth, he can't see the @@ -266,12 +274,6 @@ module Api # check can't see the redacted data get api_node_version_path(node_v3.node_id, node_v3.version), :headers => auth_header assert_response :forbidden, "Redacted node shouldn't be visible via the version API." - - # and when accessed via history - get api_node_versions_path(node), :headers => auth_header - assert_response :success, "Redaction shouldn't have stopped history working." - assert_select "osm node[id='#{node_v3.node_id}'][version='#{node_v3.version}']", 0, - "redacted node #{node_v3.node_id} version #{node_v3.version} shouldn't be present in the history." end ## diff --git a/test/controllers/api/old_relations_controller_test.rb b/test/controllers/api/old_relations_controller_test.rb index 75fa5c77a..aac46ad65 100644 --- a/test/controllers/api/old_relations_controller_test.rb +++ b/test/controllers/api/old_relations_controller_test.rb @@ -89,6 +89,24 @@ module Api "redacted relation #{relation.id} version 1 shouldn't be present in the history, even when logged in and passing flag." end + def test_index_redacted_moderator + relation = create(:relation, :with_history, :version => 2) + relation.old_relations.find_by(:version => 1).redact!(create(:redaction)) + auth_header = bearer_authorization_header create(:moderator_user) + + get api_relation_versions_path(relation), :headers => auth_header + + assert_response :success, "Redaction shouldn't have stopped history working." + assert_dom "osm relation[id='#{relation.id}'][version='1']", 0, + "relation #{relation.id} version 1 should not be present in the history for moderators when not passing flag." + + get api_relation_versions_path(relation, :show_redactions => "true"), :headers => auth_header + + assert_response :success, "Redaction shouldn't have stopped history working." + assert_dom "osm relation[id='#{relation.id}'][version='1']", 1, + "relation #{relation.id} version 1 should still be present in the history for moderators when passing flag." + end + def test_show relation = create(:relation, :with_history, :version => 2) create(:old_relation_tag, :old_relation => relation.old_relations[0], :k => "k1", :v => "v1") @@ -225,16 +243,6 @@ module Api assert_response :forbidden, "After redaction, relation should be gone for moderator, when flag not passed." get api_relation_version_path(relation_v3.relation_id, relation_v3.version, :show_redactions => "true"), :headers => auth_header assert_response :success, "After redaction, relation should not be gone for moderator, when flag passed." - - # and when accessed via history - get api_relation_versions_path(relation), :headers => auth_header - assert_response :success, "Redaction shouldn't have stopped history working." - assert_select "osm relation[id='#{relation_v3.relation_id}'][version='#{relation_v3.version}']", 0, - "relation #{relation_v3.relation_id} version #{relation_v3.version} should not be present in the history for moderators when not passing flag." - get api_relation_versions_path(relation, :show_redactions => "true"), :headers => auth_header - assert_response :success, "Redaction shouldn't have stopped history working." - assert_select "osm relation[id='#{relation_v3.relation_id}'][version='#{relation_v3.version}']", 1, - "relation #{relation_v3.relation_id} version #{relation_v3.version} should still be present in the history for moderators when passing flag." end # testing that if the moderator drops auth, he can't see the @@ -254,12 +262,6 @@ module Api # check can't see the redacted data get api_relation_version_path(relation_v3.relation_id, relation_v3.version), :headers => auth_header assert_response :forbidden, "Redacted relation shouldn't be visible via the version API." - - # and when accessed via history - get api_relation_versions_path(relation), :headers => auth_header - assert_response :success, "Redaction shouldn't have stopped history working." - assert_select "osm relation[id='#{relation_v3.relation_id}'][version='#{relation_v3.version}']", 0, - "redacted relation #{relation_v3.relation_id} version #{relation_v3.version} shouldn't be present in the history." end ## diff --git a/test/controllers/api/old_ways_controller_test.rb b/test/controllers/api/old_ways_controller_test.rb index 9464b6232..c365f3297 100644 --- a/test/controllers/api/old_ways_controller_test.rb +++ b/test/controllers/api/old_ways_controller_test.rb @@ -96,6 +96,24 @@ module Api "redacted node #{way.id} version 1 shouldn't be present in the history, even when logged in and passing flag." end + def test_index_redacted_moderator + way = create(:way, :with_history, :version => 2) + way.old_ways.find_by(:version => 1).redact!(create(:redaction)) + auth_header = bearer_authorization_header create(:moderator_user) + + get api_way_versions_path(way), :headers => auth_header + + assert_response :success, "Redaction shouldn't have stopped history working." + assert_dom "osm way[id='#{way.id}'][version='1']", 0, + "way #{way.id} version 1 should not be present in the history for moderators when not passing flag." + + get api_way_versions_path(way, :show_redactions => "true"), :headers => auth_header + + assert_response :success, "Redaction shouldn't have stopped history working." + assert_dom "osm way[id='#{way.id}'][version='1']", 1, + "way #{way.id} version 1 should still be present in the history for moderators when passing flag." + end + def test_show way = create(:way, :with_history, :version => 2) @@ -233,16 +251,6 @@ module Api assert_response :forbidden, "After redaction, node should be gone for moderator, when flag not passed." get api_way_version_path(way_v3.way_id, way_v3.version, :show_redactions => "true"), :headers => auth_header assert_response :success, "After redaction, node should not be gone for moderator, when flag passed." - - # and when accessed via history - get api_way_versions_path(way), :headers => auth_header - assert_response :success, "Redaction shouldn't have stopped history working." - assert_select "osm way[id='#{way_v3.way_id}'][version='#{way_v3.version}']", 0, - "way #{way_v3.way_id} version #{way_v3.version} should not be present in the history for moderators when not passing flag." - get api_way_versions_path(way, :show_redactions => "true"), :headers => auth_header - assert_response :success, "Redaction shouldn't have stopped history working." - assert_select "osm way[id='#{way_v3.way_id}'][version='#{way_v3.version}']", 1, - "way #{way_v3.way_id} version #{way_v3.version} should still be present in the history for moderators when passing flag." end # testing that if the moderator drops auth, he can't see the @@ -261,12 +269,6 @@ module Api # check can't see the redacted data get api_way_version_path(way_v3.way_id, way_v3.version), :headers => auth_header assert_response :forbidden, "Redacted node shouldn't be visible via the version API." - - # and when accessed via history - get api_way_versions_path(way), :headers => auth_header - assert_response :success, "Redaction shouldn't have stopped history working." - assert_select "osm way[id='#{way_v3.way_id}'][version='#{way_v3.version}']", 0, - "redacted way #{way_v3.way_id} version #{way_v3.version} shouldn't be present in the history." end ## -- 2.39.5