package no.dusken.aranea.web.control; import no.dusken.aranea.util.MailCleaner; import no.dusken.aranea.util.MailCleanerImpl; import no.dusken.common.model.Mail; import org.junit.Before; import org.junit.Test; import org.owasp.validator.html.PolicyException; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; /** @author Benjamin Bjørnseth <benjamin@underdusken.no> */ public class MailCleanerTest { private MailCleaner cleaner; @Before public void onSetup() throws PolicyException { cleaner = new MailCleanerImpl("antisamy-myspace-1.3.xml"); } @Test public void testMailCleaner() throws Exception { Mail mail = new Mail(); mail.setBody("<script>alert(\"Warning!\")</script>"); mail.setFromAddress("<html>Hei!</html>"); mail.setFromName("<h1>Tjoho</h1>"); mail.setToAddress("function()"); mail.setSubject("Test"); cleaner.cleanMail(mail); assertTrue("mailBody should not contain script",!mail.getBody().contains(("<script>"))); assertTrue("mailFromAddress should not contain <html>", !mail.getFromAddress().contains("<html>Hei!</html>")); assertTrue("mailFromName should contain <h1>", mail.getFromName().contains("<h1>Tjoho</h1>")); assertTrue("mailToAdress should contain function", mail.getToAddress().equals("function()")); assertFalse("mailSubject should not be empty", mail.getSubject().equals("")); } }