Comparison

spec/util_rfc6724_spec.lua @ 8236:4878e4159e12

Port tests to the `busted` test runner
author Waqas Hussain <waqas20@gmail.com>
date Fri, 15 Sep 2017 17:07:57 -0400
comparison
equal deleted inserted replaced
8235:7d9a2c200736 8236:4878e4159e12
1
2 local rfc6724 = require "util.rfc6724";
3 local new_ip = require"util.ip".new_ip;
4
5 describe("util.rfc6724", function()
6 describe("#source()", function()
7 it("should work", function()
8 assert.are.equal(rfc6724.source(new_ip("2001:db8:1::1", "IPv6"),
9 {new_ip("2001:db8:3::1", "IPv6"), new_ip("fe80::1", "IPv6")}).addr,
10 "2001:db8:3::1",
11 "prefer appropriate scope");
12 assert.are.equal(rfc6724.source(new_ip("ff05::1", "IPv6"),
13 {new_ip("2001:db8:3::1", "IPv6"), new_ip("fe80::1", "IPv6")}).addr,
14 "2001:db8:3::1",
15 "prefer appropriate scope");
16 assert.are.equal(rfc6724.source(new_ip("2001:db8:1::1", "IPv6"),
17 {new_ip("2001:db8:1::1", "IPv6"), new_ip("2001:db8:2::1", "IPv6")}).addr,
18 "2001:db8:1::1",
19 "prefer same address"); -- "2001:db8:1::1" should be marked "deprecated" here, we don't handle that right now
20 assert.are.equal(rfc6724.source(new_ip("fe80::1", "IPv6"),
21 {new_ip("fe80::2", "IPv6"), new_ip("2001:db8:1::1", "IPv6")}).addr,
22 "fe80::2",
23 "prefer appropriate scope"); -- "fe80::2" should be marked "deprecated" here, we don't handle that right now
24 assert.are.equal(rfc6724.source(new_ip("2001:db8:1::1", "IPv6"),
25 {new_ip("2001:db8:1::2", "IPv6"), new_ip("2001:db8:3::2", "IPv6")}).addr,
26 "2001:db8:1::2",
27 "longest matching prefix");
28 --[[ "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
29 assert.are.equal(rfc6724.source(new_ip("2001:db8:1::1", "IPv6"),
30 {new_ip("2001:db8:1::2", "IPv6"), new_ip("2001:db8:3::2", "IPv6")}).addr,
31 "2001:db8:3::2",
32 "prefer home address");
33 ]]
34 assert.are.equal(rfc6724.source(new_ip("2002:c633:6401::1", "IPv6"),
35 {new_ip("2002:c633:6401::d5e3:7953:13eb:22e8", "IPv6"), new_ip("2001:db8:1::2", "IPv6")}).addr,
36 "2002:c633:6401::d5e3:7953:13eb:22e8",
37 "prefer matching label"); -- "2002:c633:6401::d5e3:7953:13eb:22e8" should be marked "temporary" here, we don't handle that right now
38 assert.are.equal(rfc6724.source(new_ip("2001:db8:1::d5e3:0:0:1", "IPv6"),
39 {new_ip("2001:db8:1::2", "IPv6"), new_ip("2001:db8:1::d5e3:7953:13eb:22e8", "IPv6")}).addr,
40 "2001:db8:1::d5e3:7953:13eb:22e8",
41 "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
42 end);
43 end);
44 describe("#destination()", function()
45 it("should work", function()
46 local order;
47 order = rfc6724.destination({new_ip("2001:db8:1::1", "IPv6"), new_ip("198.51.100.121", "IPv4")},
48 {new_ip("2001:db8:1::2", "IPv6"), new_ip("fe80::1", "IPv6"), new_ip("169.254.13.78", "IPv4")})
49 assert.are.equal(order[1].addr, "2001:db8:1::1", "prefer matching scope");
50 assert.are.equal(order[2].addr, "198.51.100.121", "prefer matching scope");
51
52 order = rfc6724.destination({new_ip("2001:db8:1::1", "IPv6"), new_ip("198.51.100.121", "IPv4")},
53 {new_ip("fe80::1", "IPv6"), new_ip("198.51.100.117", "IPv4")})
54 assert.are.equal(order[1].addr, "198.51.100.121", "prefer matching scope");
55 assert.are.equal(order[2].addr, "2001:db8:1::1", "prefer matching scope");
56
57 order = rfc6724.destination({new_ip("2001:db8:1::1", "IPv6"), new_ip("10.1.2.3", "IPv4")},
58 {new_ip("2001:db8:1::2", "IPv6"), new_ip("fe80::1", "IPv6"), new_ip("10.1.2.4", "IPv4")})
59 assert.are.equal(order[1].addr, "2001:db8:1::1", "prefer higher precedence");
60 assert.are.equal(order[2].addr, "10.1.2.3", "prefer higher precedence");
61
62 order = rfc6724.destination({new_ip("2001:db8:1::1", "IPv6"), new_ip("fe80::1", "IPv6")},
63 {new_ip("2001:db8:1::2", "IPv6"), new_ip("fe80::2", "IPv6")})
64 assert.are.equal(order[1].addr, "fe80::1", "prefer smaller scope");
65 assert.are.equal(order[2].addr, "2001:db8:1::1", "prefer smaller scope");
66
67 --[[ "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
68 order = rfc6724.destination({new_ip("2001:db8:1::1", "IPv6"), new_ip("fe80::1", "IPv6")},
69 {new_ip("2001:db8:1::2", "IPv6"), new_ip("2001:db8:3::1", "IPv6"), new_ip("fe80::2", "IPv6")})
70 assert.are.equal(order[1].addr, "2001:db8:1::1", "prefer home address");
71 assert.are.equal(order[2].addr, "fe80::1", "prefer home address");
72 ]]
73
74 --[[ "fe80::2" should be marked "deprecated", we can't currently handle this and would fail the test
75 order = rfc6724.destination({new_ip("2001:db8:1::1", "IPv6"), new_ip("fe80::1", "IPv6")},
76 {new_ip("2001:db8:1::2", "IPv6"), new_ip("fe80::2", "IPv6")})
77 assert.are.equal(order[1].addr, "2001:db8:1::1", "avoid deprecated addresses");
78 assert.are.equal(order[2].addr, "fe80::1", "avoid deprecated addresses");
79 ]]
80
81 order = rfc6724.destination({new_ip("2001:db8:1::1", "IPv6"), new_ip("2001:db8:3ffe::1", "IPv6")},
82 {new_ip("2001:db8:1::2", "IPv6"), new_ip("2001:db8:3f44::2", "IPv6"), new_ip("fe80::2", "IPv6")})
83 assert.are.equal(order[1].addr, "2001:db8:1::1", "longest matching prefix");
84 assert.are.equal(order[2].addr, "2001:db8:3ffe::1", "longest matching prefix");
85
86 order = rfc6724.destination({new_ip("2002:c633:6401::1", "IPv6"), new_ip("2001:db8:1::1", "IPv6")},
87 {new_ip("2002:c633:6401::2", "IPv6"), new_ip("fe80::2", "IPv6")})
88 assert.are.equal(order[1].addr, "2002:c633:6401::1", "prefer matching label");
89 assert.are.equal(order[2].addr, "2001:db8:1::1", "prefer matching label");
90
91 order = rfc6724.destination({new_ip("2002:c633:6401::1", "IPv6"), new_ip("2001:db8:1::1", "IPv6")},
92 {new_ip("2002:c633:6401::2", "IPv6"), new_ip("2001:db8:1::2", "IPv6"), new_ip("fe80::2", "IPv6")})
93 assert.are.equal(order[1].addr, "2001:db8:1::1", "prefer higher precedence");
94 assert.are.equal(order[2].addr, "2002:c633:6401::1", "prefer higher precedence");
95 end);
96 end);
97 end);