Software /
code /
prosody
Comparison
tests/test_util_rfc6724.lua @ 5609:f12d1c03dd94
test_util_rfc6724: Update with new test vectors from RFC 6724
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Mon, 20 May 2013 00:28:02 +0200 |
parent | 5604:6df0ec991f2e |
comparison
equal
deleted
inserted
replaced
5608:0200945313c9 | 5609:f12d1c03dd94 |
---|---|
1 -- Prosody IM | 1 -- Prosody IM |
2 -- Copyright (C) 2011 Florian Zeitz | 2 -- Copyright (C) 2011-2013 Florian Zeitz |
3 -- | 3 -- |
4 -- This project is MIT/X11 licensed. Please see the | 4 -- This project is MIT/X11 licensed. Please see the |
5 -- COPYING file in the source package for more information. | 5 -- COPYING file in the source package for more information. |
6 -- | 6 -- |
7 | 7 |
8 function source(source) | 8 function source(source) |
9 local new_ip = require"util.ip".new_ip; | 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"); | 10 assert_equal(source(new_ip("2001:db8:1::1", "IPv6"), |
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"); | 11 {new_ip("2001:db8:3::1", "IPv6"), new_ip("fe80::1", "IPv6")}).addr, |
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"); | 12 "2001:db8:3::1", |
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"); | 13 "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"); | 14 assert_equal(source(new_ip("ff05::1", "IPv6"), |
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"); | 15 {new_ip("2001:db8:3::1", "IPv6"), new_ip("fe80::1", "IPv6")}).addr, |
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"); | 16 "2001:db8:3::1", |
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"); | 17 "prefer appropriate scope"); |
18 assert_equal(source(new_ip("2001:db8:1::1", "IPv6"), | |
19 {new_ip("2001:db8:1::1", "IPv6"), new_ip("2001:db8:2::1", "IPv6")}).addr, | |
20 "2001:db8:1::1", | |
21 "prefer same address"); -- "2001:db8:1::1" should be marked "deprecated" here, we don't handle that right now | |
22 assert_equal(source(new_ip("fe80::1", "IPv6"), | |
23 {new_ip("fe80::2", "IPv6"), new_ip("2001:db8:1::1", "IPv6")}).addr, | |
24 "fe80::2", | |
25 "prefer appropriate scope"); -- "fe80::2" should be marked "deprecated" here, we don't handle that right now | |
26 assert_equal(source(new_ip("2001:db8:1::1", "IPv6"), | |
27 {new_ip("2001:db8:1::2", "IPv6"), new_ip("2001:db8:3::2", "IPv6")}).addr, | |
28 "2001:db8:1::2", | |
29 "longest matching prefix"); | |
30 --[[ "2001:db8:1::2" should be a care-of address and "2001:db8:3::2" a home address, we can't handle this and would fail | |
31 assert_equal(source(new_ip("2001:db8:1::1", "IPv6"), | |
32 {new_ip("2001:db8:1::2", "IPv6"), new_ip("2001:db8:3::2", "IPv6")}).addr, | |
33 "2001:db8:3::2", | |
34 "prefer home address"); | |
35 ]] | |
36 assert_equal(source(new_ip("2002:c633:6401::1", "IPv6"), | |
37 {new_ip("2002:c633:6401::d5e3:7953:13eb:22e8", "IPv6"), new_ip("2001:db8:1::2", "IPv6")}).addr, | |
38 "2002:c633:6401::d5e3:7953:13eb:22e8", | |
39 "prefer matching label"); -- "2002:c633:6401::d5e3:7953:13eb:22e8" should be marked "temporary" here, we don't handle that right now | |
40 assert_equal(source(new_ip("2001:db8:1::d5e3:0:0:1", "IPv6"), | |
41 {new_ip("2001:db8:1::2", "IPv6"), new_ip("2001:db8:1::d5e3:7953:13eb:22e8", "IPv6")}).addr, | |
42 "2001:db8:1::d5e3:7953:13eb:22e8", | |
43 "prefer temporary address") -- "2001:db8:1::2" should be marked "public" and "2001:db8:1::d5e3:7953:13eb:22e8" should be marked "temporary" here, we don't handle that right now | |
18 end | 44 end |
19 | 45 |
20 function destination(dest) | 46 function destination(dest) |
21 local order; | 47 local order; |
22 local new_ip = require"util.ip".new_ip; | 48 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")}) | 49 order = dest({new_ip("2001:db8:1::1", "IPv6"), new_ip("198.51.100.121", "IPv4")}, |
24 assert_equal(order[1].addr, "2001::1", "prefer matching scope"); | 50 {new_ip("2001:db8:1::2", "IPv6"), new_ip("fe80::1", "IPv6"), new_ip("169.254.13.78", "IPv4")}) |
25 assert_equal(order[2].addr, "131.107.65.121", "prefer matching scope") | 51 assert_equal(order[1].addr, "2001:db8:1::1", "prefer matching scope"); |
52 assert_equal(order[2].addr, "198.51.100.121", "prefer matching scope"); | |
26 | 53 |
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")}) | 54 order = dest({new_ip("2001:db8:1::1", "IPv6"), new_ip("198.51.100.121", "IPv4")}, |
28 assert_equal(order[1].addr, "131.107.65.121", "prefer matching scope") | 55 {new_ip("fe80::1", "IPv6"), new_ip("198.51.100.117", "IPv4")}) |
29 assert_equal(order[2].addr, "2001::1", "prefer matching scope") | 56 assert_equal(order[1].addr, "198.51.100.121", "prefer matching scope"); |
57 assert_equal(order[2].addr, "2001:db8:1::1", "prefer matching scope"); | |
30 | 58 |
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")}) | 59 order = dest({new_ip("2001:db8:1::1", "IPv6"), new_ip("10.1.2.3", "IPv4")}, |
32 assert_equal(order[1].addr, "2001::1", "prefer higher precedence"); | 60 {new_ip("2001:db8:1::2", "IPv6"), new_ip("fe80::1", "IPv6"), new_ip("10.1.2.4", "IPv4")}) |
61 assert_equal(order[1].addr, "2001:db8:1::1", "prefer higher precedence"); | |
33 assert_equal(order[2].addr, "10.1.2.3", "prefer higher precedence"); | 62 assert_equal(order[2].addr, "10.1.2.3", "prefer higher precedence"); |
34 | 63 |
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")}) | 64 order = dest({new_ip("2001:db8:1::1", "IPv6"), new_ip("fe80::1", "IPv6")}, |
65 {new_ip("2001:db8:1::2", "IPv6"), new_ip("fe80::2", "IPv6")}) | |
36 assert_equal(order[1].addr, "fe80::1", "prefer smaller scope"); | 66 assert_equal(order[1].addr, "fe80::1", "prefer smaller scope"); |
37 assert_equal(order[2].addr, "fec0::1", "prefer smaller scope"); | 67 assert_equal(order[2].addr, "2001:db8:1::1", "prefer smaller scope"); |
38 assert_equal(order[3].addr, "2001::1", "prefer smaller scope"); | |
39 | 68 |
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")}) | 69 --[[ "2001:db8:1::2" and "fe80::2" should be marked "care-of address", while "2001:db8:3::1" should be marked "home address", we can't currently handle this and would fail the test |
41 assert_equal(order[1].addr, "2001::1", "longest matching prefix"); | 70 order = dest({new_ip("2001:db8:1::1", "IPv6"), new_ip("fe80::1", "IPv6")}, |
42 assert_equal(order[2].addr, "3ffe::1", "longest matching prefix"); | 71 {new_ip("2001:db8:1::2", "IPv6"), new_ip("2001:db8:3::1", "IPv6"), new_ip("fe80::2", "IPv6")}) |
72 assert_equal(order[1].addr, "2001:db8:1::1", "prefer home address"); | |
73 assert_equal(order[2].addr, "fe80::1", "prefer home address"); | |
74 ]] | |
43 | 75 |
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")}) | 76 --[[ "fe80::2" should be marked "deprecated", we can't currently handle this and would fail the test |
45 assert_equal(order[1].addr, "2002:836b:4179::1", "prefer matching label"); | 77 order = dest({new_ip("2001:db8:1::1", "IPv6"), new_ip("fe80::1", "IPv6")}, |
46 assert_equal(order[2].addr, "2001::1", "prefer matching label"); | 78 {new_ip("2001:db8:1::2", "IPv6"), new_ip("fe80::2", "IPv6")}) |
79 assert_equal(order[1].addr, "2001:db8:1::1", "avoid deprecated addresses"); | |
80 assert_equal(order[2].addr, "fe80::1", "avoid deprecated addresses"); | |
81 ]] | |
47 | 82 |
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")}) | 83 order = dest({new_ip("2001:db8:1::1", "IPv6"), new_ip("2001:db8:3ffe::1", "IPv6")}, |
49 assert_equal(order[1].addr, "2001::1", "prefer higher precedence"); | 84 {new_ip("2001:db8:1::2", "IPv6"), new_ip("2001:db8:3f44::2", "IPv6"), new_ip("fe80::2", "IPv6")}) |
50 assert_equal(order[2].addr, "2002:836b:4179::1", "prefer higher precedence"); | 85 assert_equal(order[1].addr, "2001:db8:1::1", "longest matching prefix"); |
86 assert_equal(order[2].addr, "2001:db8:3ffe::1", "longest matching prefix"); | |
87 | |
88 order = dest({new_ip("2002:c633:6401::1", "IPv6"), new_ip("2001:db8:1::1", "IPv6")}, | |
89 {new_ip("2002:c633:6401::2", "IPv6"), new_ip("fe80::2", "IPv6")}) | |
90 assert_equal(order[1].addr, "2002:c633:6401::1", "prefer matching label"); | |
91 assert_equal(order[2].addr, "2001:db8:1::1", "prefer matching label"); | |
92 | |
93 order = dest({new_ip("2002:c633:6401::1", "IPv6"), new_ip("2001:db8:1::1", "IPv6")}, | |
94 {new_ip("2002:c633:6401::2", "IPv6"), new_ip("2001:db8:1::2", "IPv6"), new_ip("fe80::2", "IPv6")}) | |
95 assert_equal(order[1].addr, "2001:db8:1::1", "prefer higher precedence"); | |
96 assert_equal(order[2].addr, "2002:c633:6401::1", "prefer higher precedence"); | |
51 end | 97 end |