Comparison

tests/test_util_rfc6724.lua @ 5604:6df0ec991f2e

tests: Some much-needed cleanup...
author Matthew Wild <mwild1@gmail.com>
date Sat, 18 May 2013 17:14:30 +0100
parent 4420:tests/test_util_rfc3484.lua@4314eeeed394
child 5609:f12d1c03dd94
comparison
equal deleted inserted replaced
5603:e07f4f02e4f9 5604:6df0ec991f2e
1 -- Prosody IM
2 -- Copyright (C) 2011 Florian Zeitz
3 --
4 -- This project is MIT/X11 licensed. Please see the
5 -- COPYING file in the source package for more information.
6 --
7
8 function source(source)
9 local new_ip = require"util.ip".new_ip;
10 assert_equal(source(new_ip("2001::1", "IPv6"), {new_ip("3ffe::1", "IPv6"), new_ip("fe80::1", "IPv6")}).addr, "3ffe::1", "prefer appropriate scope");
11 assert_equal(source(new_ip("2001::1", "IPv6"), {new_ip("fe80::1", "IPv6"), new_ip("fec0::1", "IPv6")}).addr, "fec0::1", "prefer appropriate scope");
12 assert_equal(source(new_ip("fec0::1", "IPv6"), {new_ip("fe80::1", "IPv6"), new_ip("2001::1", "IPv6")}).addr, "2001::1", "prefer appropriate scope");
13 assert_equal(source(new_ip("ff05::1", "IPv6"), {new_ip("fe80::1", "IPv6"), new_ip("fec0::1", "IPv6"), new_ip("2001::1", "IPv6")}).addr, "fec0::1", "prefer appropriate scope");
14 assert_equal(source(new_ip("2001::1", "IPv6"), {new_ip("2001::1", "IPv6"), new_ip("2002::1", "IPv6")}).addr, "2001::1", "prefer same address");
15 assert_equal(source(new_ip("fec0::1", "IPv6"), {new_ip("fec0::2", "IPv6"), new_ip("2001::1", "IPv6")}).addr, "fec0::2", "prefer appropriate scope");
16 assert_equal(source(new_ip("2001::1", "IPv6"), {new_ip("2001::2", "IPv6"), new_ip("3ffe::2", "IPv6")}).addr, "2001::2", "longest matching prefix");
17 assert_equal(source(new_ip("2002:836b:2179::1", "IPv6"), {new_ip("2002:836b:2179::d5e3:7953:13eb:22e8", "IPv6"), new_ip("2001::2", "IPv6")}).addr, "2002:836b:2179::d5e3:7953:13eb:22e8", "prefer matching label");
18 end
19
20 function destination(dest)
21 local order;
22 local new_ip = require"util.ip".new_ip;
23 order = dest({new_ip("2001::1", "IPv6"), new_ip("131.107.65.121", "IPv4")}, {new_ip("2001::2", "IPv6"), new_ip("fe80::1", "IPv6"), new_ip("169.254.13.78", "IPv4")})
24 assert_equal(order[1].addr, "2001::1", "prefer matching scope");
25 assert_equal(order[2].addr, "131.107.65.121", "prefer matching scope")
26
27 order = dest({new_ip("2001::1", "IPv6"), new_ip("131.107.65.121", "IPv4")}, {new_ip("fe80::1", "IPv6"), new_ip("131.107.65.117", "IPv4")})
28 assert_equal(order[1].addr, "131.107.65.121", "prefer matching scope")
29 assert_equal(order[2].addr, "2001::1", "prefer matching scope")
30
31 order = dest({new_ip("2001::1", "IPv6"), new_ip("10.1.2.3", "IPv4")}, {new_ip("2001::2", "IPv6"), new_ip("fe80::1", "IPv6"), new_ip("10.1.2.4", "IPv4")})
32 assert_equal(order[1].addr, "2001::1", "prefer higher precedence");
33 assert_equal(order[2].addr, "10.1.2.3", "prefer higher precedence");
34
35 order = dest({new_ip("2001::1", "IPv6"), new_ip("fec0::1", "IPv6"), new_ip("fe80::1", "IPv6")}, {new_ip("2001::2", "IPv6"), new_ip("fec0::1", "IPv6"), new_ip("fe80::2", "IPv6")})
36 assert_equal(order[1].addr, "fe80::1", "prefer smaller scope");
37 assert_equal(order[2].addr, "fec0::1", "prefer smaller scope");
38 assert_equal(order[3].addr, "2001::1", "prefer smaller scope");
39
40 order = dest({new_ip("2001::1", "IPv6"), new_ip("3ffe::1", "IPv6")}, {new_ip("2001::2", "IPv6"), new_ip("3f44::2", "IPv6"), new_ip("fe80::2", "IPv6")})
41 assert_equal(order[1].addr, "2001::1", "longest matching prefix");
42 assert_equal(order[2].addr, "3ffe::1", "longest matching prefix");
43
44 order = dest({new_ip("2002:836b:4179::1", "IPv6"), new_ip("2001::1", "IPv6")}, {new_ip("2002:836b:4179::2", "IPv6"), new_ip("fe80::2", "IPv6")})
45 assert_equal(order[1].addr, "2002:836b:4179::1", "prefer matching label");
46 assert_equal(order[2].addr, "2001::1", "prefer matching label");
47
48 order = dest({new_ip("2002:836b:4179::1", "IPv6"), new_ip("2001::1", "IPv6")}, {new_ip("2002:836b:4179::2", "IPv6"), new_ip("2001::2", "IPv6"), new_ip("fe80::2", "IPv6")})
49 assert_equal(order[1].addr, "2001::1", "prefer higher precedence");
50 assert_equal(order[2].addr, "2002:836b:4179::1", "prefer higher precedence");
51 end