Skip to content

Commit

Permalink
Merge pull request #8322 from gytis/master-WFLY-5518-xts-security-man…
Browse files Browse the repository at this point in the history
…ager

[WFLY-5518] Fix XTS tests to work with security manager
  • Loading branch information
n1hility committed Oct 23, 2015
2 parents 5ea3983 + b465fe7 commit 23fe4ac
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 69 deletions.
23 changes: 22 additions & 1 deletion testsuite/integration/xts/pom.xml
Expand Up @@ -92,7 +92,28 @@
</plugins>
</build>
</profile>

<profile>
<id>ts.security.manager</id>
<activation>
<property>
<name>security.manager</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<!-- This test uses Byteman and requires permission on a random port every time -->
<exclude>**/BAParticipantCompletionTestCase.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>

</profiles>
</project>
Expand Up @@ -24,14 +24,10 @@
import com.arjuna.mw.wst11.UserBusinessActivity;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.shared.TestSuiteEnvironment;
import org.jboss.as.test.xts.annotation.service.CompensatableService;
import org.jboss.as.test.xts.annotation.service.CompensatableServiceImpl;
import org.jboss.shrinkwrap.api.ArchivePaths;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.as.test.xts.util.DeploymentHelper;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
Expand All @@ -45,23 +41,25 @@ public class CompensatableTestCase {

private static final String DEPLOYMENT_NAME = "compensatable-test";

@ArquillianResource
private ManagementClient managementClient;
private static final String SERVER_HOST_PORT = TestSuiteEnvironment.getServerAddress() + ":"
+ TestSuiteEnvironment.getHttpPort();

private static final String DEPLOYMENT_URL = "http://" + SERVER_HOST_PORT + "/" + DEPLOYMENT_NAME;

@Deployment
public static WebArchive getDeployment() {
final WebArchive webArchive = ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME + ".war")
final WebArchive webArchive = DeploymentHelper.getInstance().getWebArchiveWithPermissions(DEPLOYMENT_NAME)
.addClass(CompensatableClient.class)
.addClass(CompensatableService.class)
.addClass(CompensatableServiceImpl.class)
.addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));
.addClass(TestSuiteEnvironment.class);

return webArchive;
}

@Test
public void testNoTransaction() throws Exception {
final String deploymentUrl = getDeploymentUrl();
final String deploymentUrl = DEPLOYMENT_URL;
final CompensatableService compensatableService = CompensatableClient.newInstance(deploymentUrl);

final boolean isTransactionActive = compensatableService.isTransactionActive();
Expand All @@ -71,7 +69,7 @@ public void testNoTransaction() throws Exception {

@Test
public void testActiveTransaction() throws Exception {
final String deploymentUrl = getDeploymentUrl();
final String deploymentUrl = DEPLOYMENT_URL;
final CompensatableService compensatableService = CompensatableClient.newInstance(deploymentUrl);

final UserBusinessActivity userBusinessActivity = UserBusinessActivity.getUserBusinessActivity();
Expand All @@ -83,10 +81,4 @@ public void testActiveTransaction() throws Exception {
Assert.assertEquals(true, isTransactionActive);
}

private String getDeploymentUrl() {
final String baseUrl = managementClient.getWebUri().toString();

return baseUrl + "/" + DEPLOYMENT_NAME;
}

}
Expand Up @@ -24,13 +24,10 @@
import com.arjuna.mw.wst11.UserTransaction;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.shared.TestSuiteEnvironment;
import org.jboss.as.test.xts.annotation.service.TransactionalService;
import org.jboss.as.test.xts.annotation.service.TransactionalServiceImpl;
import org.jboss.shrinkwrap.api.ArchivePaths;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.as.test.xts.util.DeploymentHelper;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
Expand All @@ -45,24 +42,26 @@ public class TransactionalTestCase {

private static final String DEPLOYMENT_NAME = "transactional-test";

@ArquillianResource
private ManagementClient managementClient;
private static final String SERVER_HOST_PORT = TestSuiteEnvironment.getServerAddress() + ":"
+ TestSuiteEnvironment.getHttpPort();

private static final String DEPLOYMENT_URL = "http://" + SERVER_HOST_PORT + "/" + DEPLOYMENT_NAME;

@Deployment
public static WebArchive getDeployment() {
final WebArchive webArchive = ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME + ".war")
final WebArchive webArchive = DeploymentHelper.getInstance().getWebArchiveWithPermissions(DEPLOYMENT_NAME)
.addClass(TransactionalClient.class)
.addClass(TransactionalService.class)
.addClass(TransactionalServiceImpl.class)
.addAsManifestResource(new StringAsset("Dependencies: org.jboss.xts,org.jboss.jts\n"), "MANIFEST.MF")
.addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));
.addClass(TestSuiteEnvironment.class)
.addAsManifestResource(new StringAsset("Dependencies: org.jboss.xts,org.jboss.jts\n"), "MANIFEST.MF");

return webArchive;
}

@Test
public void testNoTransaction() throws Exception {
final String deploymentUrl = getDeploymentUrl();
final String deploymentUrl = DEPLOYMENT_URL;
final TransactionalService transactionalService = TransactionalClient.newInstance(deploymentUrl);

final boolean isTransactionActive = transactionalService.isTransactionActive();
Expand All @@ -72,7 +71,7 @@ public void testNoTransaction() throws Exception {

@Test
public void testActiveTransaction() throws Exception {
final String deploymentUrl = getDeploymentUrl();
final String deploymentUrl = DEPLOYMENT_URL;
final TransactionalService transactionalService = TransactionalClient.newInstance(deploymentUrl);
final UserTransaction userTransaction = UserTransaction.getUserTransaction();

Expand All @@ -83,10 +82,4 @@ public void testActiveTransaction() throws Exception {
Assert.assertEquals(true, isTransactionActive);
}

private String getDeploymentUrl() {
final String baseUrl = managementClient.getWebUri().toString();

return baseUrl + "/" + DEPLOYMENT_NAME;
}

}
Expand Up @@ -23,10 +23,9 @@

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.test.xts.util.DeploymentHelper;
import org.jboss.narayana.compensations.impl.BAControler;
import org.jboss.narayana.compensations.impl.BAControllerFactory;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.After;
import org.junit.Assert;
Expand All @@ -49,9 +48,8 @@ public class CompensationScopedTestCase {

@Deployment
public static JavaArchive getDeployment() {
JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "test.jar")
.addPackage(CompensationScopedTestCase.class.getPackage())
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
final JavaArchive archive = DeploymentHelper.getInstance().getJavaArchive("test")
.addPackage(CompensationScopedTestCase.class.getPackage());

return archive;
}
Expand Down
@@ -0,0 +1,92 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file 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.as.test.xts.util;

import org.jboss.as.test.shared.TestSuiteEnvironment;
import org.jboss.as.test.shared.integration.ejb.security.PermissionUtils;
import org.jboss.shrinkwrap.api.ArchivePaths;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;

import java.io.File;
import java.io.FilePermission;
import java.net.SocketPermission;
import java.util.PropertyPermission;

/**
* @author <a href="mailto:gytis@redhat.com">Gytis Trikleris</a>
*/
public class DeploymentHelper {

private static final DeploymentHelper INSTANCE = new DeploymentHelper();

private DeploymentHelper() {

}

public static DeploymentHelper getInstance() {
return INSTANCE;
}

public JavaArchive getJavaArchive(final String archiveName) {
final JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, archiveName + ".jar")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

return javaArchive;
}

public WebArchive getWebArchive(final String archiveName) {
final WebArchive webArchive = ShrinkWrap.create(WebArchive.class, archiveName + ".war")
.addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));

return webArchive;
}

public WebArchive getWebArchiveWithPermissions(final String archiveName) {
final String javaHome = TestSuiteEnvironment.getSystemProperty("java.home");
final String serverHostPort = TestSuiteEnvironment.getServerAddress() + ":"
+ TestSuiteEnvironment.getHttpPort();

final WebArchive webArchive = ShrinkWrap.create(WebArchive.class, archiveName + ".war")
.addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"))
.addAsManifestResource(PermissionUtils.createPermissionsXmlAsset(
// Permissions for port access
new PropertyPermission("management.address", "read"),
new PropertyPermission("node0", "read"),
new PropertyPermission("jboss.http.port", "read"),
new SocketPermission(serverHostPort, "connect,resolve"),
// Permissions for the new client creation
new RuntimePermission("getClassLoader"),
new FilePermission(javaHome + File.separator + "lib" + File.separator + "wsdl.properties", "read"),
new PropertyPermission("user.dir", "read"),
new RuntimePermission("org.apache.cxf.permission"),
new RuntimePermission("createClassLoader"),
new FilePermission(System.getProperty("basedir") + File.separator + "target" + File.separator
+ "workdir" + File.separator + "xcatalog", "read")
), "permissions.xml");

return webArchive;
}

}
Expand Up @@ -35,6 +35,7 @@

import org.jboss.as.test.xts.base.BaseFunctionalTest;
import org.jboss.as.test.xts.base.TestApplicationException;
import org.jboss.as.test.xts.util.DeploymentHelper;
import org.jboss.as.test.xts.util.EventLog;
import org.jboss.as.test.xts.util.EventLogEvent;
import org.jboss.as.test.xts.wsat.service.AT;
Expand All @@ -45,9 +46,6 @@
import static org.jboss.as.test.xts.util.ServiceCommand.*;
import static org.jboss.as.test.xts.util.EventLogEvent.*;

import org.jboss.shrinkwrap.api.ArchivePaths;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.After;
Expand All @@ -66,23 +64,20 @@ public class ATTestCase extends BaseFunctionalTest {
private AT client1, client2, client3;

public static final String ARCHIVE_NAME = "wsat-test";

@Inject
EventLog eventLog;

@Deployment
public static WebArchive createTestArchive() {
WebArchive archive = ShrinkWrap.create(WebArchive.class, ARCHIVE_NAME + ".war")
final WebArchive archive = DeploymentHelper.getInstance().getWebArchiveWithPermissions(ARCHIVE_NAME)
.addPackage(AT.class.getPackage())
.addPackage(ATClient.class.getPackage())
.addPackage(EventLog.class.getPackage())
.addPackage(BaseFunctionalTest.class.getPackage())

// needed to setup the server-side handler chain
.addAsResource("context-handlers.xml")
.addAsManifestResource(new StringAsset("Dependencies: org.jboss.xts,org.jboss.jts\n"), "MANIFEST.MF")
.addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml")); // beans.xml is put under web-inf for war deploy

.addAsManifestResource(new StringAsset("Dependencies: org.jboss.xts,org.jboss.jts\n"), "MANIFEST.MF");
return archive;
}

Expand Down
Expand Up @@ -22,8 +22,6 @@

package org.jboss.as.test.xts.wsba.coordinatorcompletion.client;

import java.io.File;

import javax.inject.Inject;

import com.arjuna.mw.wst11.UserBusinessActivity;
Expand All @@ -33,18 +31,14 @@
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.test.xts.base.BaseFunctionalTest;
import org.jboss.as.test.xts.base.TestApplicationException;
import org.jboss.as.test.xts.util.DeploymentHelper;
import org.jboss.as.test.xts.util.EventLog;
import org.jboss.as.test.xts.util.EventLogEvent;
import org.jboss.as.test.xts.wsba.coordinatorcompletion.service.BACoordinatorCompletion;
import org.jboss.as.test.xts.wsba.coordinatorcompletion.service.BACoordinatorCompletionService1;
import org.jboss.as.test.xts.wsba.coordinatorcompletion.service.BACoordinatorCompletionService2;
import org.jboss.as.test.xts.wsba.coordinatorcompletion.service.BACoordinatorCompletionService3;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ArchivePaths;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.exporter.ZipExporter;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.After;
import org.junit.Assert;
Expand All @@ -69,15 +63,13 @@ public class BACoordinatorCompletionTestCase extends BaseFunctionalTest {
public static final String ARCHIVE_NAME = "wsba-coordinatorcompletition-test";

@Deployment
public static Archive<?> createTestArchive() {
Archive<?> war = ShrinkWrap.create(WebArchive.class, ARCHIVE_NAME + ".war")
public static WebArchive createTestArchive() {
final WebArchive war = DeploymentHelper.getInstance().getWebArchiveWithPermissions(ARCHIVE_NAME)
.addPackage(BACoordinatorCompletion.class.getPackage())
.addPackage(BACoordinatorCompletionClient.class.getPackage())
.addPackage(EventLog.class.getPackage())
.addPackage(BaseFunctionalTest.class.getPackage())

.addAsResource("context-handlers.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"))
.addAsManifestResource(new StringAsset("Dependencies: org.jboss.xts,org.jboss.jts\n"), "MANIFEST.MF");
return war;
}
Expand Down

0 comments on commit 23fe4ac

Please sign in to comment.