diff options
author | Heiko Bernloehr <Heiko.Bernloehr@FreeIT.de> | 2013-02-07 00:22:52 +0100 |
---|---|---|
committer | Heiko Bernloehr <Heiko.Bernloehr@FreeIT.de> | 2013-02-07 00:22:52 +0100 |
commit | b1991493127376655516ccced62a403ae84c3012 (patch) | |
tree | 3df01f7eda95e98ce9e49cb2f9fbe619db543ddf | |
parent | 3894dfdd5e8973812e5a1330ad57b328d9abe429 (diff) | |
download | ecs2-b1991493127376655516ccced62a403ae84c3012.tar.gz ecs2-b1991493127376655516ccced62a403ae84c3012.zip |
Prevent message deletion.
Scenario:
Owner deletes his message for which he is concurrently a receiver
This should only be possible until he clears its receiver queue. Then
the next DELETE operation removes the message from ECS and also destroys
all other receiver references as it would be happened if the message
owner had not even addressed itself.
-rw-r--r-- | app/controllers/messages_controller.rb | 2 | ||||
-rw-r--r-- | test/functional/messages_controller_test.rb | 28 |
2 files changed, 29 insertions, 1 deletions
diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 0c6a3a5..0ab375b 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -71,7 +71,7 @@ class MessagesController < ApplicationController when @record.outtimed_auths_resource_by_non_owner?(@app_namespace, @resource_name, @participant) @record.destroy_as_receiver(@participant) raise Ecs::OuttimedAuthsException, 'Authorization token outtimed' - when @participant.sender?(@record) + when (@participant.sender?(@record) and not @participant.receiver?(@record)) @record.destroy_as_sender else @record.destroy_as_receiver(@participant) diff --git a/test/functional/messages_controller_test.rb b/test/functional/messages_controller_test.rb index c661123..dcb35c5 100644 --- a/test/functional/messages_controller_test.rb +++ b/test/functional/messages_controller_test.rb @@ -186,6 +186,34 @@ class MessagesControllerTest < ActionController::TestCase assert_response 404 end + # Owner deletes his message for which he is concurrently a receiver. + # This should only be possible until he clears its receiver queue. Then the + # next delete operation removes the message from ECS and also destroys all other + # receiver references. + test "delete_postrouted_message_as_owner_and_receiver_with_references_in_place" do + @request.set_REQUEST_URI("/numlab/exercises/99999") + @request.env["X-EcsAuthId"] = identities(:stgt_id1).name + refscount= MembershipMessage.find_all_by_message_id(messages(:numlab_ex1)).count + assert refscount > 1 + post :destroy, { :id => messages(:numlab_ex1).id } + logger.debug "@request.path = "+@request.path + assert_response 200 + get :show, { :id => messages(:numlab_ex1).id } + assert_response 200 + assert MembershipMessage.find_all_by_message_id(messages(:numlab_ex1)).count == refscount - 1 + # message is only tagged as removed (events on). physically it's still there. + assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(messages(:numlab_ex1)) } + # This destroy is processed as role "sender", because the receiver quueue of the sender + # participant is now empty. Therefore all receiver references were deleted. + post :destroy, { :id => messages(:numlab_ex1).id } + assert_response 200 + get :show, { :id => messages(:numlab_ex1).id } + assert_response 404 + assert_equal 0, MembershipMessage.find_all_by_message_id(messages(:numlab_ex1)).count + # message is only tagged as removed (events on). physically it's still there. + assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(messages(:numlab_ex1)) } + end + test "delete_postrouted_message_as_owner_with_references_in_place" do @request.set_REQUEST_URI("/numlab/exercises/99999") @request.env["X-EcsAuthId"] = identities(:ulm_id1).name |