Fixes removing properties with partial match, and adds tests for it.

ice4sip
Damian Minkov 12 years ago
parent 02aa358e4f
commit 994e8bfe99

@ -354,7 +354,7 @@ public synchronized void removeProperty(String propertyName)
//remove all properties //remove all properties
for (String child : this.getPropertyNamesByPrefix(propertyName, false)) for (String child : this.getPropertyNamesByPrefix(propertyName, false))
{ {
removeProperty(child); this.setProperty(child, null, false);
} }
this.setProperty(propertyName, null, false); this.setProperty(propertyName, null, false);
@ -411,15 +411,17 @@ public List<String> getPropertyNamesByPrefix(String prefix,
while (q.next()) while (q.next())
{ {
String key = q.getString(1); String key = q.getString(1);
int ix = key.lastIndexOf('.');
if(ix == -1)
{
continue;
}
String keyPrefix = key.substring(0, ix);
if(exactPrefixMatch) if(exactPrefixMatch)
{ {
int ix = key.lastIndexOf('.');
if(ix == -1)
{
continue;
}
String keyPrefix = key.substring(0, ix);
if(prefix.equals(keyPrefix)) if(prefix.equals(keyPrefix))
{ {
resultSet.add(key); resultSet.add(key);
@ -427,7 +429,7 @@ public List<String> getPropertyNamesByPrefix(String prefix,
} }
else else
{ {
if(keyPrefix.startsWith(prefix)) if(key.startsWith(prefix))
{ {
resultSet.add(key); resultSet.add(key);
} }
@ -772,7 +774,6 @@ public String getConfigurationFilename()
{ {
return "props.hsql.script"; return "props.hsql.script";
} }
/** /**
* Loads the specified default properties maps from the Jitsi installation * Loads the specified default properties maps from the Jitsi installation

@ -536,9 +536,13 @@ private int getLastCustomStatusMessageIndex()
DesktopUtilActivator.getConfigurationService() DesktopUtilActivator.getConfigurationService()
.getPropertyNamesByPrefix(CUSTOM_MESSAGES_PREFIX, false); .getPropertyNamesByPrefix(CUSTOM_MESSAGES_PREFIX, false);
int prefixLen = CUSTOM_MESSAGES_PREFIX.length() + 1;
for(String p : customMessagesProps) for(String p : customMessagesProps)
{ {
String s = p.substring(CUSTOM_MESSAGES_PREFIX.length() + 1); if(prefixLen > p.length())
continue;
String s = p.substring(prefixLen);
try try
{ {

@ -485,7 +485,7 @@ private void initContent()
protocol, protocol,
accID.getUserID())); accID.getUserID()));
} }
for(Map.Entry<String, String> entry : for(Map.Entry<String, String> entry :
SecurityConfigActivator.getChatRoomsWithSavedPasswords() SecurityConfigActivator.getChatRoomsWithSavedPasswords()
.entrySet()) .entrySet())
@ -498,7 +498,7 @@ private void initContent()
resources.getI18NString("service.gui.CHAT_ROOM"), resources.getI18NString("service.gui.CHAT_ROOM"),
description)); description));
} }
// load provisioning passwords // load provisioning passwords
String PROVISIONING_PROPERTIES_PREFIX = String PROVISIONING_PROPERTIES_PREFIX =
"net.java.sip.communicator.plugin.provisioning.auth"; "net.java.sip.communicator.plugin.provisioning.auth";
@ -523,17 +523,18 @@ private void initContent()
configurationService.getPropertyNamesByPrefix( configurationService.getPropertyNamesByPrefix(
HTTP_PROPERTIES_PREFIX, false); HTTP_PROPERTIES_PREFIX, false);
int prefLen = HTTP_PROPERTIES_PREFIX.length() + 1;
for(String prop: httpPasses) for(String prop: httpPasses)
{ {
// we skip the entry containing the encoded password // we skip the entry containing the encoded password
if(prop.contains("PASSWORD")) if(prop.contains("PASSWORD")
|| prefLen > prop.length())
continue; continue;
model.savedPasswords.add( model.savedPasswords.add(
new PasswordsTableRow( new PasswordsTableRow(
prop, prop,
"http://" + prop.substring( "http://" + prop.substring(prefLen),
HTTP_PROPERTIES_PREFIX.length() + 1),
configurationService.getString(prop))); configurationService.getString(prop)));
} }
} }

@ -151,6 +151,7 @@ private void doLoadStoredAccounts(ProtocolProviderFactory factory)
bundleContext, bundleContext,
CredentialsStorageService.class); CredentialsStorageService.class);
int prefLen = storedAccount.length() + 1;
for (Iterator<String> storedAccountPropertyIter for (Iterator<String> storedAccountPropertyIter
= storedAccountProperties.iterator(); = storedAccountProperties.iterator();
storedAccountPropertyIter.hasNext();) storedAccountPropertyIter.hasNext();)
@ -159,7 +160,10 @@ private void doLoadStoredAccounts(ProtocolProviderFactory factory)
String value = configService.getString(property); String value = configService.getString(property);
//strip the package prefix //strip the package prefix
property = property.substring(storedAccount.length() + 1); if(prefLen > property.length())
continue;
property = property.substring(prefLen);
if (ProtocolProviderFactory.IS_ACCOUNT_DISABLED.equals(property)) if (ProtocolProviderFactory.IS_ACCOUNT_DISABLED.equals(property))
disabled = Boolean.parseBoolean(value); disabled = Boolean.parseBoolean(value);

@ -153,6 +153,57 @@ public void testSetGetProperty() throws PropertyVetoException
property, actualReturn); property, actualReturn);
} }
/**
* Tests whether removing and getting properties works correctly.
* @throws PropertyVetoException in case someone wrongfully vetoes the
* property change.
*/
public void testRemoveProperty() throws PropertyVetoException
{
String propertyName = "my.test.property.acc1234";
Object property = new String("my.test.property's value");
configurationService.setProperty(propertyName, property);
Object actualReturn = configurationService.getProperty(propertyName);
assertEquals("a property was not properly stored",
property, actualReturn);
configurationService.removeProperty(propertyName);
Object actualReturn2 = configurationService.getProperty(propertyName);
assertNull("a property was not properly removed",
actualReturn2);
}
/**
* Tests whether removing and getting properties works correctly.
* @throws PropertyVetoException in case someone wrongfully vetoes the
* property change.
*/
public void testRemovePrefixedProperty() throws PropertyVetoException
{
// this one is used in provisioning, if we have account info like:
// net.java.sip.communicator.impl.protocol.sip.acc1sip1322067404000=acc1sip1322067404000
// we need to remove it by provisioning this:
// net.java.sip.communicator.impl.protocol.sip.acc1sip=${null}
String propertyName = "my.test.property.acc1234";
String propertyPrefixName = "my.test.property.acc";
Object property = new String("my.test.property's value");
configurationService.setProperty(propertyName, property);
Object actualReturn = configurationService.getProperty(propertyName);
assertEquals("a property was not properly stored",
property, actualReturn);
configurationService.removeProperty(propertyPrefixName);
Object actualReturn2 = configurationService.getProperty(propertyName);
assertNull("a property was not properly removed by prefix",
actualReturn2);
}
/** /**
* Tests whether setting and getting works alright for properties declared * Tests whether setting and getting works alright for properties declared
* as system and whether resolving and retrieving from the system property * as system and whether resolving and retrieving from the system property

Loading…
Cancel
Save