Software / code / prosody
Comparison
tests/test_util_ip.lua @ 5606:3dc141acf381
test_util_ip: Add tests for IP matching
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sat, 18 May 2013 17:44:01 +0100 |
| parent | 5604:6df0ec991f2e |
| child | 5607:eee23fb79a5e |
comparison
equal
deleted
inserted
replaced
| 5605:468d7a2f85ba | 5606:3dc141acf381 |
|---|---|
| 1 | 1 |
| 2 function test_match(match_ip) | 2 function match(match) |
| 3 assert(match_ip("10.20.30.40", "10.0.0.0/8")); | 3 local _ = require "util.ip".new_ip; |
| 4 assert(match_ip("80.244.94.84", "80.244.94.84")); | 4 local ip = _"10.20.30.40"; |
| 5 assert(match_ip("8.8.8.8", "8.8.0.0/16")); | 5 assert_equal(match(ip, _"10.0.0.0", 8), true); |
| 6 assert(match_ip("8.8.4.4", "8.8.0.0/16")); | 6 assert_equal(match(ip, _"10.0.0.0", 16), false); |
| 7 assert_equal(match(ip, _"10.0.0.0", 24), false); | |
| 8 assert_equal(match(ip, _"10.0.0.0", 32), false); | |
| 9 | |
| 10 assert_equal(match(ip, _"10.20.0.0", 8), true); | |
| 11 assert_equal(match(ip, _"10.20.0.0", 16), true); | |
| 12 assert_equal(match(ip, _"10.20.0.0", 24), false); | |
| 13 assert_equal(match(ip, _"10.20.0.0", 32), false); | |
| 14 | |
| 15 assert_equal(match(ip, _"0.0.0.0", 32), false); | |
| 16 assert_equal(match(ip, _"0.0.0.0", 0), true); | |
| 17 assert_equal(match(ip, _"0.0.0.0"), false); | |
| 18 | |
| 19 assert_equal(match(ip, _"10.0.0.0", 255), false, "excessive number of bits"); | |
| 20 assert_equal(match(ip, _"10.0.0.0", -8), true, "negative number of bits"); | |
| 21 assert_equal(match(ip, _"10.0.0.0", -32), true, "negative number of bits"); | |
| 22 assert_equal(match(ip, _"10.0.0.0", 0), true, "zero bits"); | |
| 23 assert_equal(match(ip, _"10.0.0.0"), false, "no specified number of bits (differing ip)"); | |
| 24 assert_equal(match(ip, _"10.20.30.40"), true, "no specified number of bits (same ip)"); | |
| 25 | |
| 26 assert_equal(match(_"80.244.94.84", _"80.244.94.84"), true, "simple ip"); | |
| 27 | |
| 28 assert_equal(match(_"8.8.8.8", _"8.8.0.0", 16), true); | |
| 29 assert_equal(match(_"8.8.4.4", _"8.8.0.0", 16), true); | |
| 7 end | 30 end |