@Test public void testMissingPrivilegeBits() { try { createPrivilegeTree("test"); root.commit(); fail("Missing privilege bits property must be detected."); } catch (CommitFailedException e) { // success assertTrue(e.isConstraintViolation()); } finally { root.refresh(); } }
@Test public void testPropertyDeleted() throws Exception { try { PropertyState before = PropertyStates.createProperty(REP_AGGREGATES, ImmutableList.of(REP_READ_NODES, REP_READ_PROPERTIES), Type.NAMES); PrivilegeValidator validator = new PrivilegeValidator(root, root, getTreeProvider()); validator.propertyDeleted(before); fail("removing property from privilege store must fail."); } catch (CommitFailedException e) { // success assertTrue(e.isConstraintViolation()); assertEquals(46, e.getCode()); } }
@Test public void testPropertyChanged() throws Exception { try { PropertyState before = PropertyStates.createProperty(REP_AGGREGATES, ImmutableList.of(REP_READ_NODES, REP_READ_PROPERTIES), Type.NAMES); PropertyState after = PropertyStates.createProperty(REP_AGGREGATES, ImmutableList.of(REP_READ_NODES), Type.NAMES); PrivilegeValidator validator = new PrivilegeValidator(root, root, getTreeProvider()); validator.propertyChanged(before, after); fail("modifying property in privilege store must fail."); } catch (CommitFailedException e) { // success assertTrue(e.isConstraintViolation()); assertEquals(45, e.getCode()); } }
@Test public void testChildNodeDeleted() { try { root.getTree(PRIVILEGES_PATH).getChild(JCR_READ).remove(); root.commit(); fail("removing privilege from privilege store must fail."); } catch (CommitFailedException e) { // success assertTrue(e.isConstraintViolation()); assertEquals(42, e.getCode()); } }
@Test public void testChangeNext() { try { setPrivilegeBits(bitsProvider.getPrivilegesTree(), REP_NEXT, 1); root.commit(); fail("Outdated rep:next property must be detected."); } catch (CommitFailedException e) { // success assertTrue(e.isConstraintViolation()); assertEquals(43, e.getCode()); } finally { root.refresh(); } }
@Test public void testPrivBitsMissing() { try { NodeState newDef = new MemoryNodeBuilder(EmptyNodeState.EMPTY_NODE) .setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PRIVILEGE) .getNodeState(); PrivilegeValidator validator = createPrivilegeValidator(); validator.childNodeAdded("test", newDef); fail("missing priv bits must be detected."); } catch (CommitFailedException e) { assertTrue(e.isConstraintViolation()); assertEquals(48, e.getCode()); } }
@Test public void testSingularAggregation() { try { Tree privTree = createPrivilegeTree("test"); privTree.setProperty(PropertyStates.createProperty(REP_AGGREGATES, Collections.singletonList(JCR_READ), Type.NAMES)); PrivilegeBits.getInstance(bitsProvider.getBits(JCR_READ)).writeTo(privTree); root.commit(); fail("Aggregation of a single privilege is invalid."); } catch (CommitFailedException e) { // success assertTrue(e.isConstraintViolation()); assertEquals(50, e.getCode()); } finally { root.refresh(); } }
@Test public void testBitsConflict() { try { Tree privTree = createPrivilegeTree("test"); bitsProvider.getBits(JCR_READ).writeTo(privTree); root.commit(); fail("Conflicting privilege bits property must be detected."); } catch (CommitFailedException e) { // success assertTrue(e.isConstraintViolation()); assertEquals(49, e.getCode()); } finally { root.refresh(); } }
@Test public void testNextNotUpdated() { try { Tree privTree = createPrivilegeTree("test"); PrivilegeBits.getInstance(privilegesTree).writeTo(privTree); root.commit(); fail("Outdated rep:next property must be detected."); } catch (CommitFailedException e) { // success assertTrue(e.isConstraintViolation()); assertEquals(43, e.getCode()); } finally { root.refresh(); } }
@Test public void testModifyRepExternalId() throws Exception { try { root.getTree(externalUserPath).setProperty(ExternalIdentityConstants.REP_EXTERNAL_ID, "anotherValue"); root.commit(); fail("Modification of rep:externalId must be detected in the default setup."); } catch (CommitFailedException e) { // success: verify nature of the exception assertTrue(e.isConstraintViolation()); assertEquals(74, e.getCode()); } }
@Test public void testAddRepExternalId() throws Exception { try { root.getTree(testUserPath).setProperty(ExternalIdentityConstants.REP_EXTERNAL_ID, "id"); root.commit(); fail("Adding rep:externalId must be detected in the default setup."); } catch (CommitFailedException e) { // success: verify nature of the exception assertTrue(e.isConstraintViolation()); assertEquals(74, e.getCode()); } }
@Test public void testRemoveRepExternalId() { try { root.getTree(externalUserPath).removeProperty(ExternalIdentityConstants.REP_EXTERNAL_ID); root.commit(); fail("Removal of rep:externalId must be detected in the default setup."); } catch (CommitFailedException e) { // success: verify nature of the exception assertTrue(e.isConstraintViolation()); assertEquals(73, e.getCode()); } }
@Override @Test public void testRemoveRepExternalId() { try { root.getTree(externalUserPath).removeProperty(ExternalIdentityConstants.REP_EXTERNAL_ID); root.commit(); fail("Removal of rep:externalId must be detected in the default setup."); } catch (CommitFailedException e) { // success: verify nature of the exception assertTrue(e.isConstraintViolation()); assertEquals(74, e.getCode()); } }
@Test public void addNamedPropertyWithBadRequiredType() { EditorHook hook = new EditorHook(new TypeEditorProvider()); NodeState root = INITIAL_CONTENT; NodeBuilder builder = root.builder(); NodeState before = builder.getNodeState(); NodeBuilder testNode = builder.child("testNode"); testNode.setProperty(JCR_PRIMARYTYPE, NT_FOLDER, Type.NAME); testNode.setProperty(JCR_MIXINTYPES, ImmutableList.of("mix:title"), Type.NAMES); testNode.setProperty("jcr:title", true); try { hook.processCommit(before, builder.getNodeState(), CommitInfo.EMPTY); fail(); } catch (CommitFailedException e) { assertTrue(e.isConstraintViolation()); } }
@Test public void testCreateCacheByName() throws RepositoryException { for (Authorizable a : authorizables) { try { NodeUtil node = new NodeUtil(getAuthorizableTree(a)); node.addChild(CacheConstants.REP_CACHE, JcrConstants.NT_UNSTRUCTURED); root.commit(); fail("Creating rep:cache node below a user or group must fail."); } catch (CommitFailedException e) { assertTrue(e.isConstraintViolation()); assertEquals(34, e.getCode()); } finally { root.refresh(); } } }
@Test public void testRemoveRepExternalIdWithoutPrincipalNames() throws Exception { Root systemRoot = getSystemRoot(); systemRoot.getTree(testUserPath).setProperty(ExternalIdentityConstants.REP_EXTERNAL_ID, "id"); systemRoot.commit(); root.refresh(); try { root.getTree(testUserPath).removeProperty(ExternalIdentityConstants.REP_EXTERNAL_ID); root.commit(); fail("Removal of rep:externalId must be detected in the default setup."); } catch (CommitFailedException e) { // success: verify nature of the exception assertTrue(e.isConstraintViolation()); assertEquals(74, e.getCode()); } }
@Test public void testNestedCache() throws Exception { NodeUtil cache = new NodeUtil(getCache(getTestUser())); try { NodeUtil c = cache.getOrAddChild(CacheConstants.REP_CACHE, CacheConstants.NT_REP_CACHE); c.setLong(CacheConstants.REP_EXPIRATION, 223); root.commit(CacheValidatorProvider.asCommitAttributes()); fail("Creating nested cache must fail."); } catch (CommitFailedException e) { assertTrue(e.isConstraintViolation()); assertEquals(34, e.getCode()); } finally { root.refresh(); } }
@Test public void changeNodeTypeNewBroken() throws CommitFailedException { EditorHook hook = new EditorHook(new TypeEditorProvider()); NodeState root = INITIAL_CONTENT; NodeBuilder builder = root.builder(); NodeState before = builder.getNodeState(); builder.child("testcontent").setProperty(JCR_PRIMARYTYPE, "nt:folder", Type.NAME); builder.child("testcontent").setProperty("extra", "information"); try { hook.processCommit(before, builder.getNodeState(), CommitInfo.EMPTY); fail("should not be able to change node type due to extra properties"); } catch (CommitFailedException e) { assertTrue(e.isConstraintViolation()); } }
@Test public void testCreateCacheBelowProfile() throws Exception { try { NodeUtil node = new NodeUtil(getAuthorizableTree(getTestUser())); NodeUtil child = node.addChild("profile", NodeTypeConstants.NT_OAK_UNSTRUCTURED); child.addChild(CacheConstants.REP_CACHE, CacheConstants.NT_REP_CACHE).setLong(CacheConstants.REP_EXPIRATION, 23); root.commit(CacheValidatorProvider.asCommitAttributes()); fail("Creating rep:cache node below a user or group must fail."); } catch (CommitFailedException e) { assertTrue(e.isConstraintViolation()); assertEquals(34, e.getCode()); } finally { root.refresh(); } }
@Test public void testUniqueConstraintSubsequentCommit() throws Exception { SyncResult res = syncCtx.sync(idp.getUser(USER_ID)); r.commit(); try { Tree t = r.getTree(getTestUser().getPath()); t.setProperty(DefaultSyncContext.REP_EXTERNAL_ID, res.getIdentity().getExternalIdRef().getString()); r.commit(); fail("Duplicate value for rep:externalId must be detected in the default setup."); } catch (CommitFailedException e) { // success: verify nature of the exception assertTrue(e.isConstraintViolation()); assertEquals(30, e.getCode()); } finally { r.refresh(); } }