@Test public void testGetNotExistingProperty() throws RepositoryException, NotExecutableException { String hint = "Fullname"; String propName = hint; int i = 0; while (user.hasProperty(propName)) { propName = hint + i; i++; } assertNull(user.getProperty(propName)); assertFalse(user.hasProperty(propName)); }
@Test public void testHasPropertyByInvalidRelativePath() throws NotExecutableException, RepositoryException { List<String> wrongPaths = new ArrayList<String>(); wrongPaths.add("../jcr:primaryType"); wrongPaths.add("../../jcr:primaryType"); wrongPaths.add("../testing/jcr:primaryType"); for (String path : wrongPaths) { assertFalse(user.hasProperty(path)); } List<String> invalidPaths = new ArrayList<String>(); invalidPaths.add(".."); invalidPaths.add("."); invalidPaths.add(null); for (String invalidPath : invalidPaths) { try { assertFalse(user.hasProperty(invalidPath)); } catch (RepositoryException e) { // success } } }
@Test public void testRemoveNotExistingProperty() throws RepositoryException, NotExecutableException { String hint = "Fullname"; String propName = hint; int i = 0; while (user.hasProperty(propName)) { propName = hint + i; i++; } assertFalse(user.removeProperty(propName)); superuser.save(); }
@Test public void testSetPropertyByRelPath() throws NotExecutableException, RepositoryException { Value[] v = new Value[] {superuser.getValueFactory().createValue("Super User")}; List<String> relPaths = new ArrayList<String>(); relPaths.add("testing/Fullname"); relPaths.add("testing/Email"); relPaths.add("testing/testing/testing/Fullname"); relPaths.add("testing/testing/testing/Email"); for (String relPath : relPaths) { try { user.setProperty(relPath, v); superuser.save(); assertTrue(user.hasProperty(relPath)); String propName = Text.getName(relPath); assertFalse(user.hasProperty(propName)); } finally { // try to remove the property even if previous calls failed. user.removeProperty(relPath); superuser.save(); } } }
assertTrue(user.hasProperty(propName)); assertTrue(user.hasProperty("./" + propName)); assertFalse(user.hasProperty(propName));
@Test public void testSetNullPropertyRemoves() throws RepositoryException, NotExecutableException { Value v = superuser.getValueFactory().createValue("testValue"); try { user.setProperty("testProperty", v); user.setProperty("testMvProperty", new Value[] {v}); superuser.save(); } catch (RepositoryException e) { throw new NotExecutableException("Cannot test 'Authorizable.setProperty'."); } user.setProperty("testProperty", (Value) null); assertFalse(user.hasProperty("testProperty")); user.setProperty("testMvProperty", (Value[]) null); assertFalse(user.hasProperty("testMvProperty")); }
String rp = "testing/" + name; assertFalse(user.hasProperty(name)); assertNull(user.getProperty(name)); assertTrue(user.hasProperty(rp)); assertNotNull(user.getProperty(rp)); String rp = "testing/" + name; assertFalse(user.hasProperty(name)); assertNull(user.getProperty(name)); assertTrue(user.hasProperty(rp)); assertNotNull(user.getProperty(rp));
@Test public void testGetPropertyNames() throws NotExecutableException, RepositoryException { String propName = "Fullname"; Value v = superuser.getValueFactory().createValue("Super User"); try { user.setProperty(propName, v); superuser.save(); } catch (RepositoryException e) { throw new NotExecutableException("Cannot test 'Authorizable.setProperty'."); } try { for (Iterator<String> it = user.getPropertyNames(); it.hasNext();) { String name = it.next(); assertTrue(user.hasProperty(name)); assertNotNull(user.getProperty(name)); } } finally { // try to remove the property again even if previous calls failed. user.removeProperty(propName); superuser.save(); } }
assertTrue(user.hasProperty(propName)); assertTrue(user.hasProperty("./" + propName)); assertFalse(user.hasProperty(propName));
assertTrue(testUser.hasProperty(relPath)); assertFalse(testUser.hasProperty(relPath)); assertFalse(testUser.hasProperty(relPath));
@Test public void testCreateUser() throws Exception { String newUserId = "newuser" + UUID.randomUUID(); User user = null; try { user = getUserManager(root).createUser(newUserId, newUserId); root.commit(); assertFalse(root.getTree(user.getPath()).hasChild(UserConstants.REP_PWD)); assertFalse(user.hasProperty(UserConstants.REP_PWD + "/" + UserConstants.REP_PASSWORD_LAST_MODIFIED)); } finally { if (user != null) { user.remove(); root.commit(); } } }
@Test public void testCreateUser() throws Exception { String newUserId = "newuser" + UUID.randomUUID(); User user = null; try { user = getUserManager(root).createUser(newUserId, newUserId); root.commit(); assertFalse(root.getTree(user.getPath()).hasChild(UserConstants.REP_PWD)); assertFalse(user.hasProperty(UserConstants.REP_PWD + "/" + UserConstants.REP_PASSWORD_LAST_MODIFIED)); } finally { if (user != null) { user.remove(); root.commit(); } } }
@Test public void testUserGetProperties() throws RepositoryException, NotExecutableException { Node n = getNode(user, superuser); for (PropertyIterator it = n.getProperties(); it.hasNext();) { Property p = it.nextProperty(); if (p.getDefinition().isProtected()) { assertFalse(user.hasProperty(p.getName())); assertNull(user.getProperty(p.getName())); } else { // authorizable defined property assertTrue(user.hasProperty(p.getName())); assertNotNull(user.getProperty(p.getName())); } } }
/** * Test related to OAK-1922: Asserting that the default behavior is such that * no rep:pwd node is created upon user-creation. * * @since Oak 1.1 */ @Test public void testNewUserHasNoPwdNode() throws Exception { String newUserId = "newuser" + UUID.randomUUID(); User user = null; try { user = getUserManager(root).createUser(newUserId, newUserId); root.commit(); Assert.assertFalse(root.getTree(user.getPath()).hasChild(UserConstants.REP_PWD)); Assert.assertFalse(user.hasProperty(UserConstants.REP_PWD + "/" + UserConstants.REP_PASSWORD_LAST_MODIFIED)); } finally { if (user != null) { user.remove(); root.commit(); } } } }
assertFalse(u2.hasProperty(propertyName1)); assertTrue(u2.hasProperty(propertyName1)); assertEquals(value.getString(), u2.getProperty(propertyName1)[0].getString());
@Test public void testDisableRemovesProfiles() throws Exception { User user = getTestUser(); ValueFactory vf = getValueFactory(); user.setProperty("any", vf.createValue("value")); user.setProperty("profiles/public/nickname", vf.createValue("amal")); user.setProperty("profiles/private/age", vf.createValue(14)); root.commit(); user.disable("disabled"); assertTrue(user.hasProperty("any")); assertFalse(user.hasProperty("profiles/public/nickname")); assertFalse(user.hasProperty("profiles/private/age")); Tree t = root.getTree(user.getPath()); assertTrue(t.hasProperty(UserConstants.REP_DISABLED)); assertFalse(t.hasChild("profiles")); // it's transient: root.refresh(); t = root.getTree(user.getPath()); assertFalse(t.hasProperty(UserConstants.REP_DISABLED)); assertTrue(t.hasChild("profiles")); }
assertTrue(user.hasProperty(ExternalIdentityConstants.REP_LAST_SYNCED)); assertFalse(user.hasProperty(ExternalIdentityConstants.REP_EXTERNAL_PRINCIPAL_NAMES));
@Test public void testUserNode() throws Exception { Tree pwdTree = root.getTree(user.getPath()).getChild(UserConstants.REP_PWD); assertTrue(pwdTree.exists()); assertTrue(TreeUtil.isNodeType(pwdTree, UserConstants.NT_REP_PASSWORD, root.getTree(NodeTypeConstants.NODE_TYPES_PATH))); ReadOnlyNodeTypeManager ntMgr = ReadOnlyNodeTypeManager.getInstance(root, getNamePathMapper()); assertTrue(ntMgr.getDefinition(pwdTree.getParent(), pwdTree).isProtected()); PropertyState property = pwdTree.getProperty(UserConstants.REP_PASSWORD_LAST_MODIFIED); assertNotNull(property); assertEquals(Type.LONG, property.getType()); assertTrue(property.getValue(Type.LONG, 0) > 0); // protected properties must not be exposed by User#hasProperty assertFalse(user.hasProperty(UserConstants.REP_PWD + "/" + UserConstants.REP_PASSWORD_LAST_MODIFIED)); }
@Test public void testCreateUser() throws Exception { String newUserId = "newuser" + UUID.randomUUID(); User user = null; try { user = getUserManager(root).createUser(newUserId, newUserId); root.commit(); Tree pwdTree = root.getTree(user.getPath()).getChild(UserConstants.REP_PWD); assertTrue(pwdTree.exists()); assertTrue(TreeUtil.isNodeType(pwdTree, UserConstants.NT_REP_PASSWORD, root.getTree(NodeTypeConstants.NODE_TYPES_PATH))); ReadOnlyNodeTypeManager ntMgr = ReadOnlyNodeTypeManager.getInstance(root, getNamePathMapper()); assertTrue(ntMgr.getDefinition(pwdTree.getParent(), pwdTree).isProtected()); PropertyState property = pwdTree.getProperty(UserConstants.REP_PASSWORD_LAST_MODIFIED); assertNotNull(property); assertEquals(Type.LONG, property.getType()); assertTrue(property.getValue(Type.LONG, 0) > 0); // protected properties must not be exposed by User#hasProperty assertFalse(user.hasProperty(UserConstants.REP_PWD + "/" + UserConstants.REP_PASSWORD_LAST_MODIFIED)); } finally { if (user != null) { user.remove(); root.commit(); } } }