Skip to content

Commit

Permalink
Test for Actor validation improvements
Browse files Browse the repository at this point in the history
* test with an iq originating from not-denmark domain, with actor from the
  denmark domain.
* previously this would have been treated as valid, it is now rejected as
  invalid.
  • Loading branch information
ian-green committed Sep 30, 2015
1 parent cecb3ce commit 35e5869
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@

import org.buddycloud.channelserver.channel.ChannelManager;
import org.buddycloud.channelserver.packetHandler.iq.IQTestHandler;
import org.buddycloud.channelserver.packetprocessor.iq.namespace.pubsub.get.AffiliationsGet;
import org.buddycloud.channelserver.utils.XMLConstants;
import org.buddycloud.channelserver.utils.node.item.payload.Buddycloud;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.xmpp.packet.IQ;
import org.xmpp.packet.JID;
import org.xmpp.packet.Packet;
import org.xmpp.packet.PacketError;
import org.xmpp.util.XMPPConstants;

public class PubSubSetTest extends IQTestHandler {

Expand All @@ -31,15 +28,15 @@ public void setUp() throws Exception {
pubsubSet = new PubSubSet(queue, channelManager);
pubsubSet.purgeElementProcessors();
}

@Test
public void returnsErrorForIllegalActor() throws Exception {
IQ request = readStanzaAsIq("/iq/pubsub/bad-actor.stanza");

pubsubSet.process(request);
Assert.assertEquals(1, queue.size());
IQ response = (IQ) queue.poll();

Assert.assertEquals(IQ.Type.error, response.getType());

PacketError error = response.getError();
Expand All @@ -49,24 +46,45 @@ public void returnsErrorForIllegalActor() throws Exception {
Assert.assertNotNull(response.getElement().element("error").element(XMLConstants.POLICY_VIOLATION));
Assert.assertEquals(XMLConstants.INVALID_NODE, error.getApplicationConditionName());
Assert.assertEquals(Buddycloud.NS_ERROR, error.getApplicationConditionNamespaceURI());


}

@Test
public void returnsErrorForSpoofActor() throws Exception {
IQ request = readStanzaAsIq("/iq/pubsub/spoof-actor.stanza");

pubsubSet.process(request);
Assert.assertEquals(1, queue.size());
IQ response = (IQ) queue.poll();

Assert.assertEquals(IQ.Type.error, response.getType());

PacketError error = response.getError();
Assert.assertNotNull(error);

Assert.assertEquals(PacketError.Type.cancel, error.getType());
Assert.assertNotNull(response.getElement().element("error")
.element(XMLConstants.POLICY_VIOLATION));
Assert.assertEquals(XMLConstants.INVALID_NODE, error.getApplicationConditionName());
Assert.assertEquals(Buddycloud.NS_ERROR, error.getApplicationConditionNamespaceURI());

}

@Test
public void ifPacketCanNotBeProcessedShouldReceiveAFeatureNotImplementedError() throws Exception {
IQ request = readStanzaAsIq("/iq/pubsub/good-actor.stanza");

pubsubSet.process(request);
Assert.assertEquals(1, queue.size());
IQ response = (IQ) queue.poll();

Assert.assertEquals(IQ.Type.error, response.getType());

PacketError error = response.getError();
Assert.assertNotNull(error);

Assert.assertEquals(PacketError.Type.cancel, error.getType());
Assert.assertEquals(PacketError.Condition.feature_not_implemented, error.getCondition());
}

}
9 changes: 9 additions & 0 deletions src/test/resources/stanzas/iq/pubsub/spoof-actor.stanza
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<iq type="get"
from="channels.not-denmark.lit"
to="channels.shakespeare.lit"
id="items1">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
<items node="/user/francisco@denmark.lit/posts"/>
<actor xmlns="http://buddycloud.org/v1">francisco@denmark.lit</actor>
</pubsub>
</iq>

0 comments on commit 35e5869

Please sign in to comment.