Annotate

tests/test_util_rfc6724.lua @ 8220:a1b0fa38fca7

util.pubsub: Don't record publisher when superuser privileges are used (eg by modules)
author Kim Alvefur <zash@zash.se>
date Sat, 29 Jul 2017 13:09:57 +0200
parent 5609:f12d1c03dd94
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4420
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
1 -- Prosody IM
5609
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
2 -- Copyright (C) 2011-2013 Florian Zeitz
4420
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
3 --
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
4 -- This project is MIT/X11 licensed. Please see the
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
5 -- COPYING file in the source package for more information.
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
6 --
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
7
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
8 function source(source)
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
9 local new_ip = require"util.ip".new_ip;
5609
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
10 assert_equal(source(new_ip("2001:db8:1::1", "IPv6"),
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
11 {new_ip("2001:db8:3::1", "IPv6"), new_ip("fe80::1", "IPv6")}).addr,
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
12 "2001:db8:3::1",
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
13 "prefer appropriate scope");
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
14 assert_equal(source(new_ip("ff05::1", "IPv6"),
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
15 {new_ip("2001:db8:3::1", "IPv6"), new_ip("fe80::1", "IPv6")}).addr,
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
16 "2001:db8:3::1",
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
17 "prefer appropriate scope");
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
18 assert_equal(source(new_ip("2001:db8:1::1", "IPv6"),
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
19 {new_ip("2001:db8:1::1", "IPv6"), new_ip("2001:db8:2::1", "IPv6")}).addr,
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
20 "2001:db8:1::1",
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
21 "prefer same address"); -- "2001:db8:1::1" should be marked "deprecated" here, we don't handle that right now
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
22 assert_equal(source(new_ip("fe80::1", "IPv6"),
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
23 {new_ip("fe80::2", "IPv6"), new_ip("2001:db8:1::1", "IPv6")}).addr,
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
24 "fe80::2",
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
25 "prefer appropriate scope"); -- "fe80::2" should be marked "deprecated" here, we don't handle that right now
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
26 assert_equal(source(new_ip("2001:db8:1::1", "IPv6"),
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
27 {new_ip("2001:db8:1::2", "IPv6"), new_ip("2001:db8:3::2", "IPv6")}).addr,
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
28 "2001:db8:1::2",
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
29 "longest matching prefix");
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
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
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
31 assert_equal(source(new_ip("2001:db8:1::1", "IPv6"),
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
32 {new_ip("2001:db8:1::2", "IPv6"), new_ip("2001:db8:3::2", "IPv6")}).addr,
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
33 "2001:db8:3::2",
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
34 "prefer home address");
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
35 ]]
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
36 assert_equal(source(new_ip("2002:c633:6401::1", "IPv6"),
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
37 {new_ip("2002:c633:6401::d5e3:7953:13eb:22e8", "IPv6"), new_ip("2001:db8:1::2", "IPv6")}).addr,
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
38 "2002:c633:6401::d5e3:7953:13eb:22e8",
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
39 "prefer matching label"); -- "2002:c633:6401::d5e3:7953:13eb:22e8" should be marked "temporary" here, we don't handle that right now
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
40 assert_equal(source(new_ip("2001:db8:1::d5e3:0:0:1", "IPv6"),
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
41 {new_ip("2001:db8:1::2", "IPv6"), new_ip("2001:db8:1::d5e3:7953:13eb:22e8", "IPv6")}).addr,
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
42 "2001:db8:1::d5e3:7953:13eb:22e8",
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
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
4420
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
44 end
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
45
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
46 function destination(dest)
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
47 local order;
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
48 local new_ip = require"util.ip".new_ip;
5609
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
49 order = dest({new_ip("2001:db8:1::1", "IPv6"), new_ip("198.51.100.121", "IPv4")},
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
50 {new_ip("2001:db8:1::2", "IPv6"), new_ip("fe80::1", "IPv6"), new_ip("169.254.13.78", "IPv4")})
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
51 assert_equal(order[1].addr, "2001:db8:1::1", "prefer matching scope");
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
52 assert_equal(order[2].addr, "198.51.100.121", "prefer matching scope");
4420
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
53
5609
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
54 order = dest({new_ip("2001:db8:1::1", "IPv6"), new_ip("198.51.100.121", "IPv4")},
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
55 {new_ip("fe80::1", "IPv6"), new_ip("198.51.100.117", "IPv4")})
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
56 assert_equal(order[1].addr, "198.51.100.121", "prefer matching scope");
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
57 assert_equal(order[2].addr, "2001:db8:1::1", "prefer matching scope");
4420
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
58
5609
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
59 order = dest({new_ip("2001:db8:1::1", "IPv6"), new_ip("10.1.2.3", "IPv4")},
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
60 {new_ip("2001:db8:1::2", "IPv6"), new_ip("fe80::1", "IPv6"), new_ip("10.1.2.4", "IPv4")})
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
61 assert_equal(order[1].addr, "2001:db8:1::1", "prefer higher precedence");
4420
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
62 assert_equal(order[2].addr, "10.1.2.3", "prefer higher precedence");
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
63
5609
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
64 order = dest({new_ip("2001:db8:1::1", "IPv6"), new_ip("fe80::1", "IPv6")},
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
65 {new_ip("2001:db8:1::2", "IPv6"), new_ip("fe80::2", "IPv6")})
4420
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
66 assert_equal(order[1].addr, "fe80::1", "prefer smaller scope");
5609
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
67 assert_equal(order[2].addr, "2001:db8:1::1", "prefer smaller scope");
4420
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
68
5609
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
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
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
70 order = dest({new_ip("2001:db8:1::1", "IPv6"), new_ip("fe80::1", "IPv6")},
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
71 {new_ip("2001:db8:1::2", "IPv6"), new_ip("2001:db8:3::1", "IPv6"), new_ip("fe80::2", "IPv6")})
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
72 assert_equal(order[1].addr, "2001:db8:1::1", "prefer home address");
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
73 assert_equal(order[2].addr, "fe80::1", "prefer home address");
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
74 ]]
4420
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
75
5609
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
76 --[[ "fe80::2" should be marked "deprecated", we can't currently handle this and would fail the test
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
77 order = dest({new_ip("2001:db8:1::1", "IPv6"), new_ip("fe80::1", "IPv6")},
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
78 {new_ip("2001:db8:1::2", "IPv6"), new_ip("fe80::2", "IPv6")})
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
79 assert_equal(order[1].addr, "2001:db8:1::1", "avoid deprecated addresses");
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
80 assert_equal(order[2].addr, "fe80::1", "avoid deprecated addresses");
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
81 ]]
4420
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
82
5609
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
83 order = dest({new_ip("2001:db8:1::1", "IPv6"), new_ip("2001:db8:3ffe::1", "IPv6")},
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
84 {new_ip("2001:db8:1::2", "IPv6"), new_ip("2001:db8:3f44::2", "IPv6"), new_ip("fe80::2", "IPv6")})
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
85 assert_equal(order[1].addr, "2001:db8:1::1", "longest matching prefix");
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
86 assert_equal(order[2].addr, "2001:db8:3ffe::1", "longest matching prefix");
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
87
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
88 order = dest({new_ip("2002:c633:6401::1", "IPv6"), new_ip("2001:db8:1::1", "IPv6")},
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
89 {new_ip("2002:c633:6401::2", "IPv6"), new_ip("fe80::2", "IPv6")})
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
90 assert_equal(order[1].addr, "2002:c633:6401::1", "prefer matching label");
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
91 assert_equal(order[2].addr, "2001:db8:1::1", "prefer matching label");
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
92
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
93 order = dest({new_ip("2002:c633:6401::1", "IPv6"), new_ip("2001:db8:1::1", "IPv6")},
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
94 {new_ip("2002:c633:6401::2", "IPv6"), new_ip("2001:db8:1::2", "IPv6"), new_ip("fe80::2", "IPv6")})
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
95 assert_equal(order[1].addr, "2001:db8:1::1", "prefer higher precedence");
f12d1c03dd94 test_util_rfc6724: Update with new test vectors from RFC 6724
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
96 assert_equal(order[2].addr, "2002:c633:6401::1", "prefer higher precedence");
4420
4314eeeed394 util.rfc3484: New util implementing RFC3484 sorting
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
97 end