AcHandling implements ProgressCheckFactory { @Override public ProgressCheck newInstance(final JsonObject config) { if (hasNonNull(config, keys().allowedModes())) { List<AccessControlHandling> allowedModes = mapArrayOfStrings(arrayOrEmpty(config, keys().allowedModes()), compose1(String::toUpperCase, AccessControlHandling::valueOf), true); return new Check(ACHandlingLevelSet.EXPLICIT, allowedModes); } else if (hasNonNull(config, keys().levelSet())) { ACHandlingLevelSet levelSet = ACHandlingLevelSet.valueOf(config.getString(keys().levelSet()).toUpperCase()); return new Check(levelSet, Collections.emptyList()); } else { return new Check(DEFAULT_LEVEL_SET, Collections.emptyList()); } }  static JsonKeys keys(); @Override ProgressCheck newInstance(final JsonObject config); @Deprecated
    static final String CONFIG_ALLOWED_MODES; @Deprecated
    static final String CONFIG_LEVEL_SET; }
@Test public void testLevelSet() throws Exception { TestUtil.testBlock(() -> { ProgressCheck check = new AcHandling().newInstance(obj().key("levelSet", "no_unsafe").get()); CheckReport report = scanWithCheck(check, "test_childnodeorder.zip"); logViolations("level_set:no_unsafe", report); Assert.assertEquals("no violations", 0, report.getViolations().size()); assertTrue("all violations have packageIds", report.getViolations().stream() .allMatch(viol -> !viol.getPackages().isEmpty())); }); TestUtil.testBlock(() -> { ProgressCheck check = new AcHandling().newInstance(obj().key("levelSet", "only_ignore").get()); CheckReport report = scanWithCheck(check, "test_childnodeorder.zip"); logViolations("level_set:only_ignore", report); Assert.assertEquals("one violation", 1, report.getViolations().size()); assertTrue("all violations have packageIds", report.getViolations().stream() .allMatch(viol -> !viol.getPackages().isEmpty())); }); }
@Test public void testAllowedModes() throws Exception { TestUtil.testBlock(() -> { ProgressCheck check = new AcHandling().newInstance(obj().key("allowedModes", arr("merge_preserve")).get()); CheckReport report = scanWithCheck(check, "test_childnodeorder.zip"); logViolations("allowedModes:merge_preserve", report); Assert.assertEquals("no violations", 0, report.getViolations().size()); assertTrue("all violations have packageIds", report.getViolations().stream() .allMatch(viol -> !viol.getPackages().isEmpty())); }); TestUtil.testBlock(() -> { ProgressCheck check = new AcHandling().newInstance(obj().key("allowedModes", arr("ignore")).get()); CheckReport report = scanWithCheck(check, "test_childnodeorder.zip"); logViolations("allowedModes:ignore", report); Assert.assertEquals("one violation", 1, report.getViolations().size()); assertTrue("all violations have packageIds", report.getViolations().stream() .allMatch(viol -> !viol.getPackages().isEmpty())); }); }
@Test public void testEmptyConfig() throws Exception { AcHandling.Check check = (AcHandling.Check) new AcHandling().newInstance(obj().get()); assertNotNull("check should not be null", check); Assert.assertEquals("default levelSet should be " + AcHandling.DEFAULT_LEVEL_SET, check.levelSet, AcHandling.DEFAULT_LEVEL_SET); assertTrue("default allowedModes should be empty: " + check.allowedModes, check.allowedModes.isEmpty()); }