001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.console.jbas3861;
023:
024: import javax.management.Attribute;
025: import javax.management.ObjectName;
026: import javax.management.RuntimeMBeanException;
027:
028: import org.jboss.mx.util.ObjectNameFactory;
029: import org.jboss.test.JBossTestCase;
030:
031: /**
032: * Test JBAS-3861 (DeploymentFileRepository service)
033: *
034: * @author <a href="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
035: * @version $Revision: 57211 $
036: */
037: public class JBAS3861UnitTestCase extends JBossTestCase {
038: ObjectName target = ObjectNameFactory
039: .create("jboss.admin:service=DeploymentFileRepository");
040:
041: public JBAS3861UnitTestCase(String name) {
042: super (name);
043: }
044:
045: /**
046: * Check if BaseDir can be set outside the server home directory
047: */
048: public void testSetBaseDirOutsideServerHomeDir() throws Exception {
049: // remember original BaseDir
050: String basedir = (String) getServer().getAttribute(target,
051: "BaseDir");
052: try {
053: // Should throw an IllegalArgumentException
054: getServer().setAttribute(target,
055: new Attribute("BaseDir", ".."));
056: // Should throw an IllegalArgumentException
057: getServer().setAttribute(target,
058: new Attribute("BaseDir", "/"));
059:
060: // Restore the original dir and fail the test
061: getServer().setAttribute(target,
062: new Attribute("BaseDir", basedir));
063: fail("Managed to set BaseDir outside ServerHomeDir for service: "
064: + target);
065: } catch (RuntimeMBeanException e) {
066: // expected
067: }
068: }
069:
070: /**
071: * Check if we can write a file outside the server home directory
072: */
073: public void testStoreFileOutsideServerHomeDir() throws Exception {
074: try {
075: // Should throw an exception
076: getServer()
077: .invoke(
078: target,
079: "store",
080: new Object[] { "..", "jbas3861", ".tmp",
081: "file content", Boolean.TRUE },
082: new String[] { "java.lang.String",
083: "java.lang.String",
084: "java.lang.String",
085: "java.lang.String",
086: Boolean.TYPE.toString() });
087:
088: // Should throw an exception
089: getServer()
090: .invoke(
091: target,
092: "store",
093: new Object[] { ".", "../jbas3861", ".tmp",
094: "file content", Boolean.TRUE },
095: new String[] { "java.lang.String",
096: "java.lang.String",
097: "java.lang.String",
098: "java.lang.String",
099: Boolean.TYPE.toString() });
100:
101: // Remove the stored file and fail the test - normally it should throw an exception, too
102: getServer().invoke(
103: target,
104: "remove",
105: new Object[] { ".", "../jbas3861", ".tmp" },
106: new String[] { "java.lang.String",
107: "java.lang.String", "java.lang.String" });
108:
109: fail("Managed to create/remove a file outside ServerHomeDir for service: "
110: + target);
111: } catch (RuntimeMBeanException e) {
112: // expected
113: }
114: }
115:
116: }
|