Skip to content

Commit

Permalink
OAK-10334: Node.addMixin() may overwrite existing mixins
Browse files Browse the repository at this point in the history
Test reproducing issue with jcr:mixinTypes
  • Loading branch information
mreutegg committed Jun 30, 2023
1 parent 5636660 commit 2c83efb
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,26 @@
package org.apache.jackrabbit.oak.jcr.security.authorization;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import javax.jcr.AccessDeniedException;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.PropertyIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Value;

import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants;
import org.junit.Test;

import static org.apache.jackrabbit.JcrConstants.MIX_REFERENCEABLE;
import static org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.AccessControlConstants.MIX_REP_ACCESS_CONTROLLABLE;

/**
* @since OAK 1.0 : jcr:read is an aggregation of read property and node privileges.
*/
Expand Down Expand Up @@ -180,4 +191,37 @@ public void testGetStatus() throws Exception {
assertFalse(p.isNew());
}
}

@Test
public void testAddMixinType() throws Exception {
superuser.getNode(path).addMixin(MIX_REFERENCEABLE);
superuser.save();

deny(path, privilegesFromName(PrivilegeConstants.JCR_READ));
allow(path, privilegesFromName(PrivilegeConstants.REP_READ_NODES));
allow(path, privilegesFromName(PrivilegeConstants.REP_WRITE));

assertMixinTypes(superuser.getNode(path), MIX_REFERENCEABLE, MIX_REP_ACCESS_CONTROLLABLE);

Node node = testSession.getNode(path);
assertFalse(node.hasProperty(JcrConstants.JCR_MIXINTYPES));
node.addMixin("mix:title");
testSession.save();

superuser.refresh(false);
// OAK-10334 - FIXME: fails, because it only returns mix:title
// assertMixinTypes(superuser.getNode(path), MIX_REFERENCEABLE, MIX_REP_ACCESS_CONTROLLABLE, "mix:title");
}

private void assertMixinTypes(Node node, String... mixins)
throws RepositoryException {
Set<String> expected = Arrays.stream(mixins).collect(Collectors.toSet());
Set<String> actual = new HashSet<>();
if (node.hasProperty(JcrConstants.JCR_MIXINTYPES)) {
for (Value v : node.getProperty(JcrConstants.JCR_MIXINTYPES).getValues()) {
actual.add(v.getString());
}
}
assertEquals(expected, actual);
}
}

0 comments on commit 2c83efb

Please sign in to comment.