Skip to content

Commit 00d003c

Browse files
author
Lloyd Watkin
committed
Merge branch 'issues/230'
2 parents fc33b6e + 6f90a97 commit 00d003c

4 files changed

Lines changed: 80 additions & 13 deletions

File tree

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,25 @@ protected void setErrorCondition(Type type, Condition condition) {
108108

109109
protected void createExtendedErrorReply(Type type, Condition condition,
110110
String additionalElement) {
111+
if ((null != additionalElement) && (additionalElement.indexOf(" ") > -1)) {
112+
// Its probably an error message!
113+
createExtendedErrorReply(type, condition, null, null, additionalElement);
114+
return;
115+
}
111116
createExtendedErrorReply(type, condition, additionalElement,
112117
JabberPubsub.NS_PUBSUB_ERROR);
113118
}
114119

115120
protected void createExtendedErrorReply(Type type, Condition condition,
116121
String additionalElement, String additionalNamespace) {
117-
122+
createExtendedErrorReply(type, condition, additionalElement,
123+
additionalNamespace, null);
124+
}
125+
126+
127+
protected void createExtendedErrorReply(Type type, Condition condition,
128+
String additionalElement, String additionalNamespace, String text) {
129+
118130
if (null == response) {
119131
response = IQ.createResultIQ(request);
120132
}
@@ -127,6 +139,14 @@ protected void createExtendedErrorReply(Type type, Condition condition,
127139
error.addAttribute("type", type.toXMPP());
128140
error.add(standardError);
129141
error.add(extraError);
142+
if (null != text) {
143+
Element description = new DOMElement(
144+
"text",
145+
new org.dom4j.Namespace("", "urn:ietf:params:xml:ns:xmpp-stanzas")
146+
);
147+
description.setText(text);
148+
error.add(description);
149+
}
130150
response.setChildElement(error);
131151
}
132152

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

Lines changed: 13 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,15 @@ 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(
108+
Type.modify,
109+
Condition.bad_request,
110+
"Could not parse the 'after' id: "
111+
+ after.getTextTrim());
112+
return false;
110113
}
111114
}
115+
return true;
112116
}
113117

114118
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)