Skip to content

Commit 6f8559a

Browse files
author
Lloyd Watkin
committed
Fix RSM error in UserItemsGet
1 parent ad4c1ec commit 6f8559a

4 files changed

Lines changed: 72 additions & 13 deletions

File tree

src/main/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/PubSubElementProcessorAbstract.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,14 @@ protected void createExtendedErrorReply(Type type, Condition condition,
114114

115115
protected void createExtendedErrorReply(Type type, Condition condition,
116116
String additionalElement, String additionalNamespace) {
117-
117+
createExtendedErrorReply(type, condition, additionalElement,
118+
additionalNamespace, null);
119+
}
120+
121+
122+
protected void createExtendedErrorReply(Type type, Condition condition,
123+
String additionalElement, String additionalNamespace, String text) {
124+
118125
if (null == response) {
119126
response = IQ.createResultIQ(request);
120127
}
@@ -127,6 +134,14 @@ protected void createExtendedErrorReply(Type type, Condition condition,
127134
error.addAttribute("type", type.toXMPP());
128135
error.add(standardError);
129136
error.add(extraError);
137+
if (null != text) {
138+
Element description = new DOMElement(
139+
"text",
140+
new org.dom4j.Namespace("", "urn:ietf:params:xml:ns:xmpp-stanzas")
141+
);
142+
description.setText(text);
143+
error.add(description);
144+
}
130145
response.setChildElement(error);
131146
}
132147

src/main/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/get/UserItemsGet.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ public void process(Element elm, JID actorJID, IQ reqIQ, Element rsm)
7373
pubsub = response.getElement().addElement("pubsub",
7474
JabberPubsub.NAMESPACE_URI);
7575
try {
76-
parseRsmElement();
77-
addRecentItems();
78-
addRsmElement();
79-
outQueue.put(response);
76+
if (true == parseRsmElement()) {
77+
addRecentItems();
78+
addRsmElement();
79+
}
8080
} catch (NodeStoreException e) {
8181
LOGGER.error(e);
8282
response.getElement().remove(pubsub);
@@ -87,9 +87,9 @@ public void process(Element elm, JID actorJID, IQ reqIQ, Element rsm)
8787

8888
}
8989

90-
private void parseRsmElement() {
90+
private boolean parseRsmElement() {
9191
if (null == resultSetManagement) {
92-
return;
92+
return true;
9393
}
9494

9595
Element max = null;
@@ -104,11 +104,12 @@ private void parseRsmElement() {
104104
.getTextTrim());
105105
} catch (IllegalArgumentException e) {
106106
LOGGER.error(e);
107-
createExtendedErrorReply(Type.modify, Condition.bad_request,
108-
"Could not parse the 'after' id: " + after);
109-
return;
107+
createExtendedErrorReply(Type.modify, Condition.bad_request, null, null,
108+
"Could not parse the 'after' id: " + after.getTextTrim());
109+
return false;
110110
}
111111
}
112+
return true;
112113
}
113114

114115
private void addRsmElement() throws NodeStoreException {

src/main/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/get/items/special/FirehoseGet.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,17 @@ private void determineAdminUserStatus() {
102102

103103
private void parseRsmElement() {
104104
Element rsmElement = pubsub.element("set");
105-
if (null == rsmElement)
105+
if (null == rsmElement) {
106106
return;
107+
}
107108
Element max;
108109
Element after;
109-
if (null != (max = rsmElement.element("max")))
110+
if (null != (max = rsmElement.element("max"))) {
110111
maxResults = Integer.parseInt(max.getTextTrim());
111-
if (null != (after = rsmElement.element("after")))
112+
}
113+
if (null != (after = rsmElement.element("after"))) {
112114
afterItemId = after.getTextTrim();
115+
}
113116
}
114117

115118
private void addRsmElement() throws NodeStoreException {

src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/get/UserItemsGetTest.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,4 +412,44 @@ public void whenRequestingParentOnlyCorrectFlagIsSetOnDatabaseRequest()
412412
Mockito.anyInt(), Mockito.any(GlobalItemID.class),
413413
Mockito.eq(true));
414414
}
415+
416+
/**
417+
* Issue #230
418+
*/
419+
@Test
420+
public void badRsmValueReturnsValidError() throws Exception {
421+
422+
String after = "/user/demo@buddycloud.com/posts/example.com|94948";
423+
Element rsm = new BaseElement(new QName("set", new Namespace("",
424+
"http://jabber.org/protocol/rsm")));
425+
rsm.addElement("after")
426+
.setText(after);
427+
428+
String stanza = "<iq type=\"get\" to=\"channels.buddycloud.org\" " +
429+
"from=\"test.user@buddycloud.org/resource\" id=\"id:1\">" +
430+
"<pubsub xmlns=\"http://jabber.org/protocol/pubsub\">" +
431+
"<user-items xmlns=\"http://buddycloud.org/v1\" parent-only=\"true\" " +
432+
"since=\"2000-01-01T00:00:00.000Z\"/>" +
433+
"<set xmlns=\"http://jabber.org/protocol/rsm\">" +
434+
"<max>10</max>" +
435+
"<after>/user/demo@buddycloud.com/posts/example.com|94948</after>" +
436+
"</set>" +
437+
"</pubsub>" +
438+
"</iq>";
439+
IQ request = this.toIq(stanza);
440+
441+
userItemsGet.process(element, jid, request, rsm);
442+
Assert.assertEquals(1, queue.size());
443+
444+
IQ response = (IQ) queue.poll();
445+
PacketError errorPacket = response.getError();
446+
Assert.assertEquals(
447+
"Could not parse the 'after' id: " + after,
448+
errorPacket.getText()
449+
);
450+
Assert.assertEquals(PacketError.Condition.bad_request, errorPacket.getCondition());
451+
Assert.assertEquals(PacketError.Type.modify, errorPacket.getType());
452+
453+
454+
}
415455
}

0 commit comments

Comments
 (0)