Rapid spam filtering system https://rspamd.com/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.5 KiB

  1. -- inet addr tests
  2. context("Inet addr check functions", function()
  3. local ffi = require("ffi")
  4. ffi.cdef[[
  5. typedef struct rspamd_inet_addr_s rspamd_inet_addr_t;
  6. bool rspamd_parse_inet_address (rspamd_inet_addr_t **target,
  7. const char *src, size_t len);
  8. void rspamd_inet_address_free (rspamd_inet_addr_t *addr);
  9. ]]
  10. local cases = {
  11. {'192.168.1.1', true},
  12. {'2a01:4f8:190:43b5::99', true},
  13. {'256.1.1.1', false},
  14. {'/tmp/socket', true},
  15. {'./socket', true},
  16. {'[fe80::f919:8b26:ff93:3092%5]', true},
  17. {'[fe80::f919:8b26:ff93:3092]', true},
  18. {'IPv6:::1', true},
  19. {'IPv6:[::1]', true},
  20. {'IPv6[:::1]', false},
  21. {'[::]', true},
  22. {'[1::]', true},
  23. {'[000:01:02:003:004:5:6:007]', true}, -- leading zeros
  24. {'[A:b:c:DE:fF:0:1:aC]', true}, -- mixed case
  25. {'[::192.168.0.1]', true}, -- embedded ipv4
  26. {'[1:2:192.168.0.1:5:6]', false}, -- poor octets
  27. {'[::ffff:192.1.2]', false}, -- ipv4 without last octet (maybe should be true?)
  28. {'[0:0::0:0:8]', true}, -- bogus zeros
  29. {'[::192.168.0.0.1]', false}, -- invalid mapping
  30. }
  31. for i,c in ipairs(cases) do
  32. test("Create inet addr from string " .. c[1] .. '; expect ' .. tostring(c[2]), function()
  33. local ip = ffi.new("rspamd_inet_addr_t* [1]");
  34. local res = ffi.C.rspamd_parse_inet_address(ip, c[1], #c[1])
  35. assert_equal(res, c[2], "Expect " .. tostring(c[2]) .. " while parsing " .. c[1])
  36. if res then
  37. ffi.C.rspamd_inet_address_free(ip[0])
  38. end
  39. end)
  40. end
  41. end)