mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-20 04:35:32 +00:00
Bug 4965: Implemented mocked security for replication tests. This is
necessary because ReplicationServlet now checks permissions.
This commit is contained in:
@@ -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",
|
||||
|
||||
+14
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user