Skip to content

Commit e29c533

Browse files
author
Lloyd Watkin
committed
Test that error packets don't get remapped
1 parent 9254336 commit e29c533

2 files changed

Lines changed: 31 additions & 7 deletions

File tree

src/main/java/org/buddycloud/channelserver/queue/FederatedQueueManager.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,19 @@ private int getId() {
7171

7272
public void process(Packet packet) throws ComponentException {
7373

74-
logger.debug("Packet payload " + packet.toXML() + " going to federation.");
74+
logger.debug("Packet payload " + packet.toXML()
75+
+ " going to federation.");
7576

7677
String to = packet.getTo().toString();
77-
String uniqueId = packet.getID();
78-
79-
if (true == performIdMapping(packet)) {
78+
String uniqueId = packet.getID();
79+
80+
if (true == performIdMapping(packet)) {
8081

8182
uniqueId = generateUniqueId(packet);
8283
idMap.put(uniqueId, packet.getID());
8384
packet.setID(uniqueId);
84-
}
85-
85+
}
86+
8687
sentRemotePackets.put(uniqueId, packet.getFrom());
8788
try {
8889
extractNodeDetails(packet);
@@ -123,7 +124,8 @@ private boolean performIdMapping(Packet packet) {
123124
return false;
124125
}
125126
IQ iq = (IQ) packet;
126-
if (true == iq.getType().equals(IQ.Type.result)) {
127+
if ((true == iq.getType().equals(IQ.Type.result))
128+
|| (true == iq.getType().equals(IQ.Type.error))) {
127129
return false;
128130
}
129131
return true;

src/test/java/org/buddycloud/channelserver/queue/FederatedQueueManagerTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,4 +296,26 @@ public void testIqResultPacketsDontGetIdMapped() throws Exception {
296296

297297
Assert.assertTrue(originalId.equals(packetExternal.getID()));
298298
}
299+
300+
301+
@Test
302+
public void testIqErrorPacketsDontGetIdMapped() throws Exception {
303+
channelsEngine.clear();
304+
305+
String originalId = "id:12345";
306+
IQ packet = new IQ();
307+
packet.setFrom(new JID("romeo@montague.lit/street"));
308+
packet.setTo(new JID("topics.capulet.lit"));
309+
packet.setType(IQ.Type.error);
310+
packet.setID(originalId);
311+
packet.getElement().addAttribute("remote-server-discover", "false");
312+
313+
queueManager.addChannelMap(new JID("topics.capulet.lit"));
314+
315+
queueManager.process(packet.createCopy());
316+
317+
IQ packetExternal = (IQ) channelsEngine.poll();
318+
319+
Assert.assertTrue(originalId.equals(packetExternal.getID()));
320+
}
299321
}

0 commit comments

Comments
 (0)