|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| This report was generated with an evaluation server license. Purchase Clover or configure your license. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IpAddressListenerTest | Line # 46 | 77 | 0% | 13 | 0 | 100% |
1.0
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| (24) | |||
| Result | |||
|
0.14444445
|
net.sourceforge.pebble.event.response.IpAddressListenerTest.testTrackBackIpAddressRemovedFromWhitelistWhenRejected
net.sourceforge.pebble.event.response.IpAddressListenerTest.testTrackBackIpAddressRemovedFromWhitelistWhenRejected
|
1 PASS | |
|
0.14444445
|
net.sourceforge.pebble.event.response.IpAddressListenerTest.testCommentIpAddressRemovedFromWhitelistWhenRejected
net.sourceforge.pebble.event.response.IpAddressListenerTest.testCommentIpAddressRemovedFromWhitelistWhenRejected
|
1 PASS | |
|
0.14444445
|
net.sourceforge.pebble.event.response.IpAddressListenerTest.testTrackBackIpAddressRemovedFromWhitelistWhenRejected
net.sourceforge.pebble.event.response.IpAddressListenerTest.testTrackBackIpAddressRemovedFromWhitelistWhenRejected
|
1 PASS | |
|
0.14444445
|
net.sourceforge.pebble.event.response.IpAddressListenerTest.testCommentIpAddressRemovedFromWhitelistWhenRejected
net.sourceforge.pebble.event.response.IpAddressListenerTest.testCommentIpAddressRemovedFromWhitelistWhenRejected
|
1 PASS | |
|
0.06666667
|
net.sourceforge.pebble.event.response.IpAddressListenerTest.testCommentIpAddressOnBlacklist
net.sourceforge.pebble.event.response.IpAddressListenerTest.testCommentIpAddressOnBlacklist
|
1 PASS | |
|
0.06666667
|
net.sourceforge.pebble.event.response.IpAddressListenerTest.testTrackBackIpAddressOnBlacklist
net.sourceforge.pebble.event.response.IpAddressListenerTest.testTrackBackIpAddressOnBlacklist
|
1 PASS | |
|
0.06666667
|
net.sourceforge.pebble.event.response.IpAddressListenerTest.testCommentIpAddressNotOnWhitelistOrBlacklist
net.sourceforge.pebble.event.response.IpAddressListenerTest.testCommentIpAddressNotOnWhitelistOrBlacklist
|
1 PASS | |
|
0.06666667
|
net.sourceforge.pebble.event.response.IpAddressListenerTest.testCommentIpAddressOnWhitelist
net.sourceforge.pebble.event.response.IpAddressListenerTest.testCommentIpAddressOnWhitelist
|
1 PASS | |
|
0.06666667
|
net.sourceforge.pebble.event.response.IpAddressListenerTest.testTrackBackIpAddressOnWhitelist
net.sourceforge.pebble.event.response.IpAddressListenerTest.testTrackBackIpAddressOnWhitelist
|
1 PASS | |
|
0.06666667
|
net.sourceforge.pebble.event.response.IpAddressListenerTest.testTrackBackIpAddressNotOnWhitelistOrBlacklist
net.sourceforge.pebble.event.response.IpAddressListenerTest.testTrackBackIpAddressNotOnWhitelistOrBlacklist
|
1 PASS | |
|
0.06666667
|
net.sourceforge.pebble.event.response.IpAddressListenerTest.testCommentIpAddressNotOnWhitelistOrBlacklist
net.sourceforge.pebble.event.response.IpAddressListenerTest.testCommentIpAddressNotOnWhitelistOrBlacklist
|
1 PASS | |
|
0.06666667
|
net.sourceforge.pebble.event.response.IpAddressListenerTest.testTrackBackIpAddressOnBlacklist
net.sourceforge.pebble.event.response.IpAddressListenerTest.testTrackBackIpAddressOnBlacklist
|
1 PASS | |
|
0.06666667
|
net.sourceforge.pebble.event.response.IpAddressListenerTest.testCommentIpAddressOnBlacklist
net.sourceforge.pebble.event.response.IpAddressListenerTest.testCommentIpAddressOnBlacklist
|
1 PASS | |
|
0.06666667
|
net.sourceforge.pebble.event.response.IpAddressListenerTest.testTrackBackIpAddressNotOnWhitelistOrBlacklist
net.sourceforge.pebble.event.response.IpAddressListenerTest.testTrackBackIpAddressNotOnWhitelistOrBlacklist
|
1 PASS | |
|
0.06666667
|
net.sourceforge.pebble.event.response.IpAddressListenerTest.testCommentIpAddressOnWhitelist
net.sourceforge.pebble.event.response.IpAddressListenerTest.testCommentIpAddressOnWhitelist
|
1 PASS | |
|
0.06666667
|
net.sourceforge.pebble.event.response.IpAddressListenerTest.testTrackBackIpAddressOnWhitelist
net.sourceforge.pebble.event.response.IpAddressListenerTest.testTrackBackIpAddressOnWhitelist
|
1 PASS | |
|
0.055555556
|
net.sourceforge.pebble.event.response.IpAddressListenerTest.testTrackBackIpAddressAddedToWhitelistWhenApproved
net.sourceforge.pebble.event.response.IpAddressListenerTest.testTrackBackIpAddressAddedToWhitelistWhenApproved
|
1 PASS | |
|
0.055555556
|
net.sourceforge.pebble.event.response.IpAddressListenerTest.testCommentIpAddressAddedToWhitelistWhenApproved
net.sourceforge.pebble.event.response.IpAddressListenerTest.testCommentIpAddressAddedToWhitelistWhenApproved
|
1 PASS | |
|
0.055555556
|
net.sourceforge.pebble.event.response.IpAddressListenerTest.testTrackBackIpAddressAddedToWhitelistWhenApproved
net.sourceforge.pebble.event.response.IpAddressListenerTest.testTrackBackIpAddressAddedToWhitelistWhenApproved
|
1 PASS | |
|
0.055555556
|
net.sourceforge.pebble.event.response.IpAddressListenerTest.testTrackBackIpAddressAddedToBlacklistWhenRejected
net.sourceforge.pebble.event.response.IpAddressListenerTest.testTrackBackIpAddressAddedToBlacklistWhenRejected
|
1 PASS | |
|
0.055555556
|
net.sourceforge.pebble.event.response.IpAddressListenerTest.testTrackBackIpAddressAddedToBlacklistWhenRejected
net.sourceforge.pebble.event.response.IpAddressListenerTest.testTrackBackIpAddressAddedToBlacklistWhenRejected
|
1 PASS | |
|
0.055555556
|
net.sourceforge.pebble.event.response.IpAddressListenerTest.testCommentIpAddressAddedToBlacklistWhenRejected
net.sourceforge.pebble.event.response.IpAddressListenerTest.testCommentIpAddressAddedToBlacklistWhenRejected
|
1 PASS | |
|
0.055555556
|
net.sourceforge.pebble.event.response.IpAddressListenerTest.testCommentIpAddressAddedToBlacklistWhenRejected
net.sourceforge.pebble.event.response.IpAddressListenerTest.testCommentIpAddressAddedToBlacklistWhenRejected
|
1 PASS | |
|
0.055555556
|
net.sourceforge.pebble.event.response.IpAddressListenerTest.testCommentIpAddressAddedToWhitelistWhenApproved
net.sourceforge.pebble.event.response.IpAddressListenerTest.testCommentIpAddressAddedToWhitelistWhenApproved
|
1 PASS | |
| 1 | /* | |
| 2 | * Copyright (c) 2003-2006, Simon Brown | |
| 3 | * All rights reserved. | |
| 4 | * | |
| 5 | * Redistribution and use in source and binary forms, with or without | |
| 6 | * modification, are permitted provided that the following conditions are met: | |
| 7 | * | |
| 8 | * - Redistributions of source code must retain the above copyright | |
| 9 | * notice, this list of conditions and the following disclaimer. | |
| 10 | * | |
| 11 | * - Redistributions in binary form must reproduce the above copyright | |
| 12 | * notice, this list of conditions and the following disclaimer in | |
| 13 | * the documentation and/or other materials provided with the | |
| 14 | * distribution. | |
| 15 | * | |
| 16 | * - Neither the name of Pebble nor the names of its contributors may | |
| 17 | * be used to endorse or promote products derived from this software | |
| 18 | * without specific prior written permission. | |
| 19 | * | |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
| 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
| 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 30 | * POSSIBILITY OF SUCH DAMAGE. | |
| 31 | */ | |
| 32 | package net.sourceforge.pebble.event.response; | |
| 33 | ||
| 34 | import net.sourceforge.pebble.domain.Comment; | |
| 35 | import net.sourceforge.pebble.domain.SingleBlogTestCase; | |
| 36 | import net.sourceforge.pebble.domain.TrackBack; | |
| 37 | import net.sourceforge.pebble.domain.BlogEntry; | |
| 38 | import net.sourceforge.pebble.api.event.comment.CommentEvent; | |
| 39 | import net.sourceforge.pebble.api.event.trackback.TrackBackEvent; | |
| 40 | ||
| 41 | /** | |
| 42 | * Tests for the IpAddressListener class. | |
| 43 | * | |
| 44 | * @author Simon Brown | |
| 45 | */ | |
| 46 | public class IpAddressListenerTest extends SingleBlogTestCase { | |
| 47 | ||
| 48 | private IpAddressListener listener; | |
| 49 | private Comment comment; | |
| 50 | private CommentEvent commentEvent; | |
| 51 | private TrackBack trackBack; | |
| 52 | private TrackBackEvent trackBackEvent; | |
| 53 | ||
| 54 | /** | |
| 55 | * Common setup code. | |
| 56 | */ | |
| 57 | 24 |
protected void setUp() throws Exception { |
| 58 | 24 | super.setUp(); |
| 59 | ||
| 60 | 24 | listener = new IpAddressListener(); |
| 61 | 24 | BlogEntry blogEntry = new BlogEntry(blog); |
| 62 | 24 | comment = blogEntry.createComment("Title", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1"); |
| 63 | 24 | commentEvent = new CommentEvent(comment, CommentEvent.COMMENT_ADDED); |
| 64 | 24 | trackBack = blogEntry.createTrackBack("Title", "Excerpt", "url", "blogName", "127.0.0.1"); |
| 65 | 24 | trackBackEvent = new TrackBackEvent(trackBack, TrackBackEvent.TRACKBACK_ADDED); |
| 66 | } | |
| 67 | ||
| 68 | /** | |
| 69 | * Tests a comment from an IP address that isn't on the whitelist | |
| 70 | * or blacklist. | |
| 71 | */ | |
| 72 | 2 |
public void testCommentIpAddressNotOnWhitelistOrBlacklist() { |
| 73 | 2 | blog.getPluginProperties().setProperty(IpAddressListener.WHITELIST_KEY, ""); |
| 74 | 2 | blog.getPluginProperties().setProperty(IpAddressListener.BLACKLIST_KEY, ""); |
| 75 | ||
| 76 | 2 | listener.commentAdded(commentEvent); |
| 77 | 2 | assertTrue(comment.isPending()); |
| 78 | 2 | assertEquals(0, comment.getSpamScore()); |
| 79 | } | |
| 80 | ||
| 81 | /** | |
| 82 | * Tests a comment from an IP address that is on the blacklist. | |
| 83 | */ | |
| 84 | 2 |
public void testCommentIpAddressOnBlacklist() { |
| 85 | 2 | blog.getPluginProperties().setProperty(IpAddressListener.WHITELIST_KEY, ""); |
| 86 | 2 | blog.getPluginProperties().setProperty(IpAddressListener.BLACKLIST_KEY, "127.0.0.1"); |
| 87 | ||
| 88 | 2 | listener.commentAdded(commentEvent); |
| 89 | 2 | assertTrue(comment.isPending()); |
| 90 | 2 | assertEquals(1, comment.getSpamScore()); |
| 91 | } | |
| 92 | ||
| 93 | /** | |
| 94 | * Tests a comment from an IP address that is on the whitelist. | |
| 95 | */ | |
| 96 | 2 |
public void testCommentIpAddressOnWhitelist() { |
| 97 | 2 | blog.getPluginProperties().setProperty(IpAddressListener.WHITELIST_KEY, "127.0.0.1"); |
| 98 | 2 | blog.getPluginProperties().setProperty(IpAddressListener.BLACKLIST_KEY, ""); |
| 99 | ||
| 100 | 2 | listener.commentAdded(commentEvent); |
| 101 | 2 | assertTrue(comment.isApproved()); |
| 102 | 2 | assertEquals(0, comment.getSpamScore()); |
| 103 | } | |
| 104 | ||
| 105 | /** | |
| 106 | * Tests a TrackBack from an IP address that isn't on the whitelist | |
| 107 | * or blacklist. | |
| 108 | */ | |
| 109 | 2 |
public void testTrackBackIpAddressNotOnWhitelistOrBlacklist() { |
| 110 | 2 | blog.getPluginProperties().setProperty(IpAddressListener.WHITELIST_KEY, ""); |
| 111 | 2 | blog.getPluginProperties().setProperty(IpAddressListener.BLACKLIST_KEY, ""); |
| 112 | ||
| 113 | 2 | listener.trackBackAdded(trackBackEvent); |
| 114 | 2 | assertTrue(trackBack.isPending()); |
| 115 | 2 | assertEquals(0, trackBack.getSpamScore()); |
| 116 | } | |
| 117 | ||
| 118 | /** | |
| 119 | * Tests a TrackBack from an IP address that is on the whitelist. | |
| 120 | */ | |
| 121 | 2 |
public void testTrackBackIpAddressOnWhitelist() { |
| 122 | 2 | blog.getPluginProperties().setProperty(IpAddressListener.WHITELIST_KEY, "127.0.0.1"); |
| 123 | 2 | blog.getPluginProperties().setProperty(IpAddressListener.BLACKLIST_KEY, ""); |
| 124 | ||
| 125 | 2 | listener.trackBackAdded(trackBackEvent); |
| 126 | 2 | assertTrue(trackBack.isApproved()); |
| 127 | 2 | assertEquals(0, trackBack.getSpamScore()); |
| 128 | } | |
| 129 | ||
| 130 | /** | |
| 131 | * Tests a TrackBack from an IP address that is on the blacklist. | |
| 132 | */ | |
| 133 | 2 |
public void testTrackBackIpAddressOnBlacklist() { |
| 134 | 2 | blog.getPluginProperties().setProperty(IpAddressListener.WHITELIST_KEY, ""); |
| 135 | 2 | blog.getPluginProperties().setProperty(IpAddressListener.BLACKLIST_KEY, "127.0.0.1"); |
| 136 | ||
| 137 | 2 | listener.trackBackAdded(trackBackEvent); |
| 138 | 2 | assertTrue(trackBack.isPending()); |
| 139 | 2 | assertEquals(1, trackBack.getSpamScore()); |
| 140 | } | |
| 141 | ||
| 142 | /** | |
| 143 | * Tests that, when a comment is marked as approved, its IP address is added | |
| 144 | * to the whitelist. | |
| 145 | */ | |
| 146 | 2 |
public void testCommentIpAddressAddedToWhitelistWhenApproved() { |
| 147 | 2 | blog.getPluginProperties().setProperty(IpAddressListener.WHITELIST_KEY, ""); |
| 148 | ||
| 149 | 2 | assertEquals("", blog.getPluginProperties().getProperty(IpAddressListener.WHITELIST_KEY)); |
| 150 | 2 | listener.blogEntryResponseApproved(comment); |
| 151 | 2 | assertEquals("127.0.0.1", blog.getPluginProperties().getProperty(IpAddressListener.WHITELIST_KEY)); |
| 152 | } | |
| 153 | ||
| 154 | /** | |
| 155 | * Tests that, when a comment is marked as rejected, its IP address is added | |
| 156 | * to the blacklist. | |
| 157 | */ | |
| 158 | 2 |
public void testCommentIpAddressAddedToBlacklistWhenRejected() { |
| 159 | 2 | blog.getPluginProperties().setProperty(IpAddressListener.BLACKLIST_KEY, ""); |
| 160 | ||
| 161 | 2 | assertEquals("", blog.getPluginProperties().getProperty(IpAddressListener.BLACKLIST_KEY)); |
| 162 | 2 | listener.blogEntryResponseRejected(comment); |
| 163 | 2 | assertEquals("127.0.0.1", blog.getPluginProperties().getProperty(IpAddressListener.BLACKLIST_KEY)); |
| 164 | } | |
| 165 | ||
| 166 | /** | |
| 167 | * Tests that, when a comment is marked as rejected, its IP address is removed | |
| 168 | * from the whitelist. | |
| 169 | */ | |
| 170 | 2 |
public void testCommentIpAddressRemovedFromWhitelistWhenRejected() { |
| 171 | 2 | blog.getPluginProperties().setProperty(IpAddressListener.WHITELIST_KEY, "192.168.0.1,127.0.0.1,192.168.0.2"); |
| 172 | 2 | listener.blogEntryResponseRejected(comment); |
| 173 | 2 | assertEquals("192.168.0.1,192.168.0.2", blog.getPluginProperties().getProperty(IpAddressListener.WHITELIST_KEY)); |
| 174 | ||
| 175 | 2 | blog.getPluginProperties().setProperty(IpAddressListener.WHITELIST_KEY, "127.0.0.1,192.168.0.1"); |
| 176 | 2 | listener.blogEntryResponseRejected(comment); |
| 177 | 2 | assertEquals("192.168.0.1", blog.getPluginProperties().getProperty(IpAddressListener.WHITELIST_KEY)); |
| 178 | ||
| 179 | 2 | blog.getPluginProperties().setProperty(IpAddressListener.WHITELIST_KEY, "192.168.0.1,127.0.0.1"); |
| 180 | 2 | listener.blogEntryResponseRejected(comment); |
| 181 | 2 | assertEquals("192.168.0.1", blog.getPluginProperties().getProperty(IpAddressListener.WHITELIST_KEY)); |
| 182 | ||
| 183 | 2 | blog.getPluginProperties().setProperty(IpAddressListener.WHITELIST_KEY, "127.0.0.1"); |
| 184 | 2 | listener.blogEntryResponseRejected(comment); |
| 185 | 2 | assertEquals("", blog.getPluginProperties().getProperty(IpAddressListener.WHITELIST_KEY)); |
| 186 | } | |
| 187 | ||
| 188 | /** | |
| 189 | * Tests that, when a TrackBack is marked as approved, its IP address is added | |
| 190 | * to the whitelist. | |
| 191 | */ | |
| 192 | 2 |
public void testTrackBackIpAddressAddedToWhitelistWhenApproved() { |
| 193 | 2 | blog.getPluginProperties().setProperty(IpAddressListener.WHITELIST_KEY, ""); |
| 194 | ||
| 195 | 2 | assertEquals("", blog.getPluginProperties().getProperty(IpAddressListener.WHITELIST_KEY)); |
| 196 | 2 | listener.blogEntryResponseApproved(trackBack); |
| 197 | 2 | assertEquals("127.0.0.1", blog.getPluginProperties().getProperty(IpAddressListener.WHITELIST_KEY)); |
| 198 | } | |
| 199 | ||
| 200 | /** | |
| 201 | * Tests that, when a TrackBack is marked as rejected, its IP address is added | |
| 202 | * to the blacklist. | |
| 203 | */ | |
| 204 | 2 |
public void testTrackBackIpAddressAddedToBlacklistWhenRejected() { |
| 205 | 2 | blog.getPluginProperties().setProperty(IpAddressListener.BLACKLIST_KEY, ""); |
| 206 | ||
| 207 | 2 | assertEquals("", blog.getPluginProperties().getProperty(IpAddressListener.BLACKLIST_KEY)); |
| 208 | 2 | listener.blogEntryResponseRejected(trackBack); |
| 209 | 2 | assertEquals("127.0.0.1", blog.getPluginProperties().getProperty(IpAddressListener.BLACKLIST_KEY)); |
| 210 | } | |
| 211 | ||
| 212 | ||
| 213 | /** | |
| 214 | * Tests that, when a TrackBack is marked as rejected, its IP address is removed | |
| 215 | * from the whitelist. | |
| 216 | */ | |
| 217 | 2 |
public void testTrackBackIpAddressRemovedFromWhitelistWhenRejected() { |
| 218 | 2 | blog.getPluginProperties().setProperty(IpAddressListener.WHITELIST_KEY, "192.168.0.1,127.0.0.1,192.168.0.2"); |
| 219 | 2 | listener.blogEntryResponseRejected(trackBack); |
| 220 | 2 | assertEquals("192.168.0.1,192.168.0.2", blog.getPluginProperties().getProperty(IpAddressListener.WHITELIST_KEY)); |
| 221 | ||
| 222 | 2 | blog.getPluginProperties().setProperty(IpAddressListener.WHITELIST_KEY, "127.0.0.1,192.168.0.1"); |
| 223 | 2 | listener.blogEntryResponseRejected(trackBack); |
| 224 | 2 | assertEquals("192.168.0.1", blog.getPluginProperties().getProperty(IpAddressListener.WHITELIST_KEY)); |
| 225 | ||
| 226 | 2 | blog.getPluginProperties().setProperty(IpAddressListener.WHITELIST_KEY, "192.168.0.1,127.0.0.1"); |
| 227 | 2 | listener.blogEntryResponseRejected(trackBack); |
| 228 | 2 | assertEquals("192.168.0.1", blog.getPluginProperties().getProperty(IpAddressListener.WHITELIST_KEY)); |
| 229 | ||
| 230 | 2 | blog.getPluginProperties().setProperty(IpAddressListener.WHITELIST_KEY, "127.0.0.1"); |
| 231 | 2 | listener.blogEntryResponseRejected(trackBack); |
| 232 | 2 | assertEquals("", blog.getPluginProperties().getProperty(IpAddressListener.WHITELIST_KEY)); |
| 233 | } | |
| 234 | ||
| 235 | } | |
|
||||||||||||