protected void createUsers(@NotNull UserManager userManager) throws Exception { for (int i = 0; i <= numberOfMembers; i++) { String id = USER + i; User u = userManager.createUser(id, null, new PrincipalImpl(id), REL_TEST_PATH); userPaths.add(u.getPath()); } }
@Override protected void createUsers(@NotNull UserManager userManager) throws Exception { for (int i = 0; i <= numberOfMembers; i++) { String id = USER + i; User u = userManager.createUser(id, null, new PrincipalImpl(id), REL_TEST_PATH); userPaths.add(u.getPath()); } }
@NotNull User createUser() throws RepositoryException { String userId = "testUser" + testUsers.size(); User usr = userMgr.createUser(userId, "pw"); testUsers.add(usr.getPath()); return usr; }
@Nullable private Long getPasswordLastModified(User user) throws RepositoryException { Tree userTree; if (user instanceof UserImpl) { userTree = ((UserImpl) user).getTree(); } else { userTree = root.getTree(user.getPath()); } PropertyState property = userTree.getChild(REP_PWD).getProperty(REP_PASSWORD_LAST_MODIFIED); return (property != null) ? property.getValue(Type.LONG) : null; }
@Before public void before() throws Exception { pwChangeAction = new PasswordChangeAction(); pwChangeAction.init(Mockito.mock(SecurityProvider.class), ConfigurationParameters.EMPTY); user = Mockito.mock(User.class); when(user.getPath()).thenReturn(USER_PATH); }
@NotNull private List<String> getHistory(@NotNull User user) throws RepositoryException { return ImmutableList.copyOf(TreeUtil.getStrings( root.getTree(user.getPath()).getChild(REP_PWD), REP_PWD_HISTORY)).reverse(); }
@Test public void testCreateUserWithAbsolutePath3() throws Exception { String userRoot = UserConstants.DEFAULT_USER_PATH + '/' + UserConstants.DEFAULT_SYSTEM_RELATIVE_PATH; String path = userRoot + "/any/path/to/the/new/user"; assertTrue(createUser(path).getPath().startsWith(path)); }
@Test public void testCreateUserWithRelativePath() throws RepositoryException, NotExecutableException { Principal p = getTestPrincipal(); String uid = p.getName(); User user = createUser(uid, "pw", p, "any/path"); createdUsers.add(user); assertNotNull(user.getID()); assertTrue(user.getPath().contains("any/path")); }
@Before public void before() throws Exception { super.before(); userPath = getTestUser().getPath(); }
@Test public void testGetPath() throws RepositoryException, NotExecutableException { assertNotNull(user.getPath()); assertNotNull(userMgr.getAuthorizable(user.getID()).getPath()); try { assertEquals(getNode(user, superuser).getPath(), user.getPath()); } catch (UnsupportedRepositoryOperationException e) { // ok. } }
@Test public void testGetAuthorizableByPath2() throws Exception { try { getUserManager(session).getAuthorizableByPath(user.getPath()); fail("invalid path must be detected"); } catch (RepositoryException e) { // success } }
public void testGetUserByPath() throws Exception { user = createUser(uid); Authorizable authorizable = userMgr.getAuthorizableByPath(user.getPath()); assertNotNull(authorizable); assertFalse(authorizable.isGroup()); assertFalse(((User) authorizable).isAdmin()); assertTrue(((User) authorizable).isSystemUser()); assertEquals(user.getPath(), authorizable.getPath()); }
@Test public void testGetPasswordHash() throws Exception { User user = userMgr.createUser(testUserId, null); root.commit(); Tree userTree = root.getTree(user.getPath()); assertNull(userTree.getProperty(UserConstants.REP_PASSWORD)); }
@Test public void testSystemUserTree() throws Exception { Tree t = root.getTree(createUser(null).getPath()); assertFalse(t.hasProperty(UserConstants.REP_PASSWORD)); assertEquals(UserConstants.NT_REP_SYSTEM_USER, TreeUtil.getPrimaryTypeName(t)); }
@Test public void testSetPassword() throws RepositoryException, CommitFailedException { systemUser.changePassword(ExerciseUtility.TEST_PW); Tree systemUserTree = root.getTree(systemUser.getPath()); String expectedPw = null; // EXERCISE assertEquals(expectedPw, TreeUtil.getString(systemUserTree, UserConstants.REP_PASSWORD)); systemUserTree.setProperty(UserConstants.REP_PASSWORD, "anotherPw"); root.commit(); }
@Test public void testCreateUserWithRepExternalIdAsSystem() throws Exception { Root systemRoot = getSystemRoot(); User u = getUserManager(systemRoot).createUser(TestIdentityProvider.ID_SECOND_USER, null); systemRoot.getTree(u.getPath()).setProperty(ExternalIdentityConstants.REP_EXTERNAL_ID, TestIdentityProvider.ID_SECOND_USER); systemRoot.commit(); }
@Test public void testRandomAuthorizableNodeName() throws RepositoryException { // EXERCISE: uncomment the setup in 'getSecurityConfigParameters' before running this test. // verify that the configuration is correct: AuthorizableNodeName configured = getUserConfiguration().getParameters().getConfigValue(UserConstants.PARAM_AUTHORIZABLE_NODE_NAME, AuthorizableNodeName.DEFAULT); assertNotSame(AuthorizableNodeName.DEFAULT, configured); assertTrue(configured instanceof RandomAuthorizableNodeName); testUser = userManager.createUser("test/:User", null); String nodeName = Text.getName(testUser.getPath()); // EXERCISE: write the correct assertion wrt the generated node name. } }
@Test public void testSystemUserNode() throws RepositoryException { Tree systemUserTree = root.getTree(systemUser.getPath()); assertTrue(systemUserTree.exists()); String expectedPrimaryTypeName = null; // EXERCISE assertEquals(expectedPrimaryTypeName, TreeUtil.getPrimaryTypeName(systemUserTree)); String expectedId = null; // EXERCISE assertEquals(expectedId, TreeUtil.getString(systemUserTree, UserConstants.REP_AUTHORIZABLE_ID)); String expectedPw = null; // EXERCISE assertEquals(expectedPw, TreeUtil.getString(systemUserTree, UserConstants.REP_PASSWORD)); }
@Test public void testByDefaultAdminHasNoPwNode() throws Exception { User adminUser = getUserManager(root).getAuthorizable(getUserConfiguration().getParameters().getConfigValue(UserConstants.PARAM_ADMIN_ID, UserConstants.DEFAULT_ADMIN_ID), User.class); assertFalse(root.getTree(adminUser.getPath()).getChild(UserConstants.REP_PWD).exists()); } }
@Test public void testOnlySystemCreatesCache() throws Exception { Set<? extends Principal> principals = principalProvider.getPrincipals(getTestUser().getID()); assertPrincipals(principals, EveryonePrincipal.getInstance(), testGroup.getPrincipal(), getTestUser().getPrincipal()); root.refresh(); Tree userTree = root.getTree(getTestUser().getPath()); assertFalse(userTree.hasChild(CacheConstants.REP_CACHE)); }