From 0063727434d240528d72cbeabae9cb4d46cd6b15 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Mon, 10 Feb 2025 18:44:05 +0300 Subject: [PATCH] Check old element state instead of responses in unredaction tests --- .../api/old_nodes_controller_test.rb | 37 +++++-------------- .../api/old_relations_controller_test.rb | 37 +++++-------------- .../api/old_ways_controller_test.rb | 37 +++++-------------- 3 files changed, 30 insertions(+), 81 deletions(-) diff --git a/test/controllers/api/old_nodes_controller_test.rb b/test/controllers/api/old_nodes_controller_test.rb index bddc6bc24..0f7227287 100644 --- a/test/controllers/api/old_nodes_controller_test.rb +++ b/test/controllers/api/old_nodes_controller_test.rb @@ -269,10 +269,13 @@ module Api 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 ## @@ -282,12 +285,14 @@ module Api 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 ## @@ -298,34 +303,12 @@ module Api 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 diff --git a/test/controllers/api/old_relations_controller_test.rb b/test/controllers/api/old_relations_controller_test.rb index d7aa923ec..a874232bd 100644 --- a/test/controllers/api/old_relations_controller_test.rb +++ b/test/controllers/api/old_relations_controller_test.rb @@ -260,10 +260,13 @@ module Api 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 ## @@ -272,12 +275,14 @@ module Api 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 ## @@ -287,34 +292,12 @@ module Api 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 diff --git a/test/controllers/api/old_ways_controller_test.rb b/test/controllers/api/old_ways_controller_test.rb index d7e6091ca..5dc1c9cfc 100644 --- a/test/controllers/api/old_ways_controller_test.rb +++ b/test/controllers/api/old_ways_controller_test.rb @@ -271,10 +271,13 @@ module Api 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 ## @@ -283,12 +286,14 @@ module Api 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 ## @@ -299,34 +304,12 @@ module Api 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 -- 2.39.5