diff --git a/src/main/java/org/buddycloud/channelserver/channel/node/configuration/Helper.java b/src/main/java/org/buddycloud/channelserver/channel/node/configuration/Helper.java index cb99bc6f..d5bd0a67 100644 --- a/src/main/java/org/buddycloud/channelserver/channel/node/configuration/Helper.java +++ b/src/main/java/org/buddycloud/channelserver/channel/node/configuration/Helper.java @@ -1,6 +1,7 @@ package org.buddycloud.channelserver.channel.node.configuration; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; @@ -123,8 +124,18 @@ private List getConfigurationValuesFromDisco(IQ request) { } private List getConfigurationValues(IQ request) { - Element element = request.getElement().element("pubsub") - .element("configure").element("x"); + Element configure = request.getElement().element("pubsub").element("configure"); + + if(configure == null) { + return Collections.emptyList(); + } + + Element element = configure.element("x"); + + if(element == null) { + return Collections.emptyList(); + } + DataForm dataForm = new DataForm(element); List fields = dataForm.getFields(); return fields; diff --git a/src/test/java/org/buddycloud/channelserver/channel/node/configuration/HelperTest.java b/src/test/java/org/buddycloud/channelserver/channel/node/configuration/HelperTest.java index 5261feda..0e399453 100644 --- a/src/test/java/org/buddycloud/channelserver/channel/node/configuration/HelperTest.java +++ b/src/test/java/org/buddycloud/channelserver/channel/node/configuration/HelperTest.java @@ -48,15 +48,6 @@ public void setUp() { parser.setFieldFactory(new Factory()); } - @Test(expected = NodeConfigurationException.class) - public void testPassingPacketWhichDoesntContainConfigureElementThrowsException() { - Element iq = new DOMElement("iq"); - iq.addElement("pubsub", JabberPubsub.NS_PUBSUB_OWNER); - IQ request = new IQ(iq); - - parser.parse(request); - } - @Test public void testNotProvidingAnyConfigurationFieldsReturnsOnlyLastUpdatedDate() throws NodeStoreException { @@ -382,4 +373,35 @@ public void testRequiredFieldsGetSetIfNotPresentInExistingData() throws Exceptio Assert.assertNotNull(configurationValues.get(LastUpdatedDate.FIELD_NAME)); } + + /** + * We expect this to not throw a {@link NodeConfigurationException} + * + * @see https://github.com/buddycloud/buddycloud-server-java/issues/200 + */ + @Test + public void testParseIQWithMissingForm() { + Element iq = new DOMElement("iq"); + Element pubsub = iq.addElement("pubsub"); + pubsub.addAttribute("xmlns", JabberPubsub.NS_PUBSUB_OWNER); + pubsub.addElement("configure"); + + IQ request = new IQ(iq); + parser.parse(request); + } + + /** + * We expect this to not throw a {@link NodeConfigurationException} + * + * @see https://github.com/buddycloud/buddycloud-server-java/issues/200 + */ + @Test + public void testParseIQWithMissingConfigure() { + Element iq = new DOMElement("iq"); + Element pubsub = iq.addElement("pubsub"); + pubsub.addAttribute("xmlns", JabberPubsub.NS_PUBSUB_OWNER); + + IQ request = new IQ(iq); + parser.parse(request); + } } \ No newline at end of file