Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HV-913 Providing new profile for the "tck-runner" module for executin…
…g the TCK with a security manager enabled
- Loading branch information
1 parent
88c6d44
commit a1aed64
Showing
12 changed files
with
524 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...r/src/main/java/org/hibernate/validator/tckrunner/securitymanager/DelegatingExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Hibernate Validator, declare and validate application constraints | ||
* | ||
* License: Apache License, Version 2.0 | ||
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>. | ||
*/ | ||
package org.hibernate.validator.tckrunner.securitymanager; | ||
|
||
/** | ||
* Executes a given operation. | ||
* <p> | ||
* The whole purpose of this class is to establish a frame on the stack which is as close as possible to the running | ||
* tests and whose protection domain has no permissions at all. It is separated from the other Arquillian-related | ||
* classes which need special permissions on their own. | ||
* <p> | ||
* This will reveal any invocation of security-relevant methods in the HV code base which don't make use of a | ||
* do-privileged block. | ||
* | ||
* @author Gunnar Morling | ||
* | ||
*/ | ||
public class DelegatingExecutor implements Executor { | ||
|
||
private final Executor delegate; | ||
|
||
public DelegatingExecutor(Executor delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public void invoke(Object... parameters) throws Throwable { | ||
delegate.invoke( parameters ); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
tck-runner/src/main/java/org/hibernate/validator/tckrunner/securitymanager/Executor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Hibernate Validator, declare and validate application constraints | ||
* | ||
* License: Apache License, Version 2.0 | ||
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>. | ||
*/ | ||
package org.hibernate.validator.tckrunner.securitymanager; | ||
|
||
/** | ||
* Executes a given operation. | ||
* | ||
* @author Gunnar Morling | ||
* | ||
*/ | ||
public interface Executor { | ||
|
||
void invoke(Object... parameters) throws Throwable; | ||
} |
73 changes: 73 additions & 0 deletions
73
tck-runner/src/test/java/org/hibernate/validator/tckrunner/securitymanager/TckRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Hibernate Validator, declare and validate application constraints | ||
* | ||
* License: Apache License, Version 2.0 | ||
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>. | ||
*/ | ||
package org.hibernate.validator.tckrunner.securitymanager; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.hibernate.beanvalidation.tck.util.IntegrationTestsMethodSelector; | ||
import org.testng.ITestResult; | ||
import org.testng.TestListenerAdapter; | ||
import org.testng.TestNG; | ||
import org.testng.xml.XmlMethodSelector; | ||
import org.testng.xml.XmlPackage; | ||
import org.testng.xml.XmlSuite; | ||
import org.testng.xml.XmlTest; | ||
|
||
/** | ||
* Main class for running the test suite programmatically, for debugging purposes. | ||
* <p> | ||
* Specify the following arguments when running this test: | ||
* <pre> | ||
* -Dvalidation.provider=org.hibernate.validator.HibernateValidator | ||
* -Djava.security.manager=default | ||
* -Djava.security.policy=target/test-classes/test.policy | ||
* -Djava.security.debug=access | ||
* -DexcludeIntegrationTests=true | ||
* -Darquillian.protocol=LocalSecurityManagerTesting | ||
* -Dorg.jboss.testharness.spi.StandaloneContainers=org.hibernate.jsr303.tck.util.StandaloneContainersImpl | ||
* </pre> | ||
* | ||
* @author Gunnar Morling | ||
*/ | ||
public class TckRunner { | ||
|
||
public static void main(String[] args) { | ||
XmlSuite suite = new XmlSuite(); | ||
suite.setName( "JSR-349-TCK" ); | ||
|
||
XmlTest test = new XmlTest(suite); | ||
test.setName("JSR-349-TCK"); | ||
|
||
List<XmlPackage> packages = Collections.singletonList( new XmlPackage( "org.hibernate.beanvalidation.tck.tests" ) ); | ||
test.setXmlPackages( packages ); | ||
|
||
// Alternatively e.g. use this for running single tests | ||
// List<XmlClass> classes = Collections.singletonList( new XmlClass( ValidateTest.class ) ); | ||
// test.setXmlClasses( classes ); | ||
|
||
XmlMethodSelector selector = new XmlMethodSelector(); | ||
selector.setClassName( IntegrationTestsMethodSelector.class.getName() ); | ||
test.setMethodSelectors( Collections.singletonList( selector ) ); | ||
|
||
TestListenerAdapter tla = new TestListenerAdapter(); | ||
TestNG testng = new TestNG(); | ||
testng.setXmlSuites( Collections.singletonList( suite ) ); | ||
testng.addListener(tla); | ||
testng.run(); | ||
|
||
for ( ITestResult failure: tla.getConfigurationFailures() ) { | ||
System.out.println( "Failure: " + failure.getName() ); | ||
failure.getThrowable().printStackTrace(); | ||
} | ||
|
||
for ( ITestResult result : tla.getFailedTests() ) { | ||
System.out.println( "Failed:" + result.getName() ); | ||
result.getThrowable().printStackTrace(); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...runner/securitymanager/arquillian/LocalSecurityManagerTestingContainerMethodExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Hibernate Validator, declare and validate application constraints | ||
* | ||
* License: Apache License, Version 2.0 | ||
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>. | ||
*/ | ||
package org.hibernate.validator.tckrunner.securitymanager.arquillian; | ||
|
||
import org.jboss.arquillian.container.test.spi.ContainerMethodExecutor; | ||
import org.jboss.arquillian.core.api.Event; | ||
import org.jboss.arquillian.core.api.Instance; | ||
import org.jboss.arquillian.core.api.annotation.Inject; | ||
import org.jboss.arquillian.test.spi.TestMethodExecutor; | ||
import org.jboss.arquillian.test.spi.TestResult; | ||
|
||
/** | ||
* A custom {@link ContainerMethodExecutor} based on {@link LocalSecurityManagerTestingExecutionEvent}. | ||
* | ||
* @author Gunnar Morling | ||
*/ | ||
public class LocalSecurityManagerTestingContainerMethodExecutor implements ContainerMethodExecutor { | ||
|
||
@Inject | ||
private Event<LocalSecurityManagerTestingExecutionEvent> event; | ||
|
||
@Inject | ||
private Instance<TestResult> testResult; | ||
|
||
@Override | ||
public TestResult invoke(TestMethodExecutor testMethodExecutor) { | ||
event.fire( new LocalSecurityManagerTestingExecutionEvent( testMethodExecutor ) ); | ||
return testResult.get(); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...dator/tckrunner/securitymanager/arquillian/LocalSecurityManagerTestingExecutionEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Hibernate Validator, declare and validate application constraints | ||
* | ||
* License: Apache License, Version 2.0 | ||
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>. | ||
*/ | ||
package org.hibernate.validator.tckrunner.securitymanager.arquillian; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import org.hibernate.validator.tckrunner.securitymanager.DelegatingExecutor; | ||
import org.hibernate.validator.tckrunner.securitymanager.Executor; | ||
import org.jboss.arquillian.container.test.impl.execution.event.LocalExecutionEvent; | ||
import org.jboss.arquillian.test.spi.TestMethodExecutor; | ||
|
||
/** | ||
* A custom {@link LocalExecutionEvent} which channels execution through a specific protection domain. | ||
* | ||
* @author Gunnar Morling | ||
*/ | ||
public class LocalSecurityManagerTestingExecutionEvent extends LocalExecutionEvent { | ||
|
||
public LocalSecurityManagerTestingExecutionEvent(TestMethodExecutor executor) { | ||
super( new DelegatingTestMethodExecutor( executor ) ); | ||
} | ||
|
||
/** | ||
* Invokes the given test method via {@link DelegatingExecutor} which lives in its own protection domain. | ||
*/ | ||
private static class DelegatingTestMethodExecutor implements TestMethodExecutor { | ||
|
||
private final Executor delegate; | ||
private final Method method; | ||
private final Object instance; | ||
|
||
public DelegatingTestMethodExecutor(TestMethodExecutor delegate) { | ||
this.method = delegate.getMethod(); | ||
this.instance = delegate.getInstance(); | ||
this.delegate = new DelegatingExecutor( new ArquillianExecutor( delegate ) ); | ||
} | ||
|
||
@Override | ||
public Method getMethod() { | ||
return method; | ||
} | ||
|
||
@Override | ||
public Object getInstance() { | ||
return instance; | ||
} | ||
|
||
@Override | ||
public void invoke(Object... parameters) throws Throwable { | ||
delegate.invoke( parameters ); | ||
} | ||
} | ||
|
||
/** | ||
* Executes a given test via a given Arquillian test executor. | ||
*/ | ||
private static class ArquillianExecutor implements Executor { | ||
|
||
private final TestMethodExecutor delegate; | ||
|
||
public ArquillianExecutor(TestMethodExecutor delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public void invoke(Object... parameters) throws Throwable { | ||
delegate.invoke( parameters ); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
.../validator/tckrunner/securitymanager/arquillian/LocalSecurityManagerTestingExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Hibernate Validator, declare and validate application constraints | ||
* | ||
* License: Apache License, Version 2.0 | ||
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>. | ||
*/ | ||
package org.hibernate.validator.tckrunner.securitymanager.arquillian; | ||
|
||
import org.jboss.arquillian.container.test.spi.client.protocol.Protocol; | ||
import org.jboss.arquillian.core.spi.LoadableExtension; | ||
|
||
/** | ||
* An Arquillian extension which contributes a special protocol, {@link LocalSecurityManagerTestingProtocol}. | ||
* <p> | ||
* This protocol is essentially the same as | ||
* {@link org.jboss.arquillian.container.test.impl.client.protocol.local.LocalProtocol}, only that the execution of | ||
* tests is channeled through a specific protection domain (basically, "target/classes" of this module, or the | ||
* equivalent JAR). Specifying only minimal permissions to this protection domain allows for the identification of code | ||
* in the HV JAR which doesn't use privileged actions as required. | ||
* | ||
* @author Gunnar Morling | ||
*/ | ||
public class LocalSecurityManagerTestingExtension implements LoadableExtension { | ||
|
||
@Override | ||
public void register(ExtensionBuilder builder) { | ||
builder.service( Protocol.class, LocalSecurityManagerTestingProtocol.class ); | ||
} | ||
} |
Oops, something went wrong.