mirror of
https://github.com/Alfresco/SearchServices.git
synced 2025-10-01 14:41:19 +00:00
ACS-2506 - Enhance error message and add unit tests
This commit is contained in:
@@ -45,12 +45,12 @@ import java.util.Set;
|
|||||||
public class SecretSharedPropertyCollector
|
public class SecretSharedPropertyCollector
|
||||||
{
|
{
|
||||||
|
|
||||||
public final static String SECRET_SHARED_METHOD_KEY = "secret";
|
public static final String SECRET_SHARED_METHOD_KEY = "secret";
|
||||||
|
|
||||||
// Property names for "secret" communication method
|
// Property names for "secret" communication method
|
||||||
static final String SECURE_COMMS_PROPERTY = "alfresco.secureComms";
|
static final String SECURE_COMMS_PROPERTY = "alfresco.secureComms";
|
||||||
private final static String SHARED_SECRET = "alfresco.secureComms.secret";
|
static final String SHARED_SECRET = "alfresco.secureComms.secret";
|
||||||
private final static String SHARED_SECRET_HEADER = "alfresco.secureComms.secret.header";
|
private static final String SHARED_SECRET_HEADER = "alfresco.secureComms.secret.header";
|
||||||
|
|
||||||
// Save communication method as static value in order to improve performance
|
// Save communication method as static value in order to improve performance
|
||||||
static String commsMethod;
|
static String commsMethod;
|
||||||
@@ -126,7 +126,8 @@ public class SecretSharedPropertyCollector
|
|||||||
|
|
||||||
if (secret == null || secret.length() == 0)
|
if (secret == null || secret.length() == 0)
|
||||||
{
|
{
|
||||||
throw new RuntimeException("Missing value for " + SHARED_SECRET + " configuration property");
|
throw new RuntimeException("Missing value for " + SHARED_SECRET + " configuration property. Make sure to"
|
||||||
|
+ " pass this property as a JVM Argument (eg. -D" + SHARED_SECRET + "=my-secret-value).");
|
||||||
}
|
}
|
||||||
|
|
||||||
return secret;
|
return secret;
|
||||||
|
@@ -37,6 +37,7 @@ import java.util.Set;
|
|||||||
import static java.util.Collections.emptySet;
|
import static java.util.Collections.emptySet;
|
||||||
import static org.alfresco.solr.security.SecretSharedPropertyCollector.SECRET_SHARED_METHOD_KEY;
|
import static org.alfresco.solr.security.SecretSharedPropertyCollector.SECRET_SHARED_METHOD_KEY;
|
||||||
import static org.alfresco.solr.security.SecretSharedPropertyCollector.SECURE_COMMS_PROPERTY;
|
import static org.alfresco.solr.security.SecretSharedPropertyCollector.SECURE_COMMS_PROPERTY;
|
||||||
|
import static org.alfresco.solr.security.SecretSharedPropertyCollector.SHARED_SECRET;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
@@ -45,15 +46,17 @@ import static org.mockito.Mockito.mockStatic;
|
|||||||
|
|
||||||
public class SecretSharedPropertyCollectorTest
|
public class SecretSharedPropertyCollectorTest
|
||||||
{
|
{
|
||||||
private final static String A_COMMS_METHOD = "aCommsMethod";
|
private static final String A_COMMS_METHOD = "aCommsMethod";
|
||||||
private final static String SET_THROUGH_SYSTEM_PROPERTY = "aCommsMethod_SetThroughSystemProperty";
|
private static final String SET_THROUGH_SYSTEM_PROPERTY = "aCommsMethod_SetThroughSystemProperty";
|
||||||
private final static String SET_THROUGH_ALFRESCO_COMMON_CONFIG = "aCommsMethod_SetThroughAlfrescoCommonConfig";
|
private static final String SET_THROUGH_ALFRESCO_COMMON_CONFIG = "aCommsMethod_SetThroughAlfrescoCommonConfig";
|
||||||
private final static String COMMS_METHOD_FROM_SOLRCORE = "aCommsMethod_FromSolrCore";
|
private static final String COMMS_METHOD_FROM_SOLRCORE = "aCommsMethod_FromSolrCore";
|
||||||
|
private static final String SECRET_VALUE = "my-secret";
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp()
|
public void setUp()
|
||||||
{
|
{
|
||||||
SecretSharedPropertyCollector.commsMethod = null;
|
SecretSharedPropertyCollector.commsMethod = null;
|
||||||
|
assertNull(System.getProperty(SHARED_SECRET));
|
||||||
assertNull(System.getProperty(SECURE_COMMS_PROPERTY));
|
assertNull(System.getProperty(SECURE_COMMS_PROPERTY));
|
||||||
assertNull(AlfrescoSolrDataModel.getCommonConfig().getProperty(SECURE_COMMS_PROPERTY));
|
assertNull(AlfrescoSolrDataModel.getCommonConfig().getProperty(SECURE_COMMS_PROPERTY));
|
||||||
}
|
}
|
||||||
@@ -61,10 +64,24 @@ public class SecretSharedPropertyCollectorTest
|
|||||||
@After
|
@After
|
||||||
public void tearDown()
|
public void tearDown()
|
||||||
{
|
{
|
||||||
|
System.clearProperty(SHARED_SECRET);
|
||||||
System.clearProperty(SECURE_COMMS_PROPERTY);
|
System.clearProperty(SECURE_COMMS_PROPERTY);
|
||||||
AlfrescoSolrDataModel.getCommonConfig().remove(SECURE_COMMS_PROPERTY);
|
AlfrescoSolrDataModel.getCommonConfig().remove(SECURE_COMMS_PROPERTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSecret_shouldReturnTheSecretValue()
|
||||||
|
{
|
||||||
|
System.setProperty(SecretSharedPropertyCollector.SHARED_SECRET, SECRET_VALUE);
|
||||||
|
assertEquals(SECRET_VALUE, SecretSharedPropertyCollector.getSecret());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = RuntimeException.class)
|
||||||
|
public void getSecretWithMissingSecretValue_shouldThrowException()
|
||||||
|
{
|
||||||
|
SecretSharedPropertyCollector.getSecret();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void commsMethodIsNotNull_shouldReturnThatValue()
|
public void commsMethodIsNotNull_shouldReturnThatValue()
|
||||||
{
|
{
|
||||||
@@ -162,4 +179,5 @@ public class SecretSharedPropertyCollectorTest
|
|||||||
SecretSharedPropertyCollector.getCommsMethod();
|
SecretSharedPropertyCollector.getCommsMethod();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user