Annotate

spec/util_ip_spec.lua @ 13652:a08065207ef0

net.server_epoll: Call :shutdown() on TLS sockets when supported Comment from Matthew: This fixes a potential issue where the Prosody process gets blocked on sockets waiting for them to close. Unlike non-TLS sockets, closing a TLS socket sends layer 7 data, and this can cause problems for sockets which are in the process of being cleaned up. This depends on LuaSec changes which are not yet upstream. From Martijn's original email: So first my analysis of luasec. in ssl.c the socket is put into blocking mode right before calling SSL_shutdown() inside meth_destroy(). My best guess to why this is is because meth_destroy is linked to the __close and __gc methods, which can't exactly be called multiple times and luasec does want to make sure that a tls session is shutdown as clean as possible. I can't say I disagree with this reasoning and don't want to change this behaviour. My solution to this without changing the current behaviour is to introduce a shutdown() method. I am aware that this overlaps in a conflicting way with tcp's shutdown method, but it stays close to the OpenSSL name. This method calls SSL_shutdown() in the current (non)blocking mode of the underlying socket and returns a boolean whether or not the shutdown is completed (matching SSL_shutdown()'s 0 or 1 return values), and returns the familiar ssl_ioerror() strings on error with a false for completion. This error can then be used to determine if we have wantread/wantwrite to finalize things. Once meth_shutdown() has been called once a shutdown flag will be set, which indicates to meth_destroy() that the SSL_shutdown() has been handled by the application and it shouldn't be needed to set the socket to blocking mode. I've left the SSL_shutdown() call in the LSEC_STATE_CONNECTED to prevent TOCTOU if the application reaches a timeout for the shutdown code, which might allow SSL_shutdown() to clean up anyway at the last possible moment. Another thing I've changed to luasec is the call to socket_setblocking() right before calling close(2) in socket_destroy() in usocket.c. According to the latest POSIX[0]: Note that the requirement for close() on a socket to block for up to the current linger interval is not conditional on the O_NONBLOCK setting. Which I read to mean that removing O_NONBLOCK on the socket before close doesn't impact the behaviour and only causes noise in system call tracers. I didn't touch the windows bits of this, since I don't do windows. For the prosody side of things I've made the TLS shutdown bits resemble interface:onwritable(), and put it under a combined guard of self._tls and self.conn.shutdown. The self._tls bit is there to prevent getting stuck on this condition, and self.conn.shutdown is there to prevent the code being called by instances where the patched luasec isn't deployed. The destroy() method can be called from various places and is read by me as the "we give up" error path. To accommodate for these unexpected entrypoints I've added a single call to self.conn:shutdown() to prevent the socket being put into blocking mode. I have no expectations that there is any other use here. Same as previous, the self.conn.shutdown check is there to make sure it's not called on unpatched luasec deployments and self._tls is there to make sure we don't call shutdown() on tcp sockets. I wouldn't recommend logging of the conn:shutdown() error inside close(), since a lot of clients simply close the connection before SSL_shutdown() is done.
author Martijn van Duren <martijn@openbsd.org>
date Thu, 06 Feb 2025 15:04:38 +0000 (5 months ago)
parent 13428:dc1ad5f3f597
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 ip = require "util.ip";
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
3
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
4 local new_ip = ip.new_ip;
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
5 local match = ip.match;
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
6 local parse_cidr = ip.parse_cidr;
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
7 local commonPrefixLength = ip.commonPrefixLength;
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
8
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
9 describe("util.ip", function()
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
10 describe("#match()", function()
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
11 it("should work", function()
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
12 local _ = new_ip;
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
13 local ip = _"10.20.30.40";
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
14 assert.are.equal(match(ip, _"10.0.0.0", 8), true);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
15 assert.are.equal(match(ip, _"10.0.0.0", 16), false);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
16 assert.are.equal(match(ip, _"10.0.0.0", 24), false);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
17 assert.are.equal(match(ip, _"10.0.0.0", 32), false);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
18
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
19 assert.are.equal(match(ip, _"10.20.0.0", 8), true);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
20 assert.are.equal(match(ip, _"10.20.0.0", 16), true);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
21 assert.are.equal(match(ip, _"10.20.0.0", 24), false);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
22 assert.are.equal(match(ip, _"10.20.0.0", 32), false);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
23
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
24 assert.are.equal(match(ip, _"0.0.0.0", 32), false);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
25 assert.are.equal(match(ip, _"0.0.0.0", 0), true);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
26 assert.are.equal(match(ip, _"0.0.0.0"), false);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
27
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
28 assert.are.equal(match(ip, _"10.0.0.0", 255), false, "excessive number of bits");
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
29 assert.are.equal(match(ip, _"10.0.0.0", -8), true, "negative number of bits");
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
30 assert.are.equal(match(ip, _"10.0.0.0", -32), true, "negative number of bits");
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
31 assert.are.equal(match(ip, _"10.0.0.0", 0), true, "zero bits");
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
32 assert.are.equal(match(ip, _"10.0.0.0"), false, "no specified number of bits (differing ip)");
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
33 assert.are.equal(match(ip, _"10.20.30.40"), true, "no specified number of bits (same ip)");
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
34
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
35 assert.are.equal(match(_"127.0.0.1", _"127.0.0.1"), true, "simple ip");
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
36
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
37 assert.are.equal(match(_"8.8.8.8", _"8.8.0.0", 16), true);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
38 assert.are.equal(match(_"8.8.4.4", _"8.8.0.0", 16), true);
13428
dc1ad5f3f597 util.ip: Add another test case for match() and commonPrefixLength()
Matthew Wild <mwild1@gmail.com>
parents: 12934
diff changeset
39
dc1ad5f3f597 util.ip: Add another test case for match() and commonPrefixLength()
Matthew Wild <mwild1@gmail.com>
parents: 12934
diff changeset
40 assert.are.equal(match(_"fe80::1", _"fec0::", 10), false);
8236
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
41 end);
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
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
44 describe("#parse_cidr()", 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 assert.are.equal(new_ip"0.0.0.0", new_ip"0.0.0.0")
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
47
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
48 local function assert_cidr(cidr, ip, bits)
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
49 local parsed_ip, parsed_bits = parse_cidr(cidr);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
50 assert.are.equal(new_ip(ip), parsed_ip, cidr.." parsed ip is "..ip);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
51 assert.are.equal(bits, parsed_bits, cidr.." parsed bits is "..tostring(bits));
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
52 end
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
53 assert_cidr("0.0.0.0", "0.0.0.0", nil);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
54 assert_cidr("127.0.0.1", "127.0.0.1", nil);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
55 assert_cidr("127.0.0.1/0", "127.0.0.1", 0);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
56 assert_cidr("127.0.0.1/8", "127.0.0.1", 8);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
57 assert_cidr("127.0.0.1/32", "127.0.0.1", 32);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
58 assert_cidr("127.0.0.1/256", "127.0.0.1", 256);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
59 assert_cidr("::/48", "::", 48);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
60 end);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
61 end);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
62
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
63 describe("#new_ip()", function()
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
64 it("should work", function()
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
65 local v4, v6 = "IPv4", "IPv6";
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
66 local function assert_proto(s, proto)
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
67 local ip = new_ip(s);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
68 if proto then
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
69 assert.are.equal(ip and ip.proto, proto, "protocol is correct for "..("%q"):format(s));
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
70 else
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
71 assert.are.equal(ip, nil, "address is invalid");
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
72 end
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
73 end
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
74 assert_proto("127.0.0.1", v4);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
75 assert_proto("::1", v6);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
76 assert_proto("", nil);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
77 assert_proto("abc", nil);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
78 assert_proto(" ", nil);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
79 end);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
80 end);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
81
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
82 describe("#commonPrefixLength()", function()
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
83 it("should work", function()
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
84 local function assert_cpl6(a, b, len, v4)
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
85 local ipa, ipb = new_ip(a), new_ip(b);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
86 if v4 then len = len+96; end
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
87 assert.are.equal(commonPrefixLength(ipa, ipb), len, "common prefix length of "..a.." and "..b.." is "..len);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
88 assert.are.equal(commonPrefixLength(ipb, ipa), len, "common prefix length of "..b.." and "..a.." is "..len);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
89 end
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
90 local function assert_cpl4(a, b, len)
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
91 return assert_cpl6(a, b, len, "IPv4");
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
92 end
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
93 assert_cpl4("0.0.0.0", "0.0.0.0", 32);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
94 assert_cpl4("255.255.255.255", "0.0.0.0", 0);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
95 assert_cpl4("255.255.255.255", "255.255.0.0", 16);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
96 assert_cpl4("255.255.255.255", "255.255.255.255", 32);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
97 assert_cpl4("255.255.255.255", "255.255.255.255", 32);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
98
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
99 assert_cpl6("::1", "::1", 128);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
100 assert_cpl6("abcd::1", "abcd::1", 128);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
101 assert_cpl6("abcd::abcd", "abcd::", 112);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
102 assert_cpl6("abcd::abcd", "abcd::abcd:abcd", 96);
13428
dc1ad5f3f597 util.ip: Add another test case for match() and commonPrefixLength()
Matthew Wild <mwild1@gmail.com>
parents: 12934
diff changeset
103
dc1ad5f3f597 util.ip: Add another test case for match() and commonPrefixLength()
Matthew Wild <mwild1@gmail.com>
parents: 12934
diff changeset
104 assert_cpl6("fe80::1", "fec0::", 9);
8236
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
105 end);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
106 end);
12934
c6dffebab2f8 util.ip: Tests for truncate()
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
107
c6dffebab2f8 util.ip: Tests for truncate()
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
108 describe("#truncate()", function ()
c6dffebab2f8 util.ip: Tests for truncate()
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
109 it("should work for IPv4", function ()
c6dffebab2f8 util.ip: Tests for truncate()
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
110 local ip1 = ip.new_ip("192.168.0.1");
c6dffebab2f8 util.ip: Tests for truncate()
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
111 local ip2 = ip.truncate(ip1, 16);
c6dffebab2f8 util.ip: Tests for truncate()
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
112 assert.truthy(ip.is_ip(ip2));
c6dffebab2f8 util.ip: Tests for truncate()
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
113 assert.equal("192.168.0.0", ip2.normal);
c6dffebab2f8 util.ip: Tests for truncate()
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
114 assert.equal("192.168.0.1", ip1.normal); -- original unmodified
c6dffebab2f8 util.ip: Tests for truncate()
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
115 end);
c6dffebab2f8 util.ip: Tests for truncate()
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
116
c6dffebab2f8 util.ip: Tests for truncate()
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
117 it("should work for IPv6", function ()
c6dffebab2f8 util.ip: Tests for truncate()
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
118 local ip1 = ip.new_ip("2001:db8::ff00:42:8329");
c6dffebab2f8 util.ip: Tests for truncate()
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
119 local ip2 = ip.truncate(ip1, 24);
c6dffebab2f8 util.ip: Tests for truncate()
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
120 assert.truthy(ip.is_ip(ip2));
c6dffebab2f8 util.ip: Tests for truncate()
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
121 assert.equal("2001:d00::", ip2.normal);
c6dffebab2f8 util.ip: Tests for truncate()
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
122 assert.equal("2001:db8::ff00:42:8329", ip1.normal); -- original unmodified
c6dffebab2f8 util.ip: Tests for truncate()
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
123 end);
c6dffebab2f8 util.ip: Tests for truncate()
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
124
c6dffebab2f8 util.ip: Tests for truncate()
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
125 it("accepts a string", function ()
c6dffebab2f8 util.ip: Tests for truncate()
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
126 assert.equal("127.0.0.0", ip.truncate("127.0.0.1", 8).normal);
c6dffebab2f8 util.ip: Tests for truncate()
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
127 end);
c6dffebab2f8 util.ip: Tests for truncate()
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
128 end);
8236
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
129 end);