/** * Validates that the parent parameter was acceptable. * * @return True if the parent parameter is valid for the current container. */ private boolean validateParent(GadgetContext context) { String container = context.getContainer(); String parent = context.getParameter("parent"); if (parent == null) { // If there is no parent parameter, we are still safe because no // dependent code ever has to trust it anyway. return true; } List<Object> parents = containerConfig.getList(container, "gadgets.parent"); if (parents.isEmpty()) { // Allow all. return true; } // We need to check each possible parent parameter against this regex. for (Object pattern : parents) { if (Pattern.matches(pattern.toString(), parent)) { return true; } } return false; }
@Before public void setUp() { LinkedList<String> containers = new LinkedList<String>(); containers.add("default"); config = createMock(ContainerConfig.class); expect(config.getContainers()).andReturn(containers); replay(config); crypter = createMock(BlobCrypter.class); }