Bug 4965: Implemented mocked security for replication tests. This is

necessary because ReplicationServlet now checks permissions.
This commit is contained in:
Steffen Schaefer
2019-04-04 08:35:14 +02:00
parent c3e7d8055f
commit 7f0bdb83e5
2 changed files with 16 additions and 1 deletions
@@ -10,7 +10,8 @@ Require-Bundle: org.junit;bundle-version="4.8.2",
com.sap.sse.common,
com.rabbitmq.client;bundle-version="2.8.4",
lz4-java;bundle-version="1.3.0",
com.sap.sse.replication.interfaces;bundle-version="1.0.0"
com.sap.sse.replication.interfaces;bundle-version="1.0.0",
org.apache.shiro.core
Export-Package: com.sap.sse.replication.testsupport
Automatic-Module-Name: com.sap.sse.replication.testsupport
Import-Package: javax.servlet;version="3.1.0",
@@ -30,6 +30,9 @@ import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.junit.Rule;
import org.junit.rules.Timeout;
import org.mockito.Matchers;
@@ -90,6 +93,7 @@ public abstract class AbstractServerReplicationTestSetUp<ReplicableInterface ext
*/
public void setUp() throws Exception {
try {
setUpSecurity();
Pair<ReplicationServiceTestImpl<ReplicableInterface>, ReplicationMasterDescriptor> result = setUpWithoutStartingToReplicateYet();
result.getA().startToReplicateFrom(result.getB());
} catch (Exception e) {
@@ -97,6 +101,16 @@ public abstract class AbstractServerReplicationTestSetUp<ReplicableInterface ext
throw e;
}
}
private void setUpSecurity() {
SecurityManager securityManager = Mockito.mock(org.apache.shiro.mgt.SecurityManager.class);
Subject fakeSubject = Mockito.mock(Subject.class);
SecurityUtils.setSecurityManager(securityManager);
Mockito.doReturn(fakeSubject).when(securityManager).createSubject(Mockito.any());
Mockito.doReturn(true).when(fakeSubject).isAuthenticated();
Mockito.doNothing().when(fakeSubject).checkPermission(Mockito.anyString());
}
/**
* Sets up master and replica, starts the JMS message broker and registers the replica with the master. If you want