Commit 61c50d9b authored by conor's avatar conor

minor fixes based on test feedback

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3266 b35dd754-fafc-0310-a699-88a17e54d16e
parent ab2513da
......@@ -8,8 +8,8 @@
<name>Content Filter</name>
<description>Scans message packets for defined patterns</description>
<author>Conor Hayes</author>
<version>1.0.1</version>
<date>12/15/2005</date>
<version>1.2</version>
<date>01/09/2005</date>
<minServerVersion>2.4.0</minServerVersion>
<!-- UI extension -->
......
......@@ -92,10 +92,16 @@ is useful.
The default mask is "***", you can change it to anything you like including smilies!
</p>
<h2>Using the Plugin</h2>
<h2>Using the plugin</h2>
<p>
After the plugin has been configured, nothing else needs to be done to use it.
</p>
<h2>Trouble shooting</h2>
<p>
If the plugin behaviour is not as expected you can enable server debug logging. This will allow the plugin to start logging.
Server debug logging should only be enabled temporarily, as it will generate a lot of additional logging that will both slow
your server down and consume a lot of disk space.
</p>
</body>
</html>
......@@ -454,8 +454,8 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
if (contentMatched && violationNotificationEnabled) {
if (Log.isDebugEnabled()) {
Log.debug("Content filter: sending violation notification.");
Log.debug("Content filter: include original msg?" +
Log.debug("Content filter: sending violation notification");
Log.debug("Content filter: include original msg? " +
this.violationIncludeOriginalPacketEnabled);
}
......@@ -473,7 +473,7 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
} else {
//no masking, msg must be rejected
if (Log.isDebugEnabled()) {
Log.debug("Content filter: rejecting packet.");
Log.debug("Content filter: rejecting packet");
}
PacketRejectedException rejected = new PacketRejectedException(
......@@ -500,6 +500,7 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
private void sendViolationNotification(Packet originalPacket) {
String subject = "Content filter notification!";
String body = null;
if (originalPacket instanceof Message) {
Message originalMsg = (Message) originalPacket;
......@@ -525,20 +526,25 @@ public class ContentFilterPlugin implements Plugin, PacketInterceptor {
if (violationNotificationByIMEnabled) {
if (Log.isDebugEnabled()) {
Log.debug("Sending IM notification");
Log.debug("Content filter: sending IM notification");
}
messageRouter.route(createServerMessage(subject, body));
sendViolationNotificationIM(subject, body);
}
if (violationNotificationByEmailEnabled) {
if (Log.isDebugEnabled()) {
Log.debug("Sending email notification");
Log.debug("Content filter: sending email notification");
}
sendViolationNotificationEmail(subject, body);
}
}
private void sendViolationNotificationIM(String subject, String body) {
Message message = createServerMessage(subject, body);
messageRouter.route(message);
}
private Message createServerMessage(String subject, String body) {
Message message = new Message();
message.setTo(violationContact + "@"
......
package org.jivesoftware.wildfire.plugin;
import java.io.IOException;
import java.io.StringReader;
import java.util.regex.PatternSyntaxException;
import junit.framework.TestCase;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.XPPPacketReader;
import org.xmlpull.v1.XmlPullParserException;
import org.xmpp.packet.Message;
import org.xmpp.packet.Presence;
/**
* Basic unit tests for ContentFilter.
......@@ -23,13 +30,16 @@ public class ContentFilterTest extends TestCase {
*/
protected void setUp() throws Exception {
filter = new ContentFilter();
}
/*
* @see TestCase#tearDown()
*/
protected void tearDown() throws Exception {
super.tearDown();
filter.clearMask();
filter.clearPatterns();
filter = null;
}
public void testSetInvalidPatterns() {
......@@ -154,7 +164,87 @@ public class ContentFilterTest extends TestCase {
message.setBody("At noon the fat cats ate lunch at Rizzos");
matched = filter.filter(message);
assertTrue(matched);
System.out.println(message.getBody());
assertEquals("** noon the fat cats ate lunch ** Rizzos", message.getBody());
}
public void testFilterChatMessage() throws DocumentException, IOException, XmlPullParserException {
String chatXML =
"<message to=\"doe@127.0.0.1/Adium\" type=\"chat\" id=\"iChat_E8B5ED64\" from=\"bob@127.0.0.1/frodo\">" +
"<body>fox</body>" +
"<html xmlns=\"http://jabber.org/protocol/xhtml-im\">" +
"<body xmlns=\"http://www.w3.org/1999/xhtml\" style=\"background-color:#E8A630;color:#000000\">fox</body>" +
"</html>" +
"<x xmlns=\"jabber:x:event\">" +
"<composing/>" +
"</x>" +
"</message>";
XPPPacketReader packetReader = new XPPPacketReader();
Document doc = packetReader.read(new StringReader(chatXML));
Message m = new Message(doc.getRootElement());
// filter on the word "fox" and "dog"
filter.setPatterns("fox,dog,message");
filter.setMask("**");
String expectedXML = chatXML.replaceAll("fox", filter.getMask());
// do filter
boolean matched = filter.filter(m);
assertTrue(matched);
assertEquals(expectedXML, expectedXML, m.toXML());
}
public void testFilterAvailablePresence() throws Exception {
// setup available presence
Presence presence = new Presence();
presence.setStatus("fox is now online!");
System.out.println(presence.toXML());
// filter on the word "fox" and "dog"
filter.setPatterns("fox,dog");
filter.setMask("**");
boolean matched = filter.filter(presence);
// matches should not be found
assertTrue(matched);
// content has changed
assertEquals("** is now online!", presence.getStatus());
}
public void testFilterPresenceXML() throws Exception {
String presenceXML =
"<presence from=\"bob@127.0.0.1/frodo\">" +
"<show>away</show>" +
"<status>fox</status>" +
"<priority>0</priority>" +
"<x xmlns=\"vcard-temp:x:update\">" +
"<photo>f9a514f112c0bcb988d5aa12bc1a9a6f22de5262</photo>" +
"</x>" +
"<c xmlns=\"http://jabber.org/protocol/caps\" node=\"apple:ichat:caps\" ver=\"392\" ext=\"avavail maudio mvideo avcap audio\"/>" +
"<x xmlns=\"http://jabber.org/protocol/tune\"/>" +
"</presence>";
XPPPacketReader packetReader = new XPPPacketReader();
Document doc = packetReader.read(new StringReader(presenceXML));
Presence p = new Presence(doc.getRootElement());
// filter on the word "fox" and "dog"
filter.setPatterns("fox,dog,message");
filter.setMask("**");
String expectedXML = presenceXML.replaceAll("fox", filter.getMask());
// do filter
boolean matched = filter.filter(p);
assertTrue(matched);
assertEquals(expectedXML, expectedXML, p.toXML());
}
}
\ No newline at end of file
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