Skip to content

Commit

Permalink
fixes #288
Browse files Browse the repository at this point in the history
  • Loading branch information
abmargb committed Jan 21, 2015
1 parent 76e0dba commit 0171e34
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ public abstract class PubSubElementProcessorAbstract implements PubSubElementPro
protected IQ response;
protected IQ request;
protected JID actor;
protected String serverDomain;
protected String topicsDomain;
protected String node = null;
protected Helper configurationHelper;
protected Map<String, String> nodeConfiguration;
Expand Down Expand Up @@ -68,39 +66,17 @@ public void setChannelManager(ChannelManager channelManager) {
this.channelManager = channelManager;
}

public void setServerDomain(String domain) {
serverDomain = domain;
}

protected String getServerDomain() {
if (null == serverDomain) {
serverDomain = Configuration.getInstance().getProperty("server.domain");
}
return serverDomain;
}

protected Collection<JID> getAdminUsers() {
if (null == adminUsers) {
adminUsers = Configuration.getInstance().getAdminUsers();
}
return adminUsers;
}

public void setTopicsDomain(String domain) {
topicsDomain = domain;
}

public void setNode(String node) {
this.node = node;
}

protected String getTopicsDomain() {
if (null == topicsDomain) {
topicsDomain = Configuration.getInstance().getProperty("server.domain.topics");
}
return topicsDomain;
}

public void setConfigurationHelper(Helper helper) {
configurationHelper = helper;
}
Expand Down Expand Up @@ -200,7 +176,7 @@ private AccessModels getNodeAccessModel() {
}

protected boolean actorIsRegistered() {
if (actor.getDomain().equals(getServerDomain())) {
if (Configuration.getInstance().isLocalJID(actor)) {
return true;
} else {
setErrorCondition(PacketError.Type.auth, PacketError.Condition.forbidden);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ private void deleteReplies() throws NodeStoreException {
reply = replies.next();
channelManager.deleteNodeItemById(reply.getNodeId(), reply.getId());

sendNotifications(node, new GlobalItemIDImpl(new JID(this.getServerDomain()), reply.getNodeId(), reply.getId()));
sendNotifications(node, new GlobalItemIDImpl(new JID(
Configuration.getInstance().getServerDomain()), reply.getNodeId(), reply.getId()));
}
}

Expand Down Expand Up @@ -206,7 +207,8 @@ private boolean itemIdProvided() {
if (GlobalItemIDImpl.isGlobalId(id)) {
itemId = GlobalItemIDImpl.fromBuddycloudString(id);
} else {
itemId = new GlobalItemIDImpl(new JID(this.getServerDomain()), node, id);
itemId = new GlobalItemIDImpl(new JID(
Configuration.getInstance().getServerDomain()), node, id);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,15 @@ public void process(Element elm, JID actorJID, IQ reqIQ, Element rsm) throws Exc
if (null == actorJID) {
actor = request.getFrom();
}
if (!nodePresent()) {
if (!nodePresent() || !isNodeValid()) {
outQueue.put(response);
return;
}
if (!Configuration.getInstance().isLocalNode(node)) {
makeRemoteRequest();
return;
}
if ((checkNodeExists()) || (!actorIsRegistered()) || (!nodeHandledByThisServer())) {

if ((checkNodeExists()) || (!actorIsRegistered())) {
outQueue.put(response);
return;
}
Expand Down Expand Up @@ -100,16 +99,11 @@ protected boolean checkNodeExists() throws NodeStoreException {
return true;
}

private boolean nodeHandledByThisServer() {
private boolean isNodeValid() {
if (!node.matches(NODE_REG_EX)) {
setErrorCondition(PacketError.Type.modify, PacketError.Condition.bad_request);
return false;
}

if ((!node.contains("@" + getServerDomain())) && (!node.contains("@" + getTopicsDomain()))) {
setErrorCondition(PacketError.Type.modify, PacketError.Condition.not_acceptable);
return false;
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void process(Element elm, JID actorJID, IQ reqIQ, Element rsm) throws Exc
makeRemoteRequest();
return;
}
if (!checkNodeExists() || !actorIsRegistered() || !nodeHandledByThisServer()
if (!checkNodeExists() || !actorIsRegistered()
|| isEphemeralNode() || !actorAllowedToDelete()) {
outQueue.put(response);
return;
Expand Down Expand Up @@ -137,14 +137,6 @@ private boolean actorAllowedToDelete() throws NodeStoreException {
return false;
}

private boolean nodeHandledByThisServer() {
if (!node.contains("@" + getServerDomain()) && !node.contains("@" + getTopicsDomain())) {
setErrorCondition(PacketError.Type.modify, PacketError.Condition.not_acceptable);
return false;
}
return true;
}

private boolean nodeValid() {
if (!node.matches(NODE_REG_EX)) {
setErrorCondition(PacketError.Type.modify, PacketError.Condition.bad_request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public void setUp() throws Exception {
queue = new LinkedBlockingQueue<Packet>();
event = new AffiliationEvent(queue, channelManager);
request = readStanzaAsIq("/iq/pubsub/affiliation/affiliationChange.stanza");
event.setServerDomain("shakespeare.lit");

element = new BaseElement("affiliations");
element.addAttribute("node", node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ public void setUp() throws Exception {
itemDelete = new ItemDelete(queue, channelManager);
request = readStanzaAsIq("/iq/pubsub/item/delete/request.stanza");

itemDelete.setServerDomain("shakespeare.lit");

element = new BaseElement("retract");
element.addAttribute("node", node);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public void setUp() throws Exception {
jid = new JID("[email protected]");
request = readStanzaAsIq("/iq/pubsub/channel/configure/request.stanza");

nodeConfigure.setServerDomain("shakespeare.lit");

element = new BaseElement("create");
element.addAttribute("node", "/user/[email protected]/posts");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public void setUp() throws Exception {
jid = new JID("[email protected]");
request = readStanzaAsIq("/iq/pubsub/channel/create/request.stanza");

nodeCreate.setServerDomain("shakespeare.lit");

element = new BaseElement("create");
element.addAttribute("node", node);
}
Expand Down Expand Up @@ -106,6 +104,11 @@ public void testRequestingAlreadyExistingNodeReturnsErrorStanza()
public void testUnauthenticatedUserCanNotCreateNode() throws Exception {
JID jid = new JID("[email protected]");

Configuration.getInstance().remove(
Configuration.CONFIGURATION_LOCAL_DOMAIN_CHECKER);
Configuration.getInstance().putProperty(
Configuration.CONFIGURATION_SERVER_DOMAIN, "shakespeare.lit");

nodeCreate.process(element, jid, request, null);
Packet response = queue.poll(100, TimeUnit.MILLISECONDS);

Expand Down Expand Up @@ -139,26 +142,24 @@ public void testInvalidlyFormattedNodeReturnsError() throws Exception {
}

@Test
public void testNewNodeMustBeOnADomainSupportedByCurrentServer()
throws Exception {
public void testNodeFromUnknownDomain() throws Exception {
element.addAttribute("node", "/user/capulet@shakespearelit/posts");

nodeCreate.setTopicsDomain("topics.shakespeare.lit");

Configuration.getInstance().putProperty(
Configuration.CONFIGURATION_LOCAL_DOMAIN_CHECKER, Boolean.FALSE.toString());

nodeCreate.process(element, jid, request, null);
Packet response = queue.poll(100, TimeUnit.MILLISECONDS);

PacketError error = response.getError();
Assert.assertNotNull(error);
Assert.assertEquals(PacketError.Type.modify, error.getType());
Assert.assertEquals(PacketError.Condition.not_acceptable, error.getCondition());
Assert.assertNull(response.getError());
Assert.assertNotNull(response.getElement().element("pubsub").element("actor"));
/**
* Add this check back in once Tinder supports xmlns on standard
* conditions Assert.assertEquals(JabberPubsub.NS_XMPP_STANZAS,
* error.getApplicationConditionNamespaceURI());
*/
}

@Test
public void testchannelManagerFailureReturnsInternalServerErrorResponse()
throws Exception {
Expand Down Expand Up @@ -270,4 +271,5 @@ public void testFailingNodeConfigurationReturnsErrorStanza()
* error.getApplicationConditionNamespaceURI());
*/
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public void setUp() throws Exception {

this.queue = new LinkedBlockingQueue<Packet>();
this.nodeDelete = new NodeDelete(queue, channelManager);
this.nodeDelete.setServerDomain("shakespeare.lit");
this.element = new BaseElement("delete");
Configuration.getInstance().putProperty(Configuration.CONFIGURATION_LOCAL_DOMAIN_CHECKER,
Boolean.TRUE.toString());
Expand Down Expand Up @@ -139,8 +138,13 @@ public void testNotRegisteredActor() throws Exception {

String node = deleteEl.attributeValue("node");
Mockito.when(channelManager.nodeExists(node)).thenReturn(true);
nodeDelete.setServerDomain("fake.domain");

Configuration.getInstance().remove(
Configuration.CONFIGURATION_LOCAL_DOMAIN_CHECKER);
Configuration.getInstance().putProperty(
Configuration.CONFIGURATION_SERVER_DOMAIN, "shakespeare.lit");

JID jid = new JID("[email protected]");
nodeDelete.process(deleteEl, jid, request, null);
Packet response = queue.poll();

Expand Down Expand Up @@ -214,13 +218,14 @@ public void testNodeFromUnknownDomain() throws Exception {
String node = deleteEl.attributeValue("node");
Mockito.when(channelManager.nodeExists(node)).thenReturn(true);

Configuration.getInstance().putProperty(
Configuration.CONFIGURATION_LOCAL_DOMAIN_CHECKER, Boolean.FALSE.toString());

nodeDelete.process(deleteEl, jid, request, null);
Packet response = queue.poll();

PacketError error = response.getError();
Assert.assertNotNull(error);
Assert.assertEquals(PacketError.Type.modify, error.getType());
Assert.assertEquals(PacketError.Condition.not_acceptable, error.getCondition());
Assert.assertNull(response.getError());
Assert.assertNotNull(response.getElement().element("pubsub").element("actor"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public void setUp() throws Exception {
jid = new JID("[email protected]/balcony");
request = readStanzaAsIq("/iq/pubsub/publish/request.stanza");

publish.setServerDomain("shakespeare.lit");
publish.setChannelManager(channelManager);
publish.setEntryValidator(validateEntry);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public void setUp() throws Exception {
queue = new LinkedBlockingQueue<Packet>();
subscribe = new SubscribeSet(queue, channelManager);
request = readStanzaAsIq("/iq/pubsub/subscribe/request.stanza");
subscribe.setServerDomain("shakespeare.lit");

element = new BaseElement("subscribe");
element.addAttribute("node", node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public void setUp() throws Exception {
queue = new LinkedBlockingQueue<Packet>();
event = new SubscriptionEvent(queue, dataStore);
request = readStanzaAsIq("/iq/pubsub/subscribe/authorizationPendingGrantReply.stanza");
event.setServerDomain("shakespeare.lit");

element = new BaseElement("subscriptions");
element.addAttribute("node", node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public void setUp() throws Exception {
queue = new LinkedBlockingQueue<Packet>();
unsubscribe = new UnsubscribeSet(queue, channelManager);
request = readStanzaAsIq("/iq/pubsub/unsubscribe/request.stanza");
unsubscribe.setServerDomain("shakespeare.lit");

element = new BaseElement("unsubscribe");
element.addAttribute("node", node);
Expand Down

0 comments on commit 0171e34

Please sign in to comment.