-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve: remove ip ratelimiting, set limits more tolerable
- Loading branch information
1 parent
1161e6f
commit bf65c51
Showing
4 changed files
with
37 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,45 +2,24 @@ | |
|
||
import org.junit.Test; | ||
|
||
import foundation.privacybydesign.email.ratelimit.RateLimit; | ||
import foundation.privacybydesign.email.ratelimit.MemoryRateLimit; | ||
|
||
import static junit.framework.TestCase.assertFalse; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.assertNotEquals; | ||
|
||
/** | ||
* Test whether the canonicalization algorithm for IP addresses works well. | ||
* Test whether the rate limiter works as expected. | ||
*/ | ||
public class RateLimitTest { | ||
@Test | ||
public void testIPv4Address() { | ||
assertEquals("1.2.3.4", | ||
RateLimit.getAddressPrefix("1.2.3.4")); | ||
} | ||
|
||
@Test | ||
public void testIPv6AddressLocal() { | ||
assertEquals("0:0:0:0:0:0:0:0", | ||
RateLimit.getAddressPrefix("0:0:0:0:0:0:0:1")); | ||
} | ||
public void testRateLimit() { | ||
|
||
@Test | ||
public void testIPv6AddressRegular() { | ||
assertEquals("2a00:123:4567:8900:0:0:0:0", | ||
RateLimit.getAddressPrefix("2a00:0123:4567:89ab:cdef:fedc:ba98:7654")); | ||
} | ||
var rateLimit = MemoryRateLimit.getInstance(); | ||
var email = "[email protected]"; | ||
|
||
@Test | ||
public void testIPv6Equals() { | ||
String addr1 = RateLimit.getAddressPrefix("2a00:0123:4567:89ab:cdef:fedc:ba98:7654"); | ||
String addr2 = RateLimit.getAddressPrefix("2a00:0123:4567:89ac:cdef:fedc:ba98:7654"); | ||
assertTrue("IPv6 addresses should match", addr1.equals(addr2)); | ||
} | ||
|
||
@Test | ||
public void testIPv6Unequals() { | ||
String addr1 = RateLimit.getAddressPrefix("2a00:0123:4567:89ab:cdef:fedc:ba98:7654"); | ||
String addr2 = RateLimit.getAddressPrefix("2a00:0123:4567:88ab:cdef:fedc:ba98:7654"); | ||
assertFalse("IPv6 addresses should not match", addr1.equals(addr2)); | ||
assertEquals("not rate limited", 0, rateLimit.rateLimited(email)); | ||
|
||
assertNotEquals("rate limited", 0, rateLimit.rateLimited(email)); | ||
} | ||
} |