@@ -0,0 +1,2417 @@
+/**%0A *%0A */%0Apackage de.terrestris.shogun2.security.access.entity;%0A%0Aimport static org.hamcrest.CoreMatchers.equalTo;%0Aimport static org.junit.Assert.assertThat;%0A%0Aimport java.util.Arrays;%0Aimport java.util.HashSet;%0Aimport java.util.Set;%0A%0Aimport org.junit.Test;%0A%0Aimport de.terrestris.shogun2.helper.IdHelper;%0Aimport de.terrestris.shogun2.model.User;%0Aimport de.terrestris.shogun2.model.UserGroup;%0Aimport de.terrestris.shogun2.model.security.Permission;%0A%0A/**%0A * @author Nils B%C3%BChner%0A *%0A */%0Apublic class UserGroupPermissionEvaluatorTest extends%0A%09AbstractSecuredObjectPermissionEvaluatorTest%3CUserGroup%3E %7B%0A%0A%09public UserGroupPermissionEvaluatorTest() %7B%0A%09%09super(UserGroup.class, new UserGroupPermissionEvaluator%3C%3E(), new UserGroup());%0A%09%7D%0A%0A%09@Test%0A%09public void hasPermission_shouldAlwaysGrantReadOnGroupsWhereUserIsMember() throws NoSuchFieldException, IllegalAccessException %7B%0A%09%09Permission readPermission = Permission.READ;%0A%0A%09%09// prepare a user that is member of the group%0A%09%09final User user = new User(%22First name%22, %22Last Name%22, %22accountName%22);%0A%09%09IdHelper.setIdOnPersistentObject(user, 42);%0A%0A%09%09// prepare a secured group%0A%09%09UserGroup userGroup = new UserGroup();%0A%09%09IdHelper.setIdOnPersistentObject(user, 17);%0A%0A%09%09// add the user to the group%0A%09%09userGroup.getMembers().add(user);%0A%0A%09%09// we do not add any permissions to the user, but expect that he is allowed to READ himself%0A%09%09// call method to test%0A%09%09boolean permissionResult = persistentObjectPermissionEvaluator.hasPermission(user , userGroup, readPermission);%0A%0A%09%09assertThat(permissionResult, equalTo(true));%0A%0A%09%7D%0A%0A%09@Test%0A%09public void hasPermission_shouldNeverGrantAdminDeleteOrWriteOnOwnUserObject() throws NoSuchFieldException, IllegalAccessException %7B%0A%0A%09%09// prepare a user that%0A%09%09final User user = new User(%22First name%22, %22Last Name%22, %22accountName%22);%0A%09%09IdHelper.setIdOnPersistentObject(user, 42);%0A%0A%09%09// prepare a secured group%0A%09%09UserGroup userGroup = new UserGroup();%0A%09%09IdHelper.setIdOnPersistentObject(user, 17);%0A%0A%09%09// add the user to the group%0A%09%09userGroup.getMembers().add(user);%0A%0A%09%09Set%3CPermission%3E permissions = new HashSet%3CPermission%3E(Arrays.asList(Permission.values()));%0A%09%09permissions.remove(Permission.READ); // everything but READ%0A%0A%09%09for (Permission permission : permissions) %7B%0A%09%09%09// call method to test%0A%09%09%09boolean permissionResult = persistentObjectPermissionEvaluator.hasPermission(user, userGroup, permission);%0A%0A%09%09%09assertThat(permissionResult, equalTo(false));%0A%09%09%7D%0A%0A%09%7D%0A%0A%7D%0A

Add a test for the UserGroupPermissionEvaluator