def test_unredact_node_unauthorised
node = create(:node, :with_history, :version => 2)
node_v1 = node.old_nodes.find_by(:version => 1)
- node_v1.redact!(create(:redaction))
+ redaction = create(:redaction)
+ node_v1.redact!(redaction)
post node_version_redact_path(node_v1.node_id, node_v1.version)
+
assert_response :unauthorized, "should need to be authenticated to unredact."
+ assert_equal redaction, node_v1.reload.redaction
end
##
user = create(:user)
node = create(:node, :with_history, :version => 2)
node_v1 = node.old_nodes.find_by(:version => 1)
- node_v1.redact!(create(:redaction))
-
+ redaction = create(:redaction)
+ node_v1.redact!(redaction)
auth_header = bearer_authorization_header user
post node_version_redact_path(node_v1.node_id, node_v1.version), :headers => auth_header
+
assert_response :forbidden, "should need to be moderator to unredact."
+ assert_equal redaction, node_v1.reload.redaction
end
##
node = create(:node, :with_history, :version => 2)
node_v1 = node.old_nodes.find_by(:version => 1)
node_v1.redact!(create(:redaction))
-
auth_header = bearer_authorization_header moderator_user
post node_version_redact_path(node_v1.node_id, node_v1.version), :headers => auth_header
- assert_response :success, "should be OK to unredact old version as moderator."
-
- # check moderator can now see the redacted data, when not
- # passing the aspecial flag
- get api_node_version_path(node_v1.node_id, node_v1.version), :headers => auth_header
- assert_response :success, "After unredaction, node should not be gone for moderator."
-
- # and when accessed via history
- get api_node_versions_path(node)
- assert_response :success, "Unredaction shouldn't have stopped history working."
- assert_select "osm node[id='#{node_v1.node_id}'][version='#{node_v1.version}']", 1,
- "node #{node_v1.node_id} version #{node_v1.version} should now be present in the history for moderators without passing flag."
- auth_header = bearer_authorization_header
-
- # check normal user can now see the redacted data
- get api_node_version_path(node_v1.node_id, node_v1.version), :headers => auth_header
- assert_response :success, "After unredaction, node should be visible to normal users."
-
- # and when accessed via history
- get api_node_versions_path(node)
- assert_response :success, "Unredaction shouldn't have stopped history working."
- assert_select "osm node[id='#{node_v1.node_id}'][version='#{node_v1.version}']", 1,
- "node #{node_v1.node_id} version #{node_v1.version} should now be present in the history for normal users without passing flag."
+ assert_response :success, "should be OK to unredact old version as moderator."
+ assert_nil node_v1.reload.redaction
end
private
def test_unredact_relation_unauthorised
relation = create(:relation, :with_history, :version => 2)
relation_v1 = relation.old_relations.find_by(:version => 1)
- relation_v1.redact!(create(:redaction))
+ redaction = create(:redaction)
+ relation_v1.redact!(redaction)
post relation_version_redact_path(relation_v1.relation_id, relation_v1.version)
+
assert_response :unauthorized, "should need to be authenticated to unredact."
+ assert_equal redaction, relation_v1.reload.redaction
end
##
def test_unredact_relation_normal_user
relation = create(:relation, :with_history, :version => 2)
relation_v1 = relation.old_relations.find_by(:version => 1)
- relation_v1.redact!(create(:redaction))
-
+ redaction = create(:redaction)
+ relation_v1.redact!(redaction)
auth_header = bearer_authorization_header
post relation_version_redact_path(relation_v1.relation_id, relation_v1.version), :headers => auth_header
+
assert_response :forbidden, "should need to be moderator to unredact."
+ assert_equal redaction, relation_v1.reload.redaction
end
##
relation = create(:relation, :with_history, :version => 2)
relation_v1 = relation.old_relations.find_by(:version => 1)
relation_v1.redact!(create(:redaction))
-
auth_header = bearer_authorization_header create(:moderator_user)
post relation_version_redact_path(relation_v1.relation_id, relation_v1.version), :headers => auth_header
- assert_response :success, "should be OK to unredact old version as moderator."
-
- # check moderator can still see the redacted data, without passing
- # the appropriate flag
- get api_relation_version_path(relation_v1.relation_id, relation_v1.version), :headers => auth_header
- assert_response :success, "After unredaction, relation should not be gone for moderator."
- # 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_v1.relation_id}'][version='#{relation_v1.version}']", 1,
- "relation #{relation_v1.relation_id} version #{relation_v1.version} should still be present in the history for moderators."
-
- auth_header = bearer_authorization_header
-
- # check normal user can now see the redacted data
- get api_relation_version_path(relation_v1.relation_id, relation_v1.version), :headers => auth_header
- assert_response :success, "After redaction, node should not be gone for normal user."
-
- # 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_v1.relation_id}'][version='#{relation_v1.version}']", 1,
- "relation #{relation_v1.relation_id} version #{relation_v1.version} should still be present in the history for normal users."
+ assert_response :success, "should be OK to unredact old version as moderator."
+ assert_nil relation_v1.reload.redaction
end
private
def test_unredact_way_unauthorised
way = create(:way, :with_history, :version => 2)
way_v1 = way.old_ways.find_by(:version => 1)
- way_v1.redact!(create(:redaction))
+ redaction = create(:redaction)
+ way_v1.redact!(redaction)
post way_version_redact_path(way_v1.way_id, way_v1.version)
+
assert_response :unauthorized, "should need to be authenticated to unredact."
+ assert_equal redaction, way_v1.reload.redaction
end
##
def test_unredact_way_normal_user
way = create(:way, :with_history, :version => 2)
way_v1 = way.old_ways.find_by(:version => 1)
- way_v1.redact!(create(:redaction))
-
+ redaction = create(:redaction)
+ way_v1.redact!(redaction)
auth_header = bearer_authorization_header
post way_version_redact_path(way_v1.way_id, way_v1.version), :headers => auth_header
+
assert_response :forbidden, "should need to be moderator to unredact."
+ assert_equal redaction, way_v1.reload.redaction
end
##
way = create(:way, :with_history, :version => 2)
way_v1 = way.old_ways.find_by(:version => 1)
way_v1.redact!(create(:redaction))
-
auth_header = bearer_authorization_header moderator_user
post way_version_redact_path(way_v1.way_id, way_v1.version), :headers => auth_header
- assert_response :success, "should be OK to unredact old version as moderator."
- # check moderator can still see the unredacted data, without passing
- # the appropriate flag
- get api_way_version_path(way_v1.way_id, way_v1.version), :headers => auth_header
- assert_response :success, "After unredaction, node should not be gone for moderator."
-
- # and when accessed via history
- get api_way_versions_path(way), :headers => auth_header
- assert_response :success, "Unredaction shouldn't have stopped history working."
- assert_select "osm way[id='#{way_v1.way_id}'][version='#{way_v1.version}']", 1,
- "way #{way_v1.way_id} version #{way_v1.version} should still be present in the history for moderators."
-
- auth_header = bearer_authorization_header
-
- # check normal user can now see the unredacted data
- get api_way_version_path(way_v1.way_id, way_v1.version), :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_v1.way_id}'][version='#{way_v1.version}']", 1,
- "way #{way_v1.way_id} version #{way_v1.version} should still be present in the history for normal users."
+ assert_response :success, "should be OK to unredact old version as moderator."
+ assert_nil way_v1.reload.redaction
end
private