Software /
code /
prosody
Annotate
spec/util_rfc6724_spec.lua @ 11571:a8f0f87e115a
prosody: Close the state on exit (ie garbage-collect everything)
This ensures __gc is called on everything that may need it, such as
database connections.
It was reported in the chat by Happy that SQLite3 does not close its
state cleanly in WAL mode, leaving the WAL file behind. This is probably
rather a bug in mod_storage_sql, but forcing a final GC sweep should
also help with such things everywhere.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 18 May 2021 20:08:37 +0200 |
parent | 8236:4878e4159e12 |
rev | line source |
---|---|
8236
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
1 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
2 local rfc6724 = require "util.rfc6724"; |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
3 local new_ip = require"util.ip".new_ip; |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
4 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
5 describe("util.rfc6724", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
6 describe("#source()", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
7 it("should work", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
8 assert.are.equal(rfc6724.source(new_ip("2001:db8:1::1", "IPv6"), |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
9 {new_ip("2001:db8:3::1", "IPv6"), new_ip("fe80::1", "IPv6")}).addr, |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 "2001:db8:3::1", |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 "prefer appropriate scope"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 assert.are.equal(rfc6724.source(new_ip("ff05::1", "IPv6"), |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 {new_ip("2001:db8:3::1", "IPv6"), new_ip("fe80::1", "IPv6")}).addr, |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 "2001:db8:3::1", |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 "prefer appropriate scope"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
16 assert.are.equal(rfc6724.source(new_ip("2001:db8:1::1", "IPv6"), |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 {new_ip("2001:db8:1::1", "IPv6"), new_ip("2001:db8:2::1", "IPv6")}).addr, |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 "2001:db8:1::1", |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 "prefer same address"); -- "2001:db8:1::1" should be marked "deprecated" here, we don't handle that right now |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 assert.are.equal(rfc6724.source(new_ip("fe80::1", "IPv6"), |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 {new_ip("fe80::2", "IPv6"), new_ip("2001:db8:1::1", "IPv6")}).addr, |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 "fe80::2", |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 "prefer appropriate scope"); -- "fe80::2" should be marked "deprecated" here, we don't handle that right now |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
24 assert.are.equal(rfc6724.source(new_ip("2001:db8:1::1", "IPv6"), |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
25 {new_ip("2001:db8:1::2", "IPv6"), new_ip("2001:db8:3::2", "IPv6")}).addr, |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
26 "2001:db8:1::2", |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 "longest matching prefix"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
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 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 assert.are.equal(rfc6724.source(new_ip("2001:db8:1::1", "IPv6"), |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
30 {new_ip("2001:db8:1::2", "IPv6"), new_ip("2001:db8:3::2", "IPv6")}).addr, |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 "2001:db8:3::2", |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
32 "prefer home address"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
33 ]] |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
34 assert.are.equal(rfc6724.source(new_ip("2002:c633:6401::1", "IPv6"), |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
35 {new_ip("2002:c633:6401::d5e3:7953:13eb:22e8", "IPv6"), new_ip("2001:db8:1::2", "IPv6")}).addr, |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
36 "2002:c633:6401::d5e3:7953:13eb:22e8", |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 "prefer matching label"); -- "2002:c633:6401::d5e3:7953:13eb:22e8" should be marked "temporary" here, we don't handle that right now |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
38 assert.are.equal(rfc6724.source(new_ip("2001:db8:1::d5e3:0:0:1", "IPv6"), |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
39 {new_ip("2001:db8:1::2", "IPv6"), new_ip("2001:db8:1::d5e3:7953:13eb:22e8", "IPv6")}).addr, |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
40 "2001:db8:1::d5e3:7953:13eb:22e8", |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
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 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
42 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
43 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
44 describe("#destination()", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
45 it("should work", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
46 local order; |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
47 order = rfc6724.destination({new_ip("2001:db8:1::1", "IPv6"), new_ip("198.51.100.121", "IPv4")}, |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
48 {new_ip("2001:db8:1::2", "IPv6"), new_ip("fe80::1", "IPv6"), new_ip("169.254.13.78", "IPv4")}) |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
49 assert.are.equal(order[1].addr, "2001:db8:1::1", "prefer matching scope"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
50 assert.are.equal(order[2].addr, "198.51.100.121", "prefer matching scope"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
51 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
52 order = rfc6724.destination({new_ip("2001:db8:1::1", "IPv6"), new_ip("198.51.100.121", "IPv4")}, |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
53 {new_ip("fe80::1", "IPv6"), new_ip("198.51.100.117", "IPv4")}) |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
54 assert.are.equal(order[1].addr, "198.51.100.121", "prefer matching scope"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
55 assert.are.equal(order[2].addr, "2001:db8:1::1", "prefer matching scope"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
56 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
57 order = rfc6724.destination({new_ip("2001:db8:1::1", "IPv6"), new_ip("10.1.2.3", "IPv4")}, |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
58 {new_ip("2001:db8:1::2", "IPv6"), new_ip("fe80::1", "IPv6"), new_ip("10.1.2.4", "IPv4")}) |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
59 assert.are.equal(order[1].addr, "2001:db8:1::1", "prefer higher precedence"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
60 assert.are.equal(order[2].addr, "10.1.2.3", "prefer higher precedence"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
61 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
62 order = rfc6724.destination({new_ip("2001:db8:1::1", "IPv6"), new_ip("fe80::1", "IPv6")}, |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
63 {new_ip("2001:db8:1::2", "IPv6"), new_ip("fe80::2", "IPv6")}) |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
64 assert.are.equal(order[1].addr, "fe80::1", "prefer smaller scope"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
65 assert.are.equal(order[2].addr, "2001:db8:1::1", "prefer smaller scope"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
66 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
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 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
68 order = rfc6724.destination({new_ip("2001:db8:1::1", "IPv6"), new_ip("fe80::1", "IPv6")}, |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
69 {new_ip("2001:db8:1::2", "IPv6"), new_ip("2001:db8:3::1", "IPv6"), new_ip("fe80::2", "IPv6")}) |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
70 assert.are.equal(order[1].addr, "2001:db8:1::1", "prefer home address"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
71 assert.are.equal(order[2].addr, "fe80::1", "prefer home address"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
72 ]] |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
73 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
74 --[[ "fe80::2" should be marked "deprecated", we can't currently handle this and would fail the test |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
75 order = rfc6724.destination({new_ip("2001:db8:1::1", "IPv6"), new_ip("fe80::1", "IPv6")}, |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
76 {new_ip("2001:db8:1::2", "IPv6"), new_ip("fe80::2", "IPv6")}) |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
77 assert.are.equal(order[1].addr, "2001:db8:1::1", "avoid deprecated addresses"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
78 assert.are.equal(order[2].addr, "fe80::1", "avoid deprecated addresses"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
79 ]] |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
80 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
81 order = rfc6724.destination({new_ip("2001:db8:1::1", "IPv6"), new_ip("2001:db8:3ffe::1", "IPv6")}, |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
82 {new_ip("2001:db8:1::2", "IPv6"), new_ip("2001:db8:3f44::2", "IPv6"), new_ip("fe80::2", "IPv6")}) |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
83 assert.are.equal(order[1].addr, "2001:db8:1::1", "longest matching prefix"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
84 assert.are.equal(order[2].addr, "2001:db8:3ffe::1", "longest matching prefix"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
85 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
86 order = rfc6724.destination({new_ip("2002:c633:6401::1", "IPv6"), new_ip("2001:db8:1::1", "IPv6")}, |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
87 {new_ip("2002:c633:6401::2", "IPv6"), new_ip("fe80::2", "IPv6")}) |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
88 assert.are.equal(order[1].addr, "2002:c633:6401::1", "prefer matching label"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
89 assert.are.equal(order[2].addr, "2001:db8:1::1", "prefer matching label"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
90 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
91 order = rfc6724.destination({new_ip("2002:c633:6401::1", "IPv6"), new_ip("2001:db8:1::1", "IPv6")}, |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
92 {new_ip("2002:c633:6401::2", "IPv6"), new_ip("2001:db8:1::2", "IPv6"), new_ip("fe80::2", "IPv6")}) |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
93 assert.are.equal(order[1].addr, "2001:db8:1::1", "prefer higher precedence"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
94 assert.are.equal(order[2].addr, "2002:c633:6401::1", "prefer higher precedence"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
95 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
96 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
97 end); |