Test api old element index accessed as moderator

This commit is contained in:
Anton Khorev 2025-02-09 18:27:01 +03:00
parent d0c68c4041
commit 46113c9cba
3 changed files with 54 additions and 48 deletions

View file

@ -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
##

View file

@ -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
##

View file

@ -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
##