Commit 52bfdc80 authored by Nate Putnam's avatar Nate Putnam Committed by nate

Removed tests. They were written for testng originally, the rest of OF uses...

Removed tests. They were written for testng originally, the rest of OF uses JUnit so if the tests are rewritten it should be done using that. Turns out testing is with plugins is really hard due to all the static managers.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@10333 b35dd754-fafc-0310-a699-88a17e54d16e
parent 2f92754c
package org.jivesoftware.openfire.plugin.packetfilter.test;
import org.jivesoftware.openfire.plugin.rules.RuleManager;
import org.jivesoftware.openfire.plugin.rules.Rule;
import java.util.List;
import java.util.ArrayList;
public class MockRuleManager implements RuleManager {
List<Rule> rules = new ArrayList<Rule>();
public Rule getRuleById(int id) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public List<Rule> getRules() {
return rules;
}
public void addRule(Rule rule, Integer order) {
rules.add(order,rule);
}
public void addRule(Rule rule) {
rules.add(rule);
}
public void deleteRule(String ruleId) {
//To change body of implemented methods use File | Settings | File Templates.
}
public void moveOne(int srcId, int destId) {
//To change body of implemented methods use File | Settings | File Templates.
}
public int getLastOrder() {
return 0; //To change body of implemented methods use File | Settings | File Templates.
}
public void moveRuleOrder(int ruleId, int orderId) {
//To change body of implemented methods use File | Settings | File Templates.
}
public void updateRule(Rule rule) {
//To change body of implemented methods use File | Settings | File Templates.
}
public void rulesUpdated() {
//To change body of implemented methods use File | Settings | File Templates.
}
}
package org.jivesoftware.openfire.plugin.packetfilter.test;
import org.jivesoftware.openfire.group.Group;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.plugin.PacketFilter;
import org.jivesoftware.openfire.plugin.rules.Drop;
import org.jivesoftware.openfire.plugin.rules.Rule;
import org.jivesoftware.openfire.plugin.rules.RuleManager;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.xmpp.packet.IQ;
import org.xmpp.packet.Message;
import org.xmpp.packet.Presence;
public class PacketFilterTest {
private PacketFilter packetFilter;
private RuleManager rmp;
@BeforeClass
public void setup() {
//Create a packetFilter
packetFilter = PacketFilter.getInstance();
rmp = new MockRuleManager();
packetFilter.setRuleManager(rmp);
}
@Test(groups = {"default"}, expectedExceptions = PacketRejectedException.class)
public void testDropMessage() throws PacketRejectedException {
//Create some rules
Rule drop = new Drop();
drop.setSource("bart@localhost");
drop.setSourceType("User");
drop.setDestination("Any");
drop.setDestType("Any");
drop.isDisabled(false);
drop.setPacketType(Rule.PacketType.Message);
drop.doLog(false);
rmp.addRule(drop);
Message message = new Message();
message.setFrom("bart@localhost");
message.setTo("lisa@localhost");
Rule rule = packetFilter.findMatch(message);
assert (rule != null);
rule.doAction(message);
}
@Test(groups = {"default"}, expectedExceptions = PacketRejectedException.class)
public void testDropIQ() throws PacketRejectedException {
//Create some rules
Rule drop = new Drop();
drop.setSource("bart@localhost");
drop.setSourceType("User");
drop.setDestination("Any");
drop.setDestType("Any");
drop.isDisabled(false);
drop.setPacketType(Rule.PacketType.Iq);
drop.doLog(false);
rmp.addRule(drop);
IQ iq = new IQ();
iq.setFrom("bart@localhost");
iq.setTo("lisa@localhost");
Rule rule = packetFilter.findMatch(iq);
assert (rule != null);
rule.doAction(iq);
}
@Test(groups = {"default"}, expectedExceptions = PacketRejectedException.class)
public void testDropPresence() throws PacketRejectedException {
//Create some rules
Rule drop = new Drop();
drop.setSource("bart@localhost");
drop.setSourceType("User");
drop.setDestination("Any");
drop.setDestType("Any");
drop.isDisabled(false);
drop.setPacketType(Rule.PacketType.Presence);
drop.doLog(false);
rmp.addRule(drop);
Presence presence = new Presence();
presence.setFrom("bart@localhost");
presence.setTo("lisa@localhost");
Rule rule = packetFilter.findMatch(presence);
assert (rule != null);
rule.doAction(presence);
}
@Test(groups = {"default"}, expectedExceptions = PacketRejectedException.class)
public void testDropAnyType() throws PacketRejectedException {
//Create some rules
Rule drop = new Drop();
drop.setSource("bart@localhost");
drop.setSourceType(Rule.SourceDestType.User.toString());
drop.setDestination("Any");
drop.setDestType(Rule.SourceDestType.Any.toString());
drop.isDisabled(false);
drop.setPacketType(Rule.PacketType.Any);
drop.doLog(false);
rmp.addRule(drop);
Presence presence = new Presence();
presence.setFrom("bart@localhost");
presence.setTo("lisa@localhost");
Rule rule = packetFilter.findMatch(presence);
assert (rule != null);
rule.doAction(presence);
}
/*@Test(groups = {"default"}, expectedExceptions = PacketRejectedException.class)
public void testGroupDrop() throws PacketRejectedException {
Group
} */
}
package org.jivesoftware.openfire.plugin.packetfilter.test;
import org.jivesoftware.openfire.plugin.PacketFilterUtil;
import org.xmpp.packet.JID;
public class Test {
public static void main(String... args) {
String jid = JID.escapeNode("test@domain1.com@otherdomain.com");
String allDomain = "*@domain1.com@otherdomain.com";
System.out.println(matchUser(allDomain,jid));
}
public static String getComponent(String jid) {
if (jid.contains("@")) {
int atIndex = jid.indexOf("@");
return (jid.substring(atIndex,jid.length()));
}
else {
return jid;
}
}
public static String getDomain(String jid) {
return getComponent(jid);
}
public static boolean isJID(String jid) {
if (jid != null &&
(jid.split("@").length == 1) &&
jid.length() < 255 &&
jid.trim().length() > 0) {
return true;
} else return false;
}
private static boolean matchUser(String ruleToFrom, String packetToFrom) {
boolean match = false;
packetToFrom = JID.unescapeNode(packetToFrom);
if (ruleToFrom.indexOf("*") == 0 && ruleToFrom.indexOf("@") == 1) {
System.out.println(getDomain(ruleToFrom));
System.out.println(getDomain(packetToFrom));
if (getDomain(ruleToFrom).equals(getDomain(packetToFrom))) {
match = true;
}
}
else {
if (ruleToFrom.equals(packetToFrom)) {
match = true;
}
}
return match;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment