- get api_way_version_path(way_v1.way_id, way_v1.version)
- assert_response :forbidden, "Redacted way shouldn't be visible via the version API."
-
- # not even to a logged-in user
- auth_header = bearer_authorization_header
- get api_way_version_path(way_v1.way_id, way_v1.version), :headers => auth_header
- assert_response :forbidden, "Redacted way shouldn't be visible via the version API, even when logged in."
- end
-
- ##
- # check that returned history is the same as getting all
- # versions of a way from the api.
- def test_history_equals_versions
- way = create(:way, :with_history)
- used_way = create(:way, :with_history)
- create(:relation_member, :member => used_way)
- way_with_versions = create(:way, :with_history, :version => 4)
-
- check_history_equals_versions(way.id)
- check_history_equals_versions(used_way.id)
- check_history_equals_versions(way_with_versions.id)
- end
-
- ##
- # test the redaction of an old version of a way, while not being
- # authorised.
- def test_redact_way_unauthorised
- way = create(:way, :with_history, :version => 4)
- way_v3 = way.old_ways.find_by(:version => 3)
-
- do_redact_way(way_v3, create(:redaction))
- assert_response :unauthorized, "should need to be authenticated to redact."
- end
-
- ##
- # test the redaction of an old version of a way, while being
- # authorised as a normal user.
- def test_redact_way_normal_user
- auth_header = bearer_authorization_header
- way = create(:way, :with_history, :version => 4)
- way_v3 = way.old_ways.find_by(:version => 3)
-
- do_redact_way(way_v3, create(:redaction), auth_header)
- assert_response :forbidden, "should need to be moderator to redact."
- end
-
- ##
- # test that, even as moderator, the current version of a way
- # can't be redacted.
- def test_redact_way_current_version
- auth_header = bearer_authorization_header create(:moderator_user)
- way = create(:way, :with_history, :version => 4)
- way_latest = way.old_ways.last
-
- do_redact_way(way_latest, create(:redaction), auth_header)
- assert_response :bad_request, "shouldn't be OK to redact current version as moderator."
- end
-
- def test_redact_way_by_regular_without_write_redactions_scope
- auth_header = bearer_authorization_header(create(:user), :scopes => %w[read_prefs write_api])
- do_redact_redactable_way(auth_header)
- assert_response :forbidden, "should need to be moderator to redact."
- end
-
- def test_redact_way_by_regular_with_write_redactions_scope
- auth_header = bearer_authorization_header(create(:user), :scopes => %w[write_redactions])
- do_redact_redactable_way(auth_header)
- assert_response :forbidden, "should need to be moderator to redact."
- end
-
- def test_redact_way_by_moderator_without_write_redactions_scope
- auth_header = bearer_authorization_header(create(:moderator_user), :scopes => %w[read_prefs write_api])
- do_redact_redactable_way(auth_header)
- assert_response :forbidden, "should need to have write_redactions scope to redact."
- end
-
- def test_redact_way_by_moderator_with_write_redactions_scope
- auth_header = bearer_authorization_header(create(:moderator_user), :scopes => %w[write_redactions])
- do_redact_redactable_way(auth_header)
- assert_response :success, "should be OK to redact old version as moderator with write_redactions scope."
- end
-
- ##
- # test the redaction of an old version of a way, while being
- # authorised as a moderator.
- def test_redact_way_moderator
- way = create(:way, :with_history, :version => 4)
- way_v3 = way.old_ways.find_by(:version => 3)
- auth_header = bearer_authorization_header create(:moderator_user)