Commit d3b1632b authored by Alex Wenckus's avatar Alex Wenckus Committed by alex

Added check to ensure that user is a local user before updating a vCard. JM-1084

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@8521 b35dd754-fafc-0310-a699-88a17e54d16e
parent 7fb15f23
......@@ -12,6 +12,9 @@
<sourceFolder url="file://$MODULE_DIR$/../../src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/../../src/test/resources" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/../../src/test/throttletest/src" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/../../src/test/unit" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/../../make" />
<excludeFolder url="file://$MODULE_DIR$/../../target" />
<excludeFolder url="file://$MODULE_DIR$/../../work" />
</content>
<orderEntry type="inheritedJdk" />
......@@ -396,6 +399,60 @@
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../lib/jmock.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../lib/jmock-junit4.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../lib/hamcrest-library.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../lib/hamcrest-api.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../lib/objenesis.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../lib/cglib-nodep.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntryProperties />
</component>
</module>
......
......@@ -305,7 +305,38 @@
<component name="ProjectRootManager" version="2" assert-keyword="true" jdk-15="true" project-jdk-name="JDK 1.5.0" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/../../target" />
</component>
<component name="ProjectRunConfigurationManager" />
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Unit Tests" type="JUnit" factoryName="JUnit" enabled="false" merge="false">
<module name="Admin" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" value="" />
<option name="PACKAGE_NAME" value="org.jivesoftware.openfire.handler" />
<option name="MAIN_CLASS_NAME" value="" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="package" />
<option name="VM_PARAMETERS" value="" />
<option name="PARAMETERS" value="" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
<option name="ADDITIONAL_CLASS_PATH" />
<option name="TEST_SEARCH_SCOPE">
<value defaultName="wholeProject" />
</option>
<RunnerSettings RunnerId="Debug">
<option name="DEBUG_PORT" value="1297" />
<option name="TRANSPORT" value="0" />
<option name="LOCAL" value="true" />
</RunnerSettings>
<RunnerSettings RunnerId="JProfiler">
<option name="WINDOW" value="false" />
<option name="JVMPI" value="false" />
<option name="INTERPRETED" value="false" />
</RunnerSettings>
<ConfigurationWrapper RunnerId="Debug" />
<method>
<option name="Make" value="true" />
</method>
</configuration>
</component>
<component name="RmicSettings">
<option name="IS_EANABLED" value="false" />
<option name="DEBUGGING_INFO" value="true" />
......
......@@ -75,13 +75,14 @@ public class IQvCardHandler extends IQHandler {
IQ result = IQ.createResultIQ(packet);
IQ.Type type = packet.getType();
if (type.equals(IQ.Type.set)) {
if(vCardManager.isReadOnly()) {
JID userJid = packet.getFrom();
if(vCardManager.isReadOnly() || !server.isLocal(userJid)) {
result.setChildElement(packet.getChildElement().createCopy());
result.setError(PacketError.Condition.not_allowed);
}
else {
try {
User user = userManager.getUser(packet.getFrom().getNode());
User user = userManager.getUser(userJid.getNode());
Element vcard = packet.getChildElement();
vCardManager.setVCard(user.getUsername(), vcard);
}
......
......@@ -24,6 +24,7 @@ import org.jivesoftware.openfire.user.User;
import org.jivesoftware.openfire.user.UserNotFoundException;
import org.jivesoftware.openfire.vcard.VCardManager;
import org.xmpp.packet.IQ;
import org.xmpp.packet.JID;
import static org.junit.Assert.*;
import org.dom4j.Element;
......@@ -81,6 +82,31 @@ public class IQvCardHandlerTest {
assertEquals(result.getType(), IQ.Type.error);
}
@Test
public void testVCardHandlerSetUserNotLocal() throws UnauthorizedException {
IQ vCardSet = new IQ(IQ.Type.set);
vCardSet.setFrom("test@example.com");
vCardSet.setChildElement("vCard", "vcard-temp");
final VCardManager vCardManager = context.mock(VCardManager.class);
IQvCardHandler vCardHandler = new IQvCardHandler();
context.checking(new Expectations() {{
one(xmppServer).getVCardManager();
will(returnValue(vCardManager));
one(vCardManager).isReadOnly();
will(returnValue(false));
one(xmppServer).isLocal(with(a(JID.class)));
will(returnValue(false));
}});
vCardHandler.initialize(xmppServer);
IQ result = vCardHandler.handleIQ(vCardSet);
assertEquals(result.getType(), IQ.Type.error);
}
@Test
public void testVCardHandlerSet() throws UnauthorizedException {
IQ vCardSet = new IQ(IQ.Type.set);
......@@ -98,6 +124,9 @@ public class IQvCardHandlerTest {
one(vCardManager).isReadOnly();
will(returnValue(false));
one(xmppServer).isLocal(new JID("test@test.com"));
will(returnValue(true));
try {
one(userManager).getUser(with(a(String.class)));
}
......@@ -120,4 +149,16 @@ public class IQvCardHandlerTest {
IQ result = vCardHandler.handleIQ(vCardSet);
assertEquals(result.getType(), IQ.Type.result);
}
//
// @Test
// public void testVCardHandlerGetNotFound() {
// IQ vCardSet = new IQ(IQ.Type.get);
// vCardSet.setFrom("test@test.com");
// vCardSet.setChildElement("vCard", "vcard-temp");
//
// context.checking(new Expectations(){{
// one(xmppServer).isLocal(new JID("test@test.com"));
// will(returnValue(true));
// }});
// }
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment