diff --git a/bundle/src/main/java/com/adobe/acs/commons/rewriter/impl/XMLParserGenerator.java b/bundle/src/main/java/com/adobe/acs/commons/rewriter/impl/XMLParserGenerator.java index c9d636e695..b671498f23 100644 --- a/bundle/src/main/java/com/adobe/acs/commons/rewriter/impl/XMLParserGenerator.java +++ b/bundle/src/main/java/com/adobe/acs/commons/rewriter/impl/XMLParserGenerator.java @@ -46,7 +46,10 @@ public final class XMLParserGenerator implements Generator { private ContentHandler contentHandler; public XMLParserGenerator() throws ParserConfigurationException, SAXException { - SAXParserFactory factory = SAXParserFactory.newInstance(); + this(SAXParserFactory.newInstance()); + } + + public XMLParserGenerator(final SAXParserFactory factory) throws ParserConfigurationException, SAXException { factory.setNamespaceAware(true); saxParser = factory.newSAXParser(); diff --git a/bundle/src/main/java/com/adobe/acs/commons/rewriter/impl/XMLParserGeneratorFactory.java b/bundle/src/main/java/com/adobe/acs/commons/rewriter/impl/XMLParserGeneratorFactory.java index 9327d70573..5b4ef2a9b3 100644 --- a/bundle/src/main/java/com/adobe/acs/commons/rewriter/impl/XMLParserGeneratorFactory.java +++ b/bundle/src/main/java/com/adobe/acs/commons/rewriter/impl/XMLParserGeneratorFactory.java @@ -19,6 +19,8 @@ */ package com.adobe.acs.commons.rewriter.impl; +import javax.xml.parsers.SAXParserFactory; + import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Property; import org.apache.felix.scr.annotations.Service; @@ -36,12 +38,19 @@ public final class XMLParserGeneratorFactory implements GeneratorFactory { @Override public Generator createGenerator() { + return createGenerator(null); + } + + Generator createGenerator(final SAXParserFactory saxParserFactory) { try { - return new XMLParserGenerator(); + if (saxParserFactory == null) { + return new XMLParserGenerator(); + } else { + return new XMLParserGenerator(saxParserFactory); + } } catch (Exception e) { log.error("Unable to create parser", e); return null; } } - } diff --git a/bundle/src/test/java/com/adobe/acs/commons/rewriter/impl/XMLParserGeneratorTest.java b/bundle/src/test/java/com/adobe/acs/commons/rewriter/impl/XMLParserGeneratorTest.java index 725d6255c5..0511e134bf 100644 --- a/bundle/src/test/java/com/adobe/acs/commons/rewriter/impl/XMLParserGeneratorTest.java +++ b/bundle/src/test/java/com/adobe/acs/commons/rewriter/impl/XMLParserGeneratorTest.java @@ -23,6 +23,11 @@ import java.io.PrintWriter; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; @@ -32,6 +37,9 @@ import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; import org.xml.sax.Locator; +import org.xml.sax.SAXException; +import org.xml.sax.SAXNotRecognizedException; +import org.xml.sax.SAXNotSupportedException; @RunWith(MockitoJUnitRunner.class) public class XMLParserGeneratorTest { @@ -46,13 +54,15 @@ public void test() throws Exception { XMLParserGeneratorFactory factory = new XMLParserGeneratorFactory(); XMLParserGenerator generator = (XMLParserGenerator) factory.createGenerator(); + // nothing to do, nothing to mock... + generator.init(null, null); generator.setContentHandler(contentHandler); - PrintWriter printWriter = generator.getWriter(); printWriter.println(""); printWriter.println(""); generator.finished(); + generator.dispose(); verify(contentHandler).startDocument(); verify(contentHandler).setDocumentLocator((Locator) anyObject()); @@ -66,4 +76,36 @@ public void test() throws Exception { verify(contentHandler).endDocument(); verifyNoMoreInteractions(contentHandler); } + + @Test + public void testParserException() { + SAXParserFactory fakeParserFactory = new SAXParserFactory() { + @Override + public SAXParser newSAXParser() throws ParserConfigurationException, SAXException { + throw new ParserConfigurationException("failers gonna fail."); + } + + @Override + public void setFeature(final String name, final boolean value) + throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException { + } + + @Override + public boolean getFeature(final String name) + throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException { + return false; + } + }; + + XMLParserGeneratorFactory factory = new XMLParserGeneratorFactory(); + XMLParserGenerator generator = (XMLParserGenerator) factory.createGenerator(fakeParserFactory); + Assert.assertNull("generator is null when parser factory throws config exception.", generator); + } + + @Test + public void testOwnParser() { + XMLParserGeneratorFactory factory = new XMLParserGeneratorFactory(); + XMLParserGenerator generator = (XMLParserGenerator) factory.createGenerator(SAXParserFactory.newInstance()); + Assert.assertNotNull("generator is not null with own default sax parser.", generator); + } } diff --git a/oakpal-checks/src/main/java/com/adobe/acs/commons/oakpal/checks/AcsCommonsAuthorizableCompatibilityCheck.java b/oakpal-checks/src/main/java/com/adobe/acs/commons/oakpal/checks/AcsCommonsAuthorizableCompatibilityCheck.java index 32c282e83a..3d9ad42aab 100644 --- a/oakpal-checks/src/main/java/com/adobe/acs/commons/oakpal/checks/AcsCommonsAuthorizableCompatibilityCheck.java +++ b/oakpal-checks/src/main/java/com/adobe/acs/commons/oakpal/checks/AcsCommonsAuthorizableCompatibilityCheck.java @@ -26,7 +26,6 @@ import net.adamcin.oakpal.core.ProgressCheck; import net.adamcin.oakpal.core.ProgressCheckFactory; import net.adamcin.oakpal.core.SimpleProgressCheck; -import net.adamcin.oakpal.core.SimpleViolation; import net.adamcin.oakpal.core.Violation; import net.adamcin.oakpal.core.checks.Rule; import org.apache.jackrabbit.api.JackrabbitSession; @@ -45,20 +44,20 @@ * compatibility check. * */ -public class AcsCommonsAuthorizableCompatibilityCheck implements ProgressCheckFactory { +public final class AcsCommonsAuthorizableCompatibilityCheck implements ProgressCheckFactory { public static final String NT_REP_AUTHORIZABLE = "rep:Authorizable"; public static final String CONFIG_SCOPE_IDS = "scopeIds"; - class Check extends SimpleProgressCheck { + static final class Check extends SimpleProgressCheck { private final List scopeIds; - public Check(final List scopeIds) { + Check(final List scopeIds) { this.scopeIds = scopeIds; } @Override public String getCheckName() { - return AcsCommonsAuthorizableCompatibilityCheck.this.getClass().getSimpleName(); + return AcsCommonsAuthorizableCompatibilityCheck.class.getSimpleName(); } @Override @@ -66,33 +65,26 @@ public void importedPath(final PackageId packageId, final String path, final Nod throws RepositoryException { // fast check for authorizables if (node.isNodeType(NT_REP_AUTHORIZABLE)) { - UserManager userManager = ((JackrabbitSession) node.getSession()).getUserManager(); - Authorizable authz = userManager.getAuthorizableByPath(path); + final UserManager userManager = ((JackrabbitSession) node.getSession()).getUserManager(); + final Authorizable authz = userManager.getAuthorizableByPath(path); // if an authorizable is not loaded from the path, short circuit. - if (authz == null) { - return; - } + if (authz != null) { + final String id = authz.getID(); - final String id = authz.getID(); + // check for inclusion based on authorizableId + Rule lastMatched = Rule.lastMatch(scopeIds, id); - // check for inclusion based on authorizableId - Rule lastMatched = Rule.fuzzyDefaultAllow(scopeIds); - for (Rule scopeId : scopeIds) { - if (scopeId.matches(id)) { - lastMatched = scopeId; + // if id is excluded, short circuit + if (lastMatched.isExclude()) { + return; } - } - // if id is excluded, short circuit - if (lastMatched.isDeny()) { - return; - } - - if (authz.getID().startsWith("acs-commons")) { - reportViolation(new SimpleViolation(Violation.Severity.MAJOR, - String.format("%s: reserved ID prefix [%s]", path, authz.getID()), - packageId)); + if (authz.getID().startsWith("acs-commons")) { + reportViolation(Violation.Severity.MAJOR, + String.format("%s: reserved ID prefix [%s]", path, authz.getID()), + packageId); + } } } } diff --git a/oakpal-checks/src/main/java/com/adobe/acs/commons/oakpal/checks/ContentClassifications.java b/oakpal-checks/src/main/java/com/adobe/acs/commons/oakpal/checks/ContentClassifications.java index c3c3725511..1a7d833797 100644 --- a/oakpal-checks/src/main/java/com/adobe/acs/commons/oakpal/checks/ContentClassifications.java +++ b/oakpal-checks/src/main/java/com/adobe/acs/commons/oakpal/checks/ContentClassifications.java @@ -35,7 +35,6 @@ import net.adamcin.oakpal.core.ProgressCheck; import net.adamcin.oakpal.core.ProgressCheckFactory; import net.adamcin.oakpal.core.SimpleProgressCheck; -import net.adamcin.oakpal.core.SimpleViolation; import net.adamcin.oakpal.core.Violation; import net.adamcin.oakpal.core.checks.Rule; import org.apache.jackrabbit.vault.packaging.PackageId; @@ -94,14 +93,14 @@ public ProgressCheck newInstance(final JSONObject jsonObject) { return new Check(libsPathPrefix, severity, scopePaths, searchPaths); } - class Check extends SimpleProgressCheck { + static final class Check extends SimpleProgressCheck { final String libsPathPrefix; final Violation.Severity severity; final List scopePaths; final List searchPaths; - public Check(final String libsPathPrefix, final Violation.Severity severity, - final List scopePaths, final List searchPaths) { + Check(final String libsPathPrefix, final Violation.Severity severity, + final List scopePaths, final List searchPaths) { this.libsPathPrefix = libsPathPrefix; this.severity = severity; this.scopePaths = scopePaths; @@ -110,7 +109,7 @@ public Check(final String libsPathPrefix, final Violation.Severity severity, @Override public String getCheckName() { - return ContentClassifications.this.getClass().getSimpleName(); + return ContentClassifications.class.getSimpleName(); } @Override @@ -125,15 +124,10 @@ public void importedPath(final PackageId packageId, final String path, final Nod // default to ALLOW ALL // if first rule is allow, change default to DENY ALL - Rule lastMatched = Rule.fuzzyDefaultAllow(scopePaths); - for (Rule rule : scopePaths) { - if (rule.matches(path)) { - lastMatched = rule; - } - } + Rule lastMatched = Rule.lastMatch(scopePaths, path); // if path is denied from scope, short circuit. - if (lastMatched.isDeny()) { + if (lastMatched.isExclude()) { return; } @@ -160,8 +154,8 @@ void checkOverlay(final PackageId packageId, final String path, final Node node) final String libsRt = libsPathPrefix + relPath; assertClassifications(node.getSession(), libsRt, AreaType.ALLOWED_FOR_RESOURCE_SUPER_TYPE) - .ifPresent(message -> reportViolation(new SimpleViolation(severity, - String.format("%s [restricted overlay]: %s", path, message), packageId))); + .ifPresent(message -> reportViolation(severity, + String.format("%s [restricted overlay]: %s", path, message), packageId)); } @@ -178,9 +172,9 @@ void checkResourceType(final PackageId packageId, final String path, final Node } assertClassifications(node.getSession(), libsRt, AreaType.ALLOWED_FOR_RESOURCE_TYPE) - .ifPresent(message -> reportViolation(new SimpleViolation(severity, + .ifPresent(message -> reportViolation(severity, String.format("%s [restricted resource type]: %s", path, message), - packageId))); + packageId)); } } } @@ -198,17 +192,17 @@ void checkResourceSuperType(final PackageId packageId, final String path, final } assertClassifications(node.getSession(), libsRst, AreaType.ALLOWED_FOR_RESOURCE_SUPER_TYPE) - .ifPresent(message -> reportViolation(new SimpleViolation(severity, + .ifPresent(message -> reportViolation(severity, String.format("%s [restricted super type]: %s", path, message), - packageId))); + packageId)); } } } Optional assertClassifications(final Session session, final String libsPath, final Set allowedAreas) throws RepositoryException { - final Node leaf = getLibsLeaf(session, libsPath); - if (leaf != null) { + if (libsPath.startsWith(libsPathPrefix)) { + final Node leaf = getLeafNode(session, libsPath); final AreaType leafArea = AreaType.fromNode(leaf); if (leafArea == AreaType.FINAL && libsPath.startsWith(leaf.getPath() + "/")) { return Optional.of(String.format("%s is implicitly marked %s", libsPath, AreaType.INTERNAL)); @@ -221,22 +215,19 @@ Optional assertClassifications(final Session session, final String libsP return Optional.empty(); } - Node getLibsLeaf(final Session session, final String absPath) throws RepositoryException { + Node getLeafNode(final Session session, final String absPath) throws RepositoryException { if ("/".equals(absPath)) { return session.getRootNode(); - } else if (absPath.startsWith(libsPathPrefix)) { + } else { final String parentPath = Text.getRelativeParent(absPath, 1, true); - Node parent = getLibsLeaf(session, parentPath); - if (parent != null) { - final String name = Text.getName(absPath, true); - if (parent.getPath().equals(parentPath) && parent.hasNode(name)) { - return parent.getNode(name); - } else { - return parent; - } + final Node parent = getLeafNode(session, parentPath); + final String name = Text.getName(absPath, true); + if (parent.getPath().equals(parentPath) && parent.hasNode(name)) { + return parent.getNode(name); + } else { + return parent; } } - return null; } } diff --git a/oakpal-checks/src/main/java/com/adobe/acs/commons/oakpal/checks/RecommendEnsureAuthorizable.java b/oakpal-checks/src/main/java/com/adobe/acs/commons/oakpal/checks/RecommendEnsureAuthorizable.java index 565b315b6c..55e3b495f3 100644 --- a/oakpal-checks/src/main/java/com/adobe/acs/commons/oakpal/checks/RecommendEnsureAuthorizable.java +++ b/oakpal-checks/src/main/java/com/adobe/acs/commons/oakpal/checks/RecommendEnsureAuthorizable.java @@ -26,7 +26,6 @@ import net.adamcin.oakpal.core.ProgressCheck; import net.adamcin.oakpal.core.ProgressCheckFactory; import net.adamcin.oakpal.core.SimpleProgressCheck; -import net.adamcin.oakpal.core.SimpleViolation; import net.adamcin.oakpal.core.Violation; import net.adamcin.oakpal.core.checks.Rule; import org.apache.jackrabbit.api.JackrabbitSession; @@ -51,7 +50,7 @@ *
(default: {@link #DEFAULT_RECOMMENDATION}) provide a recommendation message.
* */ -public class RecommendEnsureAuthorizable implements ProgressCheckFactory { +public final class RecommendEnsureAuthorizable implements ProgressCheckFactory { public static final String NT_REP_AUTHORIZABLE = "rep:Authorizable"; public static final String CONFIG_SEVERITY = "severity"; public static final String CONFIG_RECOMMENDATION = "recommendation"; @@ -67,12 +66,12 @@ public ProgressCheck newInstance(final JSONObject config) throws Exception { return new Check(severity, recommendation, scopeIds); } - class Check extends SimpleProgressCheck { + static final class Check extends SimpleProgressCheck { private final Violation.Severity severity; private final String recommendation; private final List scopeIds; - public Check(final Violation.Severity severity, final String recommendation, final List scopeIds) { + Check(final Violation.Severity severity, final String recommendation, final List scopeIds) { this.severity = severity; this.recommendation = recommendation; this.scopeIds = scopeIds; @@ -80,7 +79,7 @@ public Check(final Violation.Severity severity, final String recommendation, fin @Override public String getCheckName() { - return RecommendEnsureAuthorizable.this.getClass().getSimpleName(); + return RecommendEnsureAuthorizable.class.getSimpleName(); } @Override @@ -88,33 +87,26 @@ public void importedPath(final PackageId packageId, final String path, final Nod throws RepositoryException { // fast check for authorizables if (node.isNodeType(NT_REP_AUTHORIZABLE)) { - UserManager userManager = ((JackrabbitSession) node.getSession()).getUserManager(); - Authorizable authz = userManager.getAuthorizableByPath(path); + final UserManager userManager = ((JackrabbitSession) node.getSession()).getUserManager(); + final Authorizable authz = userManager.getAuthorizableByPath(path); // if an authorizable is not loaded from the path, short circuit. - if (authz == null) { - return; - } + if (authz != null) { + final String id = authz.getID(); - final String id = authz.getID(); + // check for inclusion based on authorizableId + Rule lastMatched = Rule.lastMatch(scopeIds, id); - // check for inclusion based on authorizableId - Rule lastMatched = Rule.fuzzyDefaultAllow(scopeIds); - for (Rule scopeId : scopeIds) { - if (scopeId.matches(id)) { - lastMatched = scopeId; + // if id is excluded, or is user and not system user, short circuit + if (lastMatched.isExclude() || (!authz.isGroup() && !((User) authz).isSystemUser())) { + return; } - } - // if id is excluded, or is user and not system user, short circuit - if (lastMatched.isDeny() || (!authz.isGroup() && !((User) authz).isSystemUser())) { - return; + // report for groups and system users + reportViolation(severity, + String.format("%s: imported explicit %s. %s", + path, authz.isGroup() ? "group" : "system user", recommendation), packageId); } - - // report for groups and system users - reportViolation(new SimpleViolation(severity, - String.format("%s: imported explicit %s. %s", - path, authz.isGroup() ? "group" : "system user", recommendation), packageId)); } } } diff --git a/oakpal-checks/src/main/java/com/adobe/acs/commons/oakpal/checks/RecommendEnsureOakIndex.java b/oakpal-checks/src/main/java/com/adobe/acs/commons/oakpal/checks/RecommendEnsureOakIndex.java index 255aa05933..8464386872 100644 --- a/oakpal-checks/src/main/java/com/adobe/acs/commons/oakpal/checks/RecommendEnsureOakIndex.java +++ b/oakpal-checks/src/main/java/com/adobe/acs/commons/oakpal/checks/RecommendEnsureOakIndex.java @@ -26,7 +26,6 @@ import net.adamcin.oakpal.core.ProgressCheck; import net.adamcin.oakpal.core.ProgressCheckFactory; import net.adamcin.oakpal.core.SimpleProgressCheck; -import net.adamcin.oakpal.core.SimpleViolation; import net.adamcin.oakpal.core.Violation; import net.adamcin.oakpal.core.checks.Rule; import org.apache.jackrabbit.vault.packaging.PackageId; @@ -48,7 +47,7 @@ *
(default: {@link #DEFAULT_RECOMMENDATION}) provide a recommendation message.
* */ -public class RecommendEnsureOakIndex implements ProgressCheckFactory { +public final class RecommendEnsureOakIndex implements ProgressCheckFactory { public static final String NN_OAK_INDEX = "oak:index"; public static final String CONFIG_SEVERITY = "severity"; public static final String CONFIG_RECOMMENDATION = "recommendation"; @@ -64,12 +63,12 @@ public ProgressCheck newInstance(final JSONObject config) throws Exception { return new Check(severity, recommendation, scopePaths); } - class Check extends SimpleProgressCheck { + static final class Check extends SimpleProgressCheck { private final Violation.Severity severity; private final String recommendation; private final List scopePaths; - public Check(final Violation.Severity severity, final String recommendation, final List scopePaths) { + Check(final Violation.Severity severity, final String recommendation, final List scopePaths) { this.severity = severity; this.recommendation = recommendation; this.scopePaths = scopePaths; @@ -77,7 +76,7 @@ public Check(final Violation.Severity severity, final String recommendation, fin @Override public String getCheckName() { - return RecommendEnsureOakIndex.this.getClass().getSimpleName(); + return RecommendEnsureOakIndex.class.getSimpleName(); } @Override @@ -85,23 +84,18 @@ public void importedPath(final PackageId packageId, final String path, final Nod throws RepositoryException { // evaluate scope paths - Rule lastMatched = Rule.fuzzyDefaultAllow(scopePaths); - for (Rule rule : scopePaths) { - if (rule.matches(path)) { - lastMatched = rule; - } - } + Rule lastMatched = Rule.lastMatch(scopePaths, path); // short circuit if out of scope - if (lastMatched.isDeny()) { + if (lastMatched.isExclude()) { return; } // report for every immediate child of an oak:index node. if (NN_OAK_INDEX.equals(node.getParent().getName())) { - reportViolation(new SimpleViolation(severity, + reportViolation(severity, String.format("%s: imported explicit oak:index. %s", - path, recommendation), packageId)); + path, recommendation), packageId); } } } diff --git a/oakpal-checks/src/test/java/com/adobe/acs/commons/oakpal/checks/AcsCommonsAuthorizableCompatibilityCheckTest.java b/oakpal-checks/src/test/java/com/adobe/acs/commons/oakpal/checks/AcsCommonsAuthorizableCompatibilityCheckTest.java index eed58ba7b7..eee34d75f5 100644 --- a/oakpal-checks/src/test/java/com/adobe/acs/commons/oakpal/checks/AcsCommonsAuthorizableCompatibilityCheckTest.java +++ b/oakpal-checks/src/test/java/com/adobe/acs/commons/oakpal/checks/AcsCommonsAuthorizableCompatibilityCheckTest.java @@ -19,12 +19,16 @@ */ package com.adobe.acs.commons.oakpal.checks; +import static net.adamcin.oakpal.core.OrgJson.arr; +import static net.adamcin.oakpal.core.OrgJson.key; +import static net.adamcin.oakpal.core.OrgJson.obj; import static org.junit.Assert.assertEquals; import java.io.File; import net.adamcin.oakpal.core.CheckReport; import net.adamcin.oakpal.core.ProgressCheck; +import net.adamcin.oakpal.core.checks.Rule; import net.adamcin.oakpal.testing.TestPackageUtil; import org.json.JSONObject; import org.junit.Before; @@ -42,23 +46,22 @@ public void setUp() throws Exception { @Test public void testCheckNone() throws Exception { - ProgressCheck check = new AcsCommonsAuthorizableCompatibilityCheck().newInstance( - new JSONObject("{\"scopeIds\":[{\"type\":\"deny\",\"pattern\":\".*\"}]}")); + ProgressCheck check = new AcsCommonsAuthorizableCompatibilityCheck() + .newInstance(key("scopeIds", arr(Rule.DEFAULT_DENY)).get()); CheckReport reportValid = scanWithCheck(check, pack); assertEquals("No violations when deny all authorizable ids.", 0, reportValid.getViolations().size()); } @Test public void testCheckAll() throws Exception { - ProgressCheck check = new AcsCommonsAuthorizableCompatibilityCheck().newInstance( - new JSONObject("{}")); + ProgressCheck check = new AcsCommonsAuthorizableCompatibilityCheck().newInstance(obj().get()); CheckReport reportValid = scanWithCheck(check, pack); assertEquals("3 violations when allow all authorizable ids.", 3, reportValid.getViolations().size()); } private void checkSpecificId(final String authorizableId, final boolean expectValid) throws Exception { ProgressCheck checkValid = new AcsCommonsAuthorizableCompatibilityCheck().newInstance( - new JSONObject(String.format("{\"scopeIds\":[{\"type\":\"allow\",\"pattern\":\"%s\"}]}", authorizableId))); + key("scopeIds", arr(key("type", "allow").key("pattern", authorizableId))).get()); CheckReport reportValid = scanWithCheck(checkValid, pack); assertEquals("check specific authorizableId: " + authorizableId, expectValid ? 0 : 1, reportValid.getViolations().size()); diff --git a/oakpal-checks/src/test/java/com/adobe/acs/commons/oakpal/checks/ContentClassificationsTest.java b/oakpal-checks/src/test/java/com/adobe/acs/commons/oakpal/checks/ContentClassificationsTest.java index 89c67de598..ccc11ef3a0 100644 --- a/oakpal-checks/src/test/java/com/adobe/acs/commons/oakpal/checks/ContentClassificationsTest.java +++ b/oakpal-checks/src/test/java/com/adobe/acs/commons/oakpal/checks/ContentClassificationsTest.java @@ -19,6 +19,9 @@ */ package com.adobe.acs.commons.oakpal.checks; +import static net.adamcin.oakpal.core.OrgJson.arr; +import static net.adamcin.oakpal.core.OrgJson.key; +import static net.adamcin.oakpal.core.OrgJson.obj; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -29,7 +32,6 @@ import net.adamcin.oakpal.core.InitStage; import net.adamcin.oakpal.core.ProgressCheck; import net.adamcin.oakpal.testing.TestPackageUtil; -import org.json.JSONObject; import org.junit.Before; import org.junit.Test; @@ -52,6 +54,8 @@ public class ContentClassificationsTest extends CheckTestBase { "granite:PublicArea") .withForcedRoot("/libs/acs/final", "sling:Folder", "granite:FinalArea") + .withForcedRoot("/libs/acs/final/child", + "sling:Folder") .withForcedRoot("/libs/acs/final/public", "sling:Folder", "granite:PublicArea") .withForcedRoot("/libs/acs/abstract", "sling:Folder", @@ -78,14 +82,19 @@ public void setUp() throws Exception { } private ProgressCheck checkForPath(final String path) { - return new ContentClassifications().newInstance( - new JSONObject(String.format("{\"scopePaths\":[{\"type\":\"allow\",\"pattern\":\"%s\"}]}", path))); + return new ContentClassifications() + .newInstance(key("scopePaths", arr(key("type", "allow").key("pattern", path))).get()); } @Test public void testCheckAllValid() throws Exception { - ProgressCheck checkValid = new ContentClassifications().newInstance( - new JSONObject("{\"scopePaths\":[{\"type\":\"allow\",\"pattern\":\".*/valid.*\"},{\"type\":\"allow\",\"pattern\":\"/apps/acs/(abstract|public).*\"}]}")); + ProgressCheck checkValid = new ContentClassifications() + .newInstance(obj() + .key("scopePaths", arr() + .val(key("type", "allow").key("pattern", ".*/valid.*")) + .val(key("type", "allow").key("pattern", "/apps/acs/(abstract|public).*"))) + .key("searchPaths", arr("/apps", "/libs")) + .get()); CheckReport reportValid = scanWithCheck(checkValid, pack); assertEquals("No violations when deny invalid paths.", 0, reportValid.getViolations().size()); } @@ -94,8 +103,9 @@ private void checkInvalidPath(final String path, final String marked, final Stri ProgressCheck check = checkForPath(path); CheckReport report = scanWithCheck(check, pack); assertEquals(String.format("One violation: %s", description), 1, report.getViolations().size()); - assertTrue(String.format("Violation contains 'marked %s' (actual: %s): %s.", marked, - report.getViolations().iterator().next().getDescription(), description), + assertTrue( + String.format("Violation contains 'marked %s' (actual: %s): %s.", marked, + report.getViolations().iterator().next().getDescription(), description), report.getViolations().iterator().next().getDescription().contains(String.format("marked %s", marked))); } @@ -139,6 +149,11 @@ public void testCheckInvalidPageFinalChild() throws Exception { checkInvalidPath("/content/acs/invalidpage_final_child", "INTERNAL", "use final child"); } + @Test + public void testCheckInvalidPageFinalImplicitChild() throws Exception { + checkInvalidPath("/content/acs/invalidpage_final_implicitchild", "INTERNAL", "use final implicit child"); + } + @Test public void testCheckInvalidPageInternal() throws Exception { checkInvalidPath("/content/acs/invalidpage_internal", "INTERNAL", "use internal"); diff --git a/oakpal-checks/src/test/java/com/adobe/acs/commons/oakpal/checks/RecommendEnsureAuthorizableTest.java b/oakpal-checks/src/test/java/com/adobe/acs/commons/oakpal/checks/RecommendEnsureAuthorizableTest.java index 003caae9f4..067eba4adb 100644 --- a/oakpal-checks/src/test/java/com/adobe/acs/commons/oakpal/checks/RecommendEnsureAuthorizableTest.java +++ b/oakpal-checks/src/test/java/com/adobe/acs/commons/oakpal/checks/RecommendEnsureAuthorizableTest.java @@ -19,12 +19,16 @@ */ package com.adobe.acs.commons.oakpal.checks; +import static net.adamcin.oakpal.core.OrgJson.arr; +import static net.adamcin.oakpal.core.OrgJson.key; +import static net.adamcin.oakpal.core.OrgJson.obj; import static org.junit.Assert.assertEquals; import java.io.File; import net.adamcin.oakpal.core.CheckReport; import net.adamcin.oakpal.core.ProgressCheck; +import net.adamcin.oakpal.core.checks.Rule; import net.adamcin.oakpal.testing.TestPackageUtil; import org.json.JSONObject; import org.junit.Before; @@ -42,23 +46,22 @@ public void setUp() throws Exception { @Test public void testCheckNone() throws Exception { - ProgressCheck check = new RecommendEnsureAuthorizable().newInstance( - new JSONObject("{\"scopeIds\":[{\"type\":\"deny\",\"pattern\":\".*\"}]}")); + ProgressCheck check = new RecommendEnsureAuthorizable() + .newInstance(key("scopeIds", arr(Rule.DEFAULT_DENY)).get()); CheckReport reportValid = scanWithCheck(check, pack); assertEquals("No violations when deny all authorizable ids.", 0, reportValid.getViolations().size()); } @Test public void testCheckAll() throws Exception { - ProgressCheck check = new RecommendEnsureAuthorizable().newInstance( - new JSONObject("{}")); + ProgressCheck check = new RecommendEnsureAuthorizable().newInstance(obj().get()); CheckReport reportValid = scanWithCheck(check, pack); assertEquals("3 violations when allow all authorizable ids.", 3, reportValid.getViolations().size()); } private void checkSpecificId(final String authorizableId, final boolean expectValid) throws Exception { - ProgressCheck checkValid = new RecommendEnsureAuthorizable().newInstance( - new JSONObject(String.format("{\"scopeIds\":[{\"type\":\"allow\",\"pattern\":\"%s\"}]}", authorizableId))); + ProgressCheck checkValid = new RecommendEnsureAuthorizable() + .newInstance(key("scopeIds", arr(key("type", "allow").key("pattern", authorizableId))).get()); CheckReport reportValid = scanWithCheck(checkValid, pack); assertEquals("check specific authorizableId: " + authorizableId, expectValid ? 0 : 1, reportValid.getViolations().size()); diff --git a/oakpal-checks/src/test/java/com/adobe/acs/commons/oakpal/checks/RecommendEnsureOakIndexTest.java b/oakpal-checks/src/test/java/com/adobe/acs/commons/oakpal/checks/RecommendEnsureOakIndexTest.java index a7ace33c7e..975e995bd9 100644 --- a/oakpal-checks/src/test/java/com/adobe/acs/commons/oakpal/checks/RecommendEnsureOakIndexTest.java +++ b/oakpal-checks/src/test/java/com/adobe/acs/commons/oakpal/checks/RecommendEnsureOakIndexTest.java @@ -19,6 +19,9 @@ */ package com.adobe.acs.commons.oakpal.checks; +import static net.adamcin.oakpal.core.OrgJson.arr; +import static net.adamcin.oakpal.core.OrgJson.key; +import static net.adamcin.oakpal.core.OrgJson.obj; import static org.junit.Assert.assertEquals; import java.io.File; @@ -27,6 +30,7 @@ import net.adamcin.oakpal.core.CheckReport; import net.adamcin.oakpal.core.InitStage; import net.adamcin.oakpal.core.ProgressCheck; +import net.adamcin.oakpal.core.checks.Rule; import net.adamcin.oakpal.testing.TestPackageUtil; import org.json.JSONObject; import org.junit.Before; @@ -46,16 +50,15 @@ public void setUp() throws Exception { @Test public void testCheckNone() throws Exception { - ProgressCheck check = new RecommendEnsureOakIndex().newInstance( - new JSONObject("{\"scopePaths\":[{\"type\":\"deny\",\"pattern\":\".*\"}]}")); + ProgressCheck check = new RecommendEnsureOakIndex() + .newInstance(key("scopePaths", arr(Rule.DEFAULT_DENY)).get()); CheckReport reportValid = scanWithCheck(check, pack); assertEquals("No violations when deny all oak:index children.", 0, reportValid.getViolations().size()); } @Test public void testCheckAll() throws Exception { - ProgressCheck check = new RecommendEnsureOakIndex().newInstance( - new JSONObject("{}")); + ProgressCheck check = new RecommendEnsureOakIndex().newInstance(obj().get()); CheckReport reportValid = scanWithCheck(check, pack); assertEquals("3 violations when allow all oak:index children.", 3, reportValid.getViolations().size()); } diff --git a/oakpal-checks/src/test/resources/content-classifications-filevault/META-INF/vault/filter.xml b/oakpal-checks/src/test/resources/content-classifications-filevault/META-INF/vault/filter.xml index f454701031..a6c7ae3762 100644 --- a/oakpal-checks/src/test/resources/content-classifications-filevault/META-INF/vault/filter.xml +++ b/oakpal-checks/src/test/resources/content-classifications-filevault/META-INF/vault/filter.xml @@ -1,5 +1,6 @@ + diff --git a/oakpal-checks/src/test/resources/content-classifications-filevault/jcr_root/content/acs/invalidpage_final_implicitchild/.content.xml b/oakpal-checks/src/test/resources/content-classifications-filevault/jcr_root/content/acs/invalidpage_final_implicitchild/.content.xml new file mode 100644 index 0000000000..499b2b7728 --- /dev/null +++ b/oakpal-checks/src/test/resources/content-classifications-filevault/jcr_root/content/acs/invalidpage_final_implicitchild/.content.xml @@ -0,0 +1,4 @@ + + diff --git a/oakpal-checks/src/test/resources/content-classifications-filevault/jcr_root/libs/out_of_bounds/.content.xml b/oakpal-checks/src/test/resources/content-classifications-filevault/jcr_root/libs/out_of_bounds/.content.xml new file mode 100644 index 0000000000..3d0c31ab4d --- /dev/null +++ b/oakpal-checks/src/test/resources/content-classifications-filevault/jcr_root/libs/out_of_bounds/.content.xml @@ -0,0 +1,3 @@ + + diff --git a/pom.xml b/pom.xml index 4ae4672847..211753902e 100644 --- a/pom.xml +++ b/pom.xml @@ -45,7 +45,7 @@ false 1.7.21 1.26.0 - 1.1.12 + 1.1.13