]> git.openstreetmap.org Git - rails.git/commitdiff
Yet more tests...
authorTom Hughes <tom@compton.nu>
Sun, 8 Mar 2015 19:55:45 +0000 (19:55 +0000)
committerTom Hughes <tom@compton.nu>
Sun, 8 Mar 2015 19:55:45 +0000 (19:55 +0000)
test/controllers/browse_controller_test.rb
test/controllers/old_node_controller_test.rb
test/controllers/old_relation_controller_test.rb
test/controllers/old_way_controller_test.rb
test/controllers/relation_controller_test.rb
test/controllers/site_controller_test.rb

index 72bb68937dd91815d1857892d7f5dbf2896a5461..a1c94b4575309f6bfcb8857d40fec2fe1ae8f834 100644 (file)
@@ -74,6 +74,16 @@ class BrowseControllerTest < ActionController::TestCase
     browse_check "changeset", changesets(:public_user_first_change).id, "browse/changeset"
   end
 
+  def test_read_changeset_hidden_comments
+    browse_check "changeset", changesets(:normal_user_closed_change).id, "browse/changeset"
+    assert_select "div.changeset-comments ul li", :count => 3
+
+    session[:user] = users(:moderator_user).id
+
+    browse_check "changeset", changesets(:normal_user_closed_change).id, "browse/changeset"
+    assert_select "div.changeset-comments ul li", :count => 4
+  end
+
   def test_read_note
     browse_check "note", notes(:open_note).id, "browse/note"
   end
index 6edb7c553f90bb38a82cbed7ff85ad6ec0ce8ccc..226662c1898124a3c126c539b487f12fd21f310b 100644 (file)
@@ -278,6 +278,61 @@ class OldNodeControllerTest < ActionController::TestCase
     assert_select "osm node[id='#{node.node_id}'][version='#{node.version}']", 0, "redacted node #{node.node_id} version #{node.version} shouldn't be present in the history."
   end
 
+  ##
+  # test the unredaction of an old version of a node, while not being
+  # authorised.
+  def test_unredact_node_unauthorised
+    node = nodes(:redacted_node_redacted_version)
+
+    post :redact, :id => node.node_id, :version => node.version
+    assert_response :unauthorized, "should need to be authenticated to unredact."
+  end
+
+  ##
+  # test the unredaction of an old version of a node, while being
+  # authorised as a normal user.
+  def test_unredact_node_normal_user
+    node = nodes(:redacted_node_redacted_version)
+    basic_authorization(users(:public_user).email, "test")
+
+    post :redact, :id => node.node_id, :version => node.version
+    assert_response :forbidden, "should need to be moderator to unredact."
+  end
+
+  ##
+  # test the unredaction of an old version of a node, while being
+  # authorised as a moderator.
+  def test_unredact_node_moderator
+    node = nodes(:redacted_node_redacted_version)
+    basic_authorization(users(:moderator_user).email, "test")
+
+    post :redact, :id => node.node_id, :version => node.version
+    assert_response :success, "should be OK to redact old version as moderator."
+
+    # check moderator can now see the redacted data, when not
+    # passing the aspecial flag
+    get :version, :id => node.node_id, :version => node.version
+    assert_response :success, "After unredaction, node should not be gone for moderator."
+
+    # and when accessed via history
+    get :history, :id => node.node_id
+    assert_response :success, "Unredaction shouldn't have stopped history working."
+    assert_select "osm node[id='#{node.node_id}'][version='#{node.version}']", 1, "node #{node.node_id} version #{node.version} should now be present in the history for moderators without passing flag."
+
+    basic_authorization(users(:normal_user).email, "test")
+
+    # check normal user can now see the redacted data
+    get :version, :id => node.node_id, :version => node.version
+    assert_response :success, "After unredaction, node should not be gone for moderator."
+
+    # and when accessed via history
+    get :history, :id => node.node_id
+    assert_response :success, "Unredaction shouldn't have stopped history working."
+    assert_select "osm node[id='#{node.node_id}'][version='#{node.version}']", 1, "node #{node.node_id} version #{node.version} should now be present in the history for moderators without passing flag."
+  end
+
+  private
+
   def do_redact_node(node, redaction)
     get :version, :id => node.node_id, :version => node.version
     assert_response :success, "should be able to get version #{node.version} of node #{node.node_id}."
index 1ce87a25298ad104dd1cd89b356ba1bbcaeafda9..6222296610c4a83d5e11b0a6fda439a507ae78af 100644 (file)
@@ -145,6 +145,61 @@ class OldRelationControllerTest < ActionController::TestCase
     assert_select "osm relation[id='#{relation.relation_id}'][version='#{relation.version}']", 0, "redacted relation #{relation.relation_id} version #{relation.version} shouldn't be present in the history."
   end
 
+  ##
+  # test the unredaction of an old version of a relation, while not being
+  # authorised.
+  def test_unredact_relation_unauthorised
+    relation = relations(:relation_with_redacted_versions_v3)
+
+    post :redact, :id => relation.relation_id, :version => relation.version
+    assert_response :unauthorized, "should need to be authenticated to unredact."
+  end
+
+  ##
+  # test the unredaction of an old version of a relation, while being
+  # authorised as a normal user.
+  def test_unredact_relation_normal_user
+    relation = relations(:relation_with_redacted_versions_v3)
+    basic_authorization(users(:public_user).email, "test")
+
+    post :redact, :id => relation.relation_id, :version => relation.version
+    assert_response :forbidden, "should need to be moderator to unredact."
+  end
+
+  ##
+  # test the unredaction of an old version of a relation, while being
+  # authorised as a moderator.
+  def test_unredact_relation_moderator
+    relation = relations(:relation_with_redacted_versions_v3)
+    basic_authorization(users(:moderator_user).email, "test")
+
+    post :redact, :id => relation.relation_id, :version => relation.version
+    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 :version, :id => relation.relation_id, :version => relation.version
+    assert_response :success, "After redaction, node should not be gone for moderator, when flag passed."
+
+    # and when accessed via history
+    get :history, :id => relation.relation_id
+    assert_response :success, "Redaction shouldn't have stopped history working."
+    assert_select "osm relation[id='#{relation.relation_id}'][version='#{relation.version}']", 1, "relation #{relation.relation_id} version #{relation.version} should still be present in the history for moderators when passing flag."
+
+    basic_authorization(users(:normal_user).email, "test")
+
+    # check normal user can now see the redacted data
+    get :version, :id => relation.relation_id, :version => relation.version
+    assert_response :success, "After redaction, node should not be gone for moderator, when flag passed."
+
+    # and when accessed via history
+    get :history, :id => relation.relation_id
+    assert_response :success, "Redaction shouldn't have stopped history working."
+    assert_select "osm relation[id='#{relation.relation_id}'][version='#{relation.version}']", 1, "relation #{relation.relation_id} version #{relation.version} should still be present in the history for moderators when passing flag."
+  end
+
+  private
+
   ##
   # check that the current version of a relation is equivalent to the
   # version which we're getting from the versions call.
index f48b0cb89101b3121b1bc34b63310bfd534b8742..612b4a6a48545bf127cdfee855be615291914281 100644 (file)
@@ -171,6 +171,61 @@ class OldWayControllerTest < ActionController::TestCase
     assert_select "osm way[id='#{way.way_id}'][version='#{way.version}']", 0, "redacted way #{way.way_id} version #{way.version} shouldn't be present in the history."
   end
 
+  ##
+  # test the unredaction of an old version of a way, while not being
+  # authorised.
+  def test_unredact_way_unauthorised
+    way = ways(:way_with_redacted_versions_v3)
+
+    post :redact, :id => way.way_id, :version => way.version
+    assert_response :unauthorized, "should need to be authenticated to unredact."
+  end
+
+  ##
+  # test the unredaction of an old version of a way, while being
+  # authorised as a normal user.
+  def test_unredact_way_normal_user
+    way = ways(:way_with_redacted_versions_v3)
+    basic_authorization(users(:public_user).email, "test")
+
+    post :redact, :id => way.way_id, :version => way.version
+    assert_response :forbidden, "should need to be moderator to unredact."
+  end
+
+  ##
+  # test the unredaction of an old version of a way, while being
+  # authorised as a moderator.
+  def test_unredact_way_moderator
+    way = ways(:way_with_redacted_versions_v3)
+    basic_authorization(users(:moderator_user).email, "test")
+
+    post :redact, :id => way.way_id, :version => way.version
+    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 :version, :id => way.way_id, :version => way.version
+    assert_response :success, "After redaction, node should not be gone for moderator, when flag passed."
+
+    # and when accessed via history
+    get :history, :id => way.way_id
+    assert_response :success, "Redaction shouldn't have stopped history working."
+    assert_select "osm way[id='#{way.way_id}'][version='#{way.version}']", 1, "way #{way.way_id} version #{way.version} should still be present in the history for moderators when passing flag."
+
+    basic_authorization(users(:normal_user).email, "test")
+
+    # check normal user can now see the redacted data
+    get :version, :id => way.way_id, :version => way.version
+    assert_response :success, "After redaction, node should not be gone for moderator, when flag passed."
+
+    # and when accessed via history
+    get :history, :id => way.way_id
+    assert_response :success, "Redaction shouldn't have stopped history working."
+    assert_select "osm way[id='#{way.way_id}'][version='#{way.version}']", 1, "way #{way.way_id} version #{way.version} should still be present in the history for moderators when passing flag."
+  end
+
+  private
+
   ##
   # check that the current version of a way is equivalent to the
   # version which we're getting from the versions call.
index 7e10159b4d416f450af60368b5ccf5cf5a49574f..6b9ed159faee6134dec8f7e1bf3eb6d616c26055 100644 (file)
@@ -105,10 +105,15 @@ class RelationControllerTest < ActionController::TestCase
 
   def test_full
     # check the "full" mode
+    get :full, :id => 999999
+    assert_response :not_found
+
+    get :full, :id => current_relations(:invisible_relation).id
+    assert_response :gone
+
     get :full, :id => current_relations(:visible_relation).id
     assert_response :success
     # FIXME: check whether this contains the stuff we want!
-    print @response.body if $VERBOSE
   end
 
   ##
@@ -382,6 +387,19 @@ class RelationControllerTest < ActionController::TestCase
     end
   end
 
+  def test_update_wrong_id
+    basic_authorization users(:public_user).email, "test"
+    rel_id = current_relations(:multi_tag_relation).id
+    cs_id = changesets(:public_user_first_change).id
+
+    with_relation(rel_id) do |rel|
+      update_changeset(rel, cs_id)
+      content rel
+      put :update, :id => current_relations(:visible_relation).id
+      assert_response :bad_request
+    end
+  end
+
   # -------------------------------------
   # Test creating some invalid relations.
   # -------------------------------------
index 776e9448a6bd2f3bbfb6312586b47aa2e5f678a4..6c66358a0569d3455161dc1471cad496c1e65f2a 100644 (file)
@@ -91,6 +91,21 @@ class SiteControllerTest < ActionController::TestCase
 
   # Test the index page redirects
   def test_index_redirect
+    get :index, :node => 123
+    assert_redirected_to :controller => :browse, :action => :node, :id => 123
+
+    get :index, :way => 123
+    assert_redirected_to :controller => :browse, :action => :way, :id => 123
+
+    get :index, :relation => 123
+    assert_redirected_to :controller => :browse, :action => :relation, :id => 123
+
+    get :index, :note => 123
+    assert_redirected_to :controller => :browse, :action => :note, :id => 123
+
+    get :index, :query => "test"
+    assert_redirected_to :controller => :geocoder, :action => :search, :query => "test"
+
     get :index, :lat => 4, :lon => 5
     assert_redirected_to :controller => :site, :action => :index, :anchor => "map=5/4/5"