/*
* JBoss, Home of Professional Open Source
* Copyright 2006, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.test.security.test;
import java.io.File;
import java.net.URL;
import java.security.AccessControlException;
import org.jboss.test.AbstractTestCaseWithSetup;
import org.jboss.test.AbstractTestDelegate;
import org.jboss.test.security.NothingPolicyPlugin;
/**
* OriginalSecurityUnitTestCase.
*
* @author <a href="adrian@jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
public class NothingSecurityUnitTestCase extends AbstractTestCaseWithSetup
{
public NothingSecurityUnitTestCase(String name)
{
super(name);
}
public static AbstractTestDelegate getDelegate(Class clazz)
{
AbstractTestDelegate delegate = new AbstractTestDelegate(clazz);
delegate.enableSecurity = true;
delegate.securityPolicyName = NothingPolicyPlugin.class.getName();
return delegate;
}
public void testSecurity() throws Exception
{
// Shouldn't be allowed to get a system property
try
{
System.getProperty("blah");
fail("Should not be here!");
}
catch (Exception expected)
{
checkThrowable(AccessControlException.class, expected);
}
// We can't access files with the nothing policy
URL url = getResource("/org/jboss/test/BaseTestCase.class");
assertNotNull(url);
try
{
File file = new File(url.getFile());
assertTrue(file.exists());
fail("Should not be here!");
}
catch (Exception expected)
{
checkThrowable(AccessControlException.class, expected);
}
// A plain getResource for some other codesource should not work with the nothing policy
url = getClass().getResource("/org/jboss/test/BaseTestCase.class");
assertNull(url);
}
}