diff options
Diffstat (limited to 'test/models')
| -rw-r--r-- | test/models/asset_destroy_test.rb | 13 | ||||
| -rw-r--r-- | test/models/node_test.rb | 68 | ||||
| -rw-r--r-- | test/models/user_test.rb | 16 |
3 files changed, 97 insertions, 0 deletions
diff --git a/test/models/asset_destroy_test.rb b/test/models/asset_destroy_test.rb index 5583f685..2f38d692 100644 --- a/test/models/asset_destroy_test.rb +++ b/test/models/asset_destroy_test.rb | |||
| @@ -48,4 +48,17 @@ class AssetDestroyTest < ActiveSupport::TestCase | |||
| 48 | assert_equal "Doomed asset", action.metadata["asset_name"] | 48 | assert_equal "Doomed asset", action.metadata["asset_name"] |
| 49 | assert_nil action.action_participants.first.subject | 49 | assert_nil action.action_participants.first.subject |
| 50 | end | 50 | end |
| 51 | |||
| 52 | test "destroying an asset attached to a restricted node needs the redaktion role" do | ||
| 53 | editor = User.create!(:login => "asset_gate", :email => "ag@example.com", | ||
| 54 | :password => "secret", :password_confirmation => "secret") | ||
| 55 | updates = Node.root.children.create!(:slug => "updates") | ||
| 56 | node = updates.children.create!(:slug => "gated-attachment") | ||
| 57 | node.reload.attach_asset!(@asset, :user => nil) | ||
| 58 | |||
| 59 | error = assert_raises(ActiveRecord::RecordInvalid) { @asset.destroy_witnessed!(:user => editor) } | ||
| 60 | assert_includes error.message, | ||
| 61 | I18n.t("activerecord.errors.models.asset.attributes.base.not_permitted") | ||
| 62 | assert Asset.exists?(@asset.id) | ||
| 63 | end | ||
| 51 | end | 64 | end |
diff --git a/test/models/node_test.rb b/test/models/node_test.rb index c1316ea6..f57f83bf 100644 --- a/test/models/node_test.rb +++ b/test/models/node_test.rb | |||
| @@ -936,4 +936,72 @@ class NodeTest < ActiveSupport::TestCase | |||
| 936 | I18n.t("activerecord.errors.models.node.attributes.base.trash_the_trash") | 936 | I18n.t("activerecord.errors.models.node.attributes.base.trash_the_trash") |
| 937 | end | 937 | end |
| 938 | end | 938 | end |
| 939 | |||
| 940 | test "restricted? covers the root node, the restricted subtrees and their descendants" do | ||
| 941 | assert Node.root.restricted?, "the front page aggregates the feed" | ||
| 942 | |||
| 943 | updates = Node.root.children.create!(:slug => "updates") | ||
| 944 | assert updates.restricted? | ||
| 945 | year = updates.children.create!(:slug => "2026") | ||
| 946 | assert year.reload.restricted? | ||
| 947 | post = year.children.create!(:slug => "some-post") | ||
| 948 | assert post.reload.restricted? | ||
| 949 | |||
| 950 | disclosure = Node.root.children.create!(:slug => "disclosure") | ||
| 951 | assert disclosure.restricted? | ||
| 952 | |||
| 953 | plain = Node.root.children.create!(:slug => "club") | ||
| 954 | assert_not plain.restricted? | ||
| 955 | child = plain.children.create!(:slug => "erfas") | ||
| 956 | assert_not child.reload.restricted? | ||
| 957 | end | ||
| 958 | |||
| 959 | test "restricted? does not match a prefix that is merely a substring" do | ||
| 960 | decoy = Node.root.children.create!(:slug => "updatesomething") | ||
| 961 | assert_not decoy.restricted? | ||
| 962 | end | ||
| 963 | |||
| 964 | test "publishing a restricted node is refused without the redaktion role" do | ||
| 965 | editor = User.create!(:login => "guard_editor", :email => "gd@example.com", | ||
| 966 | :password => "secret", :password_confirmation => "secret") | ||
| 967 | updates = Node.root.children.create!(:slug => "updates") | ||
| 968 | node = updates.children.create!(:slug => "guarded-post") | ||
| 969 | node.reload.draft.update!(:title => "Entwurf") | ||
| 970 | |||
| 971 | error = assert_raises(ActiveRecord::RecordInvalid) { node.publish_draft!(editor) } | ||
| 972 | assert_includes error.message, | ||
| 973 | I18n.t("activerecord.errors.models.node.attributes.base.not_permitted") | ||
| 974 | assert_nil node.reload.head | ||
| 975 | end | ||
| 976 | |||
| 977 | test "publishing a restricted node succeeds with the redaktion role" do | ||
| 978 | red = User.create!(:login => "guard_red", :email => "gr2@example.com", | ||
| 979 | :password => "secret", :password_confirmation => "secret", | ||
| 980 | :roles => ["redaktion"]) | ||
| 981 | updates = Node.root.children.create!(:slug => "updates") | ||
| 982 | node = updates.children.create!(:slug => "allowed-post") | ||
| 983 | node.reload.draft.update!(:title => "Entwurf") | ||
| 984 | |||
| 985 | node.publish_draft!(red) | ||
| 986 | assert_not_nil node.reload.head | ||
| 987 | end | ||
| 988 | |||
| 989 | test "publishing outside the restricted subtrees needs no role" do | ||
| 990 | editor = User.create!(:login => "guard_free", :email => "gf@example.com", | ||
| 991 | :password => "secret", :password_confirmation => "secret") | ||
| 992 | node = Node.root.children.create!(:slug => "guard-free-post") | ||
| 993 | node.reload.draft.update!(:title => "Entwurf") | ||
| 994 | |||
| 995 | node.publish_draft!(editor) | ||
| 996 | assert_not_nil node.reload.head | ||
| 997 | end | ||
| 998 | |||
| 999 | test "a nil user is a system context and bypasses the gate" do | ||
| 1000 | updates = Node.root.children.create!(:slug => "updates") | ||
| 1001 | node = updates.children.create!(:slug => "system-post") | ||
| 1002 | node.reload.draft.update!(:title => "Entwurf") | ||
| 1003 | |||
| 1004 | node.publish_draft! | ||
| 1005 | assert_not_nil node.reload.head | ||
| 1006 | end | ||
| 939 | end | 1007 | end |
diff --git a/test/models/user_test.rb b/test/models/user_test.rb index feccce25..9942385c 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb | |||
| @@ -126,6 +126,22 @@ class UserTest < ActiveSupport::TestCase | |||
| 126 | 126 | ||
| 127 | assert user.update(:email => "quentin@example.org") | 127 | assert user.update(:email => "quentin@example.org") |
| 128 | end | 128 | end |
| 129 | |||
| 130 | test "may_change_live? gates restricted subjects on the redaktion role" do | ||
| 131 | editor = User.create!(:login => "gate_editor", :email => "ge@example.com", | ||
| 132 | :password => "secret", :password_confirmation => "secret") | ||
| 133 | redaktion = User.create!(:login => "gate_red", :email => "gr@example.com", | ||
| 134 | :password => "secret", :password_confirmation => "secret", | ||
| 135 | :roles => ["redaktion"]) | ||
| 136 | |||
| 137 | restricted = Node.root | ||
| 138 | plain = Node.root.children.create!(:slug => "gate_plain") | ||
| 139 | |||
| 140 | assert editor.may_change_live?(plain) | ||
| 141 | assert_not editor.may_change_live?(restricted) | ||
| 142 | assert redaktion.may_change_live?(plain) | ||
| 143 | assert redaktion.may_change_live?(restricted) | ||
| 144 | end | ||
| 129 | 145 | ||
| 130 | protected | 146 | protected |
| 131 | def create_user(options = {}) | 147 | def create_user(options = {}) |
