From d007771f8da390816640fa3839b29dcbaa5862d2 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 28 Nov 2018 20:36:53 +0100 Subject: util.format: Tweak how nil values are handled Because [] seems exsessive --- spec/util_format_spec.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'spec') diff --git a/spec/util_format_spec.lua b/spec/util_format_spec.lua index 7e6a0c6e..8a2e9312 100644 --- a/spec/util_format_spec.lua +++ b/spec/util_format_spec.lua @@ -5,6 +5,8 @@ describe("util.format", function() it("should work", function() assert.equal("hello", format("%s", "hello")); assert.equal("", format("%s")); + assert.equal("", format("%d")); + assert.equal("", format("%q")); assert.equal(" []", format("", nil)); assert.equal("true", format("%s", true)); assert.equal("[true]", format("%d", true)); -- cgit v1.2.3 From e999fee5c39278f767f7f508a2c0c964ec964cd1 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 30 Nov 2018 23:58:55 +0100 Subject: tests: Add scansion test for #689 about keeping the full subscription request stanza --- spec/scansion/keep_full_sub_req.scs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 spec/scansion/keep_full_sub_req.scs (limited to 'spec') diff --git a/spec/scansion/keep_full_sub_req.scs b/spec/scansion/keep_full_sub_req.scs new file mode 100644 index 00000000..318bbb60 --- /dev/null +++ b/spec/scansion/keep_full_sub_req.scs @@ -0,0 +1,37 @@ +# server MUST keep a record of the complete presence stanza comprising the subscription request (#689) + +[Client] Alice + jid: pars-a@localhost + password: password + +[Client] Bob + jid: pars-b@localhost + password: password + +--------- + +Alice connects + +Alice sends: + + + + +Alice disconnects + +Bob connects + +Bob sends: + + +Bob receives: + + + +Bob receives: + + + + +Bob disconnects + -- cgit v1.2.3 From 296555762ed5a515998d4b85d6d7fd4d9bfb62e5 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 1 Dec 2018 18:02:58 +0100 Subject: spec/keep_full_sub_req: Add missing type attribute --- spec/scansion/keep_full_sub_req.scs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/scansion/keep_full_sub_req.scs b/spec/scansion/keep_full_sub_req.scs index 318bbb60..3b80b8b2 100644 --- a/spec/scansion/keep_full_sub_req.scs +++ b/spec/scansion/keep_full_sub_req.scs @@ -29,7 +29,7 @@ Bob receives: Bob receives: - + -- cgit v1.2.3 From 8aac387431c7dad47c6afffc4bfcc024d3147950 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 1 Dec 2018 18:07:56 +0100 Subject: spec/keep_full_sub_req: Verify that the presence subscription stays the same after a reconnect --- spec/scansion/keep_full_sub_req.scs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'spec') diff --git a/spec/scansion/keep_full_sub_req.scs b/spec/scansion/keep_full_sub_req.scs index 3b80b8b2..5a5e1fdf 100644 --- a/spec/scansion/keep_full_sub_req.scs +++ b/spec/scansion/keep_full_sub_req.scs @@ -27,6 +27,23 @@ Bob sends: Bob receives: +Bob receives: + + + + +Bob disconnects + +# Works if they reconnect too + +Bob connects + +Bob sends: + + +Bob receives: + + Bob receives: -- cgit v1.2.3 From c295aedbfeeab6ebacb9b5bece085b8a532a7e9d Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 1 Dec 2018 18:12:01 +0100 Subject: spec/keep_full_sub_req: Make the second connect a differenct device (workaround for scansion issue) scansion threw an error when a client connected again --- spec/scansion/keep_full_sub_req.scs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'spec') diff --git a/spec/scansion/keep_full_sub_req.scs b/spec/scansion/keep_full_sub_req.scs index 5a5e1fdf..244c1d55 100644 --- a/spec/scansion/keep_full_sub_req.scs +++ b/spec/scansion/keep_full_sub_req.scs @@ -8,6 +8,10 @@ jid: pars-b@localhost password: password +[Client] Bob's phone + jid: pars-b@localhost/phone + password: password + --------- Alice connects @@ -36,19 +40,19 @@ Bob disconnects # Works if they reconnect too -Bob connects +Bob's phone connects -Bob sends: +Bob's phone sends: -Bob receives: - +Bob's phone receives: + -Bob receives: +Bob's phone receives: -Bob disconnects +Bob's phone disconnects -- cgit v1.2.3 From c28be4a630e1e6872438a5822de098295b55b925 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 6 Dec 2018 17:54:50 +0100 Subject: MUC: Add test case for #667 --- spec/scansion/muc_subject_issue_667.scs | 79 +++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 spec/scansion/muc_subject_issue_667.scs (limited to 'spec') diff --git a/spec/scansion/muc_subject_issue_667.scs b/spec/scansion/muc_subject_issue_667.scs new file mode 100644 index 00000000..68f4c17a --- /dev/null +++ b/spec/scansion/muc_subject_issue_667.scs @@ -0,0 +1,79 @@ +# #667 MUC message with subject and body SHALL NOT be interpreted as a subject change + +[Client] Romeo + password: password + jid: romeo@localhost + +----- + +Romeo connects + +# and creates a room +Romeo sends: + + + + +Romeo receives: + + + + + + + + +Romeo receives: + + + + +Romeo sends: + + Greetings + Hello everyone + + +Romeo receives: + + Greetings + Hello everyone + + +Romeo sends: + + Something to talk about + + +Romeo receives: + + Something to talk about + + +Romeo sends: + + + + +Romeo receives: + + + + + + + +# These have delay tags but we ignore those for now +Romeo receives: + + Greetings + Hello everyone + + +Romeo receives: + + Something to talk about + + +Romeo disconnects + -- cgit v1.2.3 From 2b289f34f929a69424a22bb0de3b668a58ba80cd Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 8 Dec 2018 17:09:55 +0100 Subject: various: Don't rely on _G.unpack existing --- spec/core_storagemanager_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/core_storagemanager_spec.lua b/spec/core_storagemanager_spec.lua index a0a8b5ef..fd2f8742 100644 --- a/spec/core_storagemanager_spec.lua +++ b/spec/core_storagemanager_spec.lua @@ -1,4 +1,4 @@ -local unpack = table.unpack or unpack; +local unpack = table.unpack or unpack; -- luacheck: ignore 113 local server = require "net.server_select"; package.loaded["net.server"] = server; -- cgit v1.2.3 From 177420df39c60de47eb47bc5ed574e2ccf082ec4 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 12 Oct 2018 01:29:34 +0200 Subject: util.format: Serialize values for the %q format Improves eg debug logs --- spec/util_format_spec.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'spec') diff --git a/spec/util_format_spec.lua b/spec/util_format_spec.lua index 8a2e9312..b9652d19 100644 --- a/spec/util_format_spec.lua +++ b/spec/util_format_spec.lua @@ -11,6 +11,7 @@ describe("util.format", function() assert.equal("true", format("%s", true)); assert.equal("[true]", format("%d", true)); assert.equal("% [true]", format("%%", true)); + assert.equal("{ }", format("%q", { })); end); end); end); -- cgit v1.2.3 From b1c3c4bc382df869fab3783a1ba35261e81420a6 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 11 Dec 2018 23:24:14 +0100 Subject: spec/scansion/prosody.cfg.lua: Update a comment from prosody.cfg.lua.dist for easier comparisons --- spec/scansion/prosody.cfg.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/scansion/prosody.cfg.lua b/spec/scansion/prosody.cfg.lua index 94861449..170371e1 100644 --- a/spec/scansion/prosody.cfg.lua +++ b/spec/scansion/prosody.cfg.lua @@ -14,7 +14,7 @@ modules_enabled = { -- Not essential, but recommended "carbons"; -- Keep multiple clients in sync - "pep"; -- Enables users to publish their mood, activity, playing music and more + "pep"; -- Enables users to publish their avatar, mood, activity, playing music and more "private"; -- Private XML storage (for room bookmarks, etc.) "blocklist"; -- Allow users to block communications with other users "vcard"; -- Allow users to set vCards -- cgit v1.2.3 From 35c3393bca3c7ce6f64ef22f0c2bfa133e4367e1 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 11 Dec 2018 23:25:16 +0100 Subject: spec/scansion/prosody.cfg.lua: Replace mod_vcard with mod_vcard4 and mod_vcard_legacy as in default config --- spec/scansion/prosody.cfg.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/scansion/prosody.cfg.lua b/spec/scansion/prosody.cfg.lua index 170371e1..e8872bff 100644 --- a/spec/scansion/prosody.cfg.lua +++ b/spec/scansion/prosody.cfg.lua @@ -17,7 +17,8 @@ modules_enabled = { "pep"; -- Enables users to publish their avatar, mood, activity, playing music and more "private"; -- Private XML storage (for room bookmarks, etc.) "blocklist"; -- Allow users to block communications with other users - "vcard"; -- Allow users to set vCards + "vcard4"; -- User profiles (stored in PEP) + "vcard_legacy"; -- Conversion between legacy vCard and PEP Avatar, vcard -- Nice to have "version"; -- Replies to server version requests -- cgit v1.2.3 From a270e6d5c8798dfad2fcd624f7ebb34ec72238a2 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 11 Dec 2018 23:26:16 +0100 Subject: spec/scansion/prosody.cfg.lua: Add remaining modules listened in prosody.cfg.lua.dist for easier comparisons --- spec/scansion/prosody.cfg.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'spec') diff --git a/spec/scansion/prosody.cfg.lua b/spec/scansion/prosody.cfg.lua index e8872bff..8d6e7c0a 100644 --- a/spec/scansion/prosody.cfg.lua +++ b/spec/scansion/prosody.cfg.lua @@ -27,6 +27,11 @@ modules_enabled = { "ping"; -- Replies to XMPP pings with pongs "register"; -- Allow users to register on this server using a client and change passwords --"mam"; -- Store messages in an archive and allow users to access it + --"csi_simple"; -- Simple Mobile optimizations + + -- Admin interfaces + --"admin_adhoc"; -- Allows administration via an XMPP client that supports ad-hoc commands + --"admin_telnet"; -- Opens telnet console interface on localhost port 5582 -- HTTP modules --"bosh"; -- Enable BOSH clients, aka "Jabber over HTTP" -- cgit v1.2.3 From 09d88cefa5738c1ec7a60c50c73685c2378335d4 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 16 Dec 2018 22:49:58 +0100 Subject: MUC: Add another message to #667 test --- spec/scansion/muc_subject_issue_667.scs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'spec') diff --git a/spec/scansion/muc_subject_issue_667.scs b/spec/scansion/muc_subject_issue_667.scs index 68f4c17a..859a0bfd 100644 --- a/spec/scansion/muc_subject_issue_667.scs +++ b/spec/scansion/muc_subject_issue_667.scs @@ -50,6 +50,16 @@ Romeo receives: Something to talk about +Romeo sends: + + Lorem ipsum dolor sit amet + + +Romeo receives: + + Lorem ipsum dolor sit amet + + Romeo sends: @@ -70,6 +80,11 @@ Romeo receives: Hello everyone +Romeo receives: + + Lorem ipsum dolor sit amet + + Romeo receives: Something to talk about -- cgit v1.2.3 From 826c511cac78d521e6f336a658f50d66cb10d78a Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 16 Dec 2018 22:53:56 +0100 Subject: MUC: Add descriptive comments to #667 test --- spec/scansion/muc_subject_issue_667.scs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'spec') diff --git a/spec/scansion/muc_subject_issue_667.scs b/spec/scansion/muc_subject_issue_667.scs index 859a0bfd..417f957a 100644 --- a/spec/scansion/muc_subject_issue_667.scs +++ b/spec/scansion/muc_subject_issue_667.scs @@ -23,11 +23,13 @@ Romeo receives: +# the default (empty) subject Romeo receives: +# this should be treated as a normal message Romeo sends: Greetings @@ -40,6 +42,7 @@ Romeo receives: Hello everyone +# this is a subject change Romeo sends: Something to talk about @@ -50,6 +53,7 @@ Romeo receives: Something to talk about +# a message without Romeo sends: Lorem ipsum dolor sit amet @@ -60,11 +64,13 @@ Romeo receives: Lorem ipsum dolor sit amet +# Resync Romeo sends: +# Presences Romeo receives: @@ -73,6 +79,7 @@ Romeo receives: +# History # These have delay tags but we ignore those for now Romeo receives: @@ -85,6 +92,7 @@ Romeo receives: Lorem ipsum dolor sit amet +# Finally, the topic Romeo receives: Something to talk about -- cgit v1.2.3 From 24a020bbaa7d9d99d26330e2639f9249511f84cd Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 16 Dec 2018 22:59:14 +0100 Subject: MUC: Test that subject is still empty after sending a non-subject change message with a subject (#667) --- spec/scansion/muc_subject_issue_667.scs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'spec') diff --git a/spec/scansion/muc_subject_issue_667.scs b/spec/scansion/muc_subject_issue_667.scs index 417f957a..74980073 100644 --- a/spec/scansion/muc_subject_issue_667.scs +++ b/spec/scansion/muc_subject_issue_667.scs @@ -42,6 +42,33 @@ Romeo receives: Hello everyone +# Resync +Romeo sends: + + + + +# Presences +Romeo receives: + + + + + + + +Romeo receives: + + Greetings + Hello everyone + + +# the still empty subject +Romeo receives: + + + + # this is a subject change Romeo sends: -- cgit v1.2.3 From b90dce4c204a7fd58ec00361cd75546ea32d585b Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 23 Dec 2018 14:52:52 +0100 Subject: util.table: Add test for pack() --- spec/util_table_spec.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 spec/util_table_spec.lua (limited to 'spec') diff --git a/spec/util_table_spec.lua b/spec/util_table_spec.lua new file mode 100644 index 00000000..97266fe2 --- /dev/null +++ b/spec/util_table_spec.lua @@ -0,0 +1,10 @@ +local u_table = require "util.table"; +describe("util.table", function () + describe("pack()", function () + it("works", function () + assert.same({ "lorem", "ipsum", "dolor", "sit", "amet", n = 5 }, u_table.pack("lorem", "ipsum", "dolor", "sit", "amet")); + end); + end); +end); + + -- cgit v1.2.3 From 9ff2b47bcc4a5c1c026ecdba8fc3b6c818af183e Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 23 Dec 2018 15:01:37 +0100 Subject: util.table: Add test for create() --- spec/util_table_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'spec') diff --git a/spec/util_table_spec.lua b/spec/util_table_spec.lua index 97266fe2..76f54b69 100644 --- a/spec/util_table_spec.lua +++ b/spec/util_table_spec.lua @@ -1,5 +1,12 @@ local u_table = require "util.table"; describe("util.table", function () + describe("create()", function () + it("works", function () + -- Can't test the allocated sizes of the table, so what you gonna do? + assert.is.table(u_table.create(1,1)); + end); + end); + describe("pack()", function () it("works", function () assert.same({ "lorem", "ipsum", "dolor", "sit", "amet", n = 5 }, u_table.pack("lorem", "ipsum", "dolor", "sit", "amet")); -- cgit v1.2.3 From 20429527b1c455e2c6784d717c48d69e80b1138b Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 28 Dec 2018 20:49:01 +0100 Subject: util.stanza: Require a type attribute for iq stanzas --- spec/util_stanza_spec.lua | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'spec') diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua index 6fbae41a..18e39554 100644 --- a/spec/util_stanza_spec.lua +++ b/spec/util_stanza_spec.lua @@ -95,20 +95,31 @@ describe("util.stanza", function() describe("#iq()", function() it("should create an iq stanza", function() - local i = st.iq({ id = "foo" }); + local i = st.iq({ type = "get", id = "foo" }); assert.are.equal("iq", i.name); assert.are.equal("foo", i.attr.id); + assert.are.equal("get", i.attr.type); end); - it("should reject stanzas with no id", function () + it("should reject stanzas with no attributes", function () assert.has.error_match(function () st.iq(); - end, "id attribute"); + end, "attributes"); + end); + + it("should reject stanzas with no id", function () assert.has.error_match(function () - st.iq({ foo = "bar" }); + st.iq({ type = "get" }); end, "id attribute"); end); + + it("should reject stanzas with no type", function () + assert.has.error_match(function () + st.iq({ id = "foo" }); + end, "type attribute"); + + end); end); describe("#presence()", function () -- cgit v1.2.3 From 15d5dffa63b71c75bcba23046ac20e4a7f0e3a58 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 10 Mar 2018 19:58:41 +0100 Subject: spec: Stub tests for util.interpolation --- spec/util_interpolation_spec.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 spec/util_interpolation_spec.lua (limited to 'spec') diff --git a/spec/util_interpolation_spec.lua b/spec/util_interpolation_spec.lua new file mode 100644 index 00000000..88d9f844 --- /dev/null +++ b/spec/util_interpolation_spec.lua @@ -0,0 +1,17 @@ +local template = [[ +{greet!}, {name?world}! +]]; +local expect1 = [[ +Hello, WORLD! +]]; +local expect2 = [[ +Hello, world! +]]; + +describe("util.interpolation", function () + it("renders", function () + local render = require "util.interpolation".new("%b{}", string.upper); + assert.equal(expect1, render(template, { greet = "Hello", name = "world" })); + assert.equal(expect2, render(template, { greet = "Hello" })); + end); +end); -- cgit v1.2.3 From 3e30870220e8c617cda3a06b1c9d9054b346283c Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 16 Jan 2019 13:53:04 +0100 Subject: util.http: Fix decoding of uppercase URL encoded chars Broken in 1af5106a2c34 --- spec/util_http_spec.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'spec') diff --git a/spec/util_http_spec.lua b/spec/util_http_spec.lua index 0f51a86c..d38645f7 100644 --- a/spec/util_http_spec.lua +++ b/spec/util_http_spec.lua @@ -28,6 +28,11 @@ describe("util.http", function() it("should decode important URL characters", function() assert.are.equal("This & that = something", http.urldecode("This%20%26%20that%20%3d%20something"), "Important URL chars escaped"); end); + + it("should decode both lower and uppercase", function () + assert.are.equal("This & that = {something}.", http.urldecode("This%20%26%20that%20%3D%20%7Bsomething%7D%2E"), "Important URL chars escaped"); + end); + end); describe("#formencode()", function() -- cgit v1.2.3 From a274eacbbc62164a6567faeaa8d18ea5993a133f Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 23 Mar 2019 08:47:55 +0000 Subject: util.queue: Add 'consume()' convenience iterator --- spec/util_queue_spec.lua | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'spec') diff --git a/spec/util_queue_spec.lua b/spec/util_queue_spec.lua index 7cd3d695..d73f523d 100644 --- a/spec/util_queue_spec.lua +++ b/spec/util_queue_spec.lua @@ -100,4 +100,41 @@ describe("util.queue", function() end); end); + describe("consume()", function () + it("should work", function () + local q = queue.new(10); + for i = 1, 5 do + q:push(i); + end + local c = 0; + for i in q:consume() do + assert(i == c + 1); + assert(q:count() == (5-i)); + c = i; + end + end); + + it("should work even if items are pushed in the loop", function () + local q = queue.new(10); + for i = 1, 5 do + q:push(i); + end + local c = 0; + for i in q:consume() do + assert(i == c + 1); + if c < 3 then + assert(q:count() == (5-i)); + else + assert(q:count() == (6-i)); + end + + c = i; + + if c == 3 then + q:push(6); + end + end + assert.equal(c, 6); + end); + end); end); -- cgit v1.2.3 From e1b559853fb0f6e0967124a135e1d380d02316d9 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 25 Mar 2019 14:37:43 +0000 Subject: util.stanza: Fix :top_tag() handling of namespaced attributes --- spec/util_stanza_spec.lua | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'spec') diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua index 18e39554..38503ab7 100644 --- a/spec/util_stanza_spec.lua +++ b/spec/util_stanza_spec.lua @@ -381,4 +381,35 @@ describe("util.stanza", function() end); end); end); + + describe("top_tag", function () + local xml_parse = require "util.xml".parse; + it("works", function () + local s = st.message({type="chat"}, "Hello"); + local top_tag = s:top_tag(); + assert.is_string(top_tag); + assert.not_equal("/>", top_tag:sub(-2, -1)); + assert.equal(">", top_tag:sub(-1, -1)); + local s2 = xml_parse(top_tag..""); + assert(st.is_stanza(s2)); + assert.equal("message", s2.name); + assert.equal(0, #s2); + assert.equal(0, #s2.tags); + assert.equal("chat", s2.attr.type); + end); + + it("works with namespaced attributes", function () + local s = xml_parse[[]]; + local top_tag = s:top_tag(); + assert.is_string(top_tag); + assert.not_equal("/>", top_tag:sub(-2, -1)); + assert.equal(">", top_tag:sub(-1, -1)); + local s2 = xml_parse(top_tag..""); + assert(st.is_stanza(s2)); + assert.equal("message", s2.name); + assert.equal(0, #s2); + assert.equal(0, #s2.tags); + assert.equal("true", s2.attr["my-awesome-ns\1bar"]); + end); + end); end); -- cgit v1.2.3 From d00874434414a06801a3b8d0be756176d1eb778b Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 11 Apr 2019 00:41:48 +0200 Subject: util.hmac: Generate test cases from RFC 4231 --- spec/util_hmac_spec.lua | 103 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 spec/util_hmac_spec.lua (limited to 'spec') diff --git a/spec/util_hmac_spec.lua b/spec/util_hmac_spec.lua new file mode 100644 index 00000000..abcc92f1 --- /dev/null +++ b/spec/util_hmac_spec.lua @@ -0,0 +1,103 @@ +-- Test cases from RFC 4231 + +local hmac = require "util.hmac"; +local hex = require "util.hex"; + +describe("Test case 1", function () + local Key = hex.from("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"); + local Data = hex.from("4869205468657265"); + describe("HMAC-SHA-256", function () + it("works", function() + assert.equal("b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7", hmac.sha256(Key, Data, true)) + end); + end); + describe("HMAC-SHA-512", function () + it("works", function() + assert.equal("87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b30545e17cdedaa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f1702e696c203a126854", hmac.sha512(Key, Data, true)) + end); + end); +end); +describe("Test case 2", function () + local Key = hex.from("4a656665"); + local Data = hex.from("7768617420646f2079612077616e7420666f72206e6f7468696e673f"); + describe("HMAC-SHA-256", function () + it("works", function() + assert.equal("5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843", hmac.sha256(Key, Data, true)) + end); + end); + describe("HMAC-SHA-512", function () + it("works", function() + assert.equal("164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7ea2505549758bf75c05a994a6d034f65f8f0e6fdcaeab1a34d4a6b4b636e070a38bce737", hmac.sha512(Key, Data, true)) + end); + end); +end); +describe("Test case 3", function () + local Key = hex.from("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); + local Data = hex.from("dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"); + describe("HMAC-SHA-256", function () + it("works", function() + assert.equal("773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514ced565fe", hmac.sha256(Key, Data, true)) + end); + end); + describe("HMAC-SHA-512", function () + it("works", function() + assert.equal("fa73b0089d56a284efb0f0756c890be9b1b5dbdd8ee81a3655f83e33b2279d39bf3e848279a722c806b485a47e67c807b946a337bee8942674278859e13292fb", hmac.sha512(Key, Data, true)) + end); + end); +end); +describe("Test case 4", function () + local Key = hex.from("0102030405060708090a0b0c0d0e0f10111213141516171819"); + local Data = hex.from("cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"); + describe("HMAC-SHA-256", function () + it("works", function() + assert.equal("82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff46729665b", hmac.sha256(Key, Data, true)) + end); + end); + describe("HMAC-SHA-512", function () + it("works", function() + assert.equal("b0ba465637458c6990e5a8c5f61d4af7e576d97ff94b872de76f8050361ee3dba91ca5c11aa25eb4d679275cc5788063a5f19741120c4f2de2adebeb10a298dd", hmac.sha512(Key, Data, true)) + end); + end); +end); +describe("Test case 5", function () + local Key = hex.from("0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c"); + local Data = hex.from("546573742057697468205472756e636174696f6e"); + describe("HMAC-SHA-256", function () + it("works", function() + assert.equal("a3b6167473100ee06e0c796c2955552b", hmac.sha256(Key, Data, true):sub(1,128/4)) + end); + end); + describe("HMAC-SHA-512", function () + it("works", function() + assert.equal("415fad6271580a531d4179bc891d87a6", hmac.sha512(Key, Data, true):sub(1,128/4)) + end); + end); +end); +describe("Test case 6", function () + local Key = hex.from("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); + local Data = hex.from("54657374205573696e67204c6172676572205468616e20426c6f636b2d53697a65204b6579202d2048617368204b6579204669727374"); + describe("HMAC-SHA-256", function () + it("works", function() + assert.equal("60e431591ee0b67f0d8a26aacbf5b77f8e0bc6213728c5140546040f0ee37f54", hmac.sha256(Key, Data, true)) + end); + end); + describe("HMAC-SHA-512", function () + it("works", function() + assert.equal("80b24263c7c1a3ebb71493c1dd7be8b49b46d1f41b4aeec1121b013783f8f3526b56d037e05f2598bd0fd2215d6a1e5295e64f73f63f0aec8b915a985d786598", hmac.sha512(Key, Data, true)) + end); + end); +end); +describe("Test case 7", function () + local Key = hex.from("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); + local Data = hex.from("5468697320697320612074657374207573696e672061206c6172676572207468616e20626c6f636b2d73697a65206b657920616e642061206c6172676572207468616e20626c6f636b2d73697a6520646174612e20546865206b6579206e6565647320746f20626520686173686564206265666f7265206265696e6720757365642062792074686520484d414320616c676f726974686d2e"); + describe("HMAC-SHA-256", function () + it("works", function() + assert.equal("9b09ffa71b942fcb27635fbcd5b0e944bfdc63644f0713938a7f51535c3a35e2", hmac.sha256(Key, Data, true)) + end); + end); + describe("HMAC-SHA-512", function () + it("works", function() + assert.equal("e37b6a775dc87dbaa4dfa9f96e5e3ffddebd71f8867289865df5a32d20cdc944b6022cac3c4982b10d5eeb55c3e4de15134676fb6de0446065c97440fa8c6a58", hmac.sha512(Key, Data, true)) + end); + end); +end); -- cgit v1.2.3 From 53f4351d9a70341bfa9083be3552b7f0d1f7ffbe Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 19 Apr 2019 13:17:49 +0200 Subject: util.hmac: Ignore long hex lines in tests --- spec/util_hmac_spec.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'spec') diff --git a/spec/util_hmac_spec.lua b/spec/util_hmac_spec.lua index abcc92f1..a2125c3a 100644 --- a/spec/util_hmac_spec.lua +++ b/spec/util_hmac_spec.lua @@ -1,5 +1,8 @@ -- Test cases from RFC 4231 +-- Yes, the lines are long, it's annoying to split the long hex things. +-- luacheck: ignore 631 + local hmac = require "util.hmac"; local hex = require "util.hex"; -- cgit v1.2.3 From 43bb3d5756a77f7d67a470ca1c69c979a2dba612 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 19 Apr 2019 14:12:28 +0200 Subject: util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi()) Number 4 is disabled by default beacuse of how long time it takes --- spec/util_hashes_spec.lua | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 spec/util_hashes_spec.lua (limited to 'spec') diff --git a/spec/util_hashes_spec.lua b/spec/util_hashes_spec.lua new file mode 100644 index 00000000..1e6187bb --- /dev/null +++ b/spec/util_hashes_spec.lua @@ -0,0 +1,37 @@ +-- Test vectors from RFC 6070 +local hashes = require "util.hashes"; +local hex = require "util.hex"; + +-- Also see spec for util.hmac where HMAC test cases reside + +describe("PBKDF2-SHA1", function () + it("test vector 1", function () + local P = "password" + local S = "salt" + local c = 1 + local DK = "0c60c80f961f0e71f3a9b524af6012062fe037a6"; + assert.equal(DK, hex.to(hashes.scram_Hi_sha1(P, S, c))); + end); + it("test vector 2", function () + local P = "password" + local S = "salt" + local c = 2 + local DK = "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957"; + assert.equal(DK, hex.to(hashes.scram_Hi_sha1(P, S, c))); + end); + it("test vector 3", function () + local P = "password" + local S = "salt" + local c = 4096 + local DK = "4b007901b765489abead49d926f721d065a429c1"; + assert.equal(DK, hex.to(hashes.scram_Hi_sha1(P, S, c))); + end); + it("test vector 4 #SLOW", function () + local P = "password" + local S = "salt" + local c = 16777216 + local DK = "eefe3d61cd4da4e4e9945b3d6ba2158c2634e984"; + assert.equal(DK, hex.to(hashes.scram_Hi_sha1(P, S, c))); + end); +end); + -- cgit v1.2.3 From 165ee3a5ef1247468e98d0d4cba6fc43e15f92d7 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 20 Apr 2019 15:11:04 +0200 Subject: util.hashes: Allow specifying output key length This is not needed for SCRAM but PBKDF2 takes this argument. --- spec/util_hashes_spec.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'spec') diff --git a/spec/util_hashes_spec.lua b/spec/util_hashes_spec.lua index 1e6187bb..9099145a 100644 --- a/spec/util_hashes_spec.lua +++ b/spec/util_hashes_spec.lua @@ -33,5 +33,21 @@ describe("PBKDF2-SHA1", function () local DK = "eefe3d61cd4da4e4e9945b3d6ba2158c2634e984"; assert.equal(DK, hex.to(hashes.scram_Hi_sha1(P, S, c))); end); + it("test vector 5", function () + local P = "passwordPASSWORDpassword" + local S = "saltSALTsaltSALTsaltSALTsaltSALTsalt" + local c = 4096 + local dkLen = 25 + local DK = "3d2eec4fe41c849b80c8d83662c0e44a8b291a964cf2f07038" + assert.equal(DK, hex.to(hashes.scram_Hi_sha1(P, S, c, dkLen))); + end); + it("works", function () + local P = "pass\0word" + local S = "sa\0lt" + local c = 4096 + local dkLen = 16 + local DK = "56fa6aa75548099dcc37d7f03425e0c3" + assert.equal(DK, hex.to(hashes.scram_Hi_sha1(P, S, c, dkLen))); + end); end); -- cgit v1.2.3 From 90d4d6bda8161d7fdc730f822db13a1a8639aee4 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 21 Apr 2019 00:59:36 +0200 Subject: Backed out changeset 61bc5c52c941 luaL_buffinitsize is only available in Lua 5.2+ --- spec/util_hashes_spec.lua | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'spec') diff --git a/spec/util_hashes_spec.lua b/spec/util_hashes_spec.lua index 9099145a..1e6187bb 100644 --- a/spec/util_hashes_spec.lua +++ b/spec/util_hashes_spec.lua @@ -33,21 +33,5 @@ describe("PBKDF2-SHA1", function () local DK = "eefe3d61cd4da4e4e9945b3d6ba2158c2634e984"; assert.equal(DK, hex.to(hashes.scram_Hi_sha1(P, S, c))); end); - it("test vector 5", function () - local P = "passwordPASSWORDpassword" - local S = "saltSALTsaltSALTsaltSALTsaltSALTsalt" - local c = 4096 - local dkLen = 25 - local DK = "3d2eec4fe41c849b80c8d83662c0e44a8b291a964cf2f07038" - assert.equal(DK, hex.to(hashes.scram_Hi_sha1(P, S, c, dkLen))); - end); - it("works", function () - local P = "pass\0word" - local S = "sa\0lt" - local c = 4096 - local dkLen = 16 - local DK = "56fa6aa75548099dcc37d7f03425e0c3" - assert.equal(DK, hex.to(hashes.scram_Hi_sha1(P, S, c, dkLen))); - end); end); -- cgit v1.2.3 From f65c017ee107f86b353d5931e85a70e8c6067f1f Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 3 May 2019 20:54:24 +0200 Subject: Fix various spelling mistakes [codespell] --- spec/util_throttle_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/util_throttle_spec.lua b/spec/util_throttle_spec.lua index 75daf1b9..985afae8 100644 --- a/spec/util_throttle_spec.lua +++ b/spec/util_throttle_spec.lua @@ -88,7 +88,7 @@ describe("util.throttle", function() later(0.1); a:update(); end - assert(math.abs(a.balance - 1) < 0.0001); -- incremental updates cause rouding errors + assert(math.abs(a.balance - 1) < 0.0001); -- incremental updates cause rounding errors end); end); -- cgit v1.2.3 From 46822c54b1e6ba4e37b88e7184147fbf57f99782 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 13 May 2019 10:36:03 +0100 Subject: util.hashring: Add tests --- spec/util_hashring_spec.lua | 85 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 spec/util_hashring_spec.lua (limited to 'spec') diff --git a/spec/util_hashring_spec.lua b/spec/util_hashring_spec.lua new file mode 100644 index 00000000..d8801774 --- /dev/null +++ b/spec/util_hashring_spec.lua @@ -0,0 +1,85 @@ +local hashring = require "util.hashring"; + +describe("util.hashring", function () + + local sha256 = require "util.hashes".sha256; + + local ring = hashring.new(128, sha256); + + it("should fail to get a node that does not exist", function () + assert.is_nil(ring:get_node("foo")) + end); + + it("should support adding nodes", function () + ring:add_node("node1"); + end); + + it("should return a single node for all keys if only one node exists", function () + for i = 1, 100 do + assert.is_equal("node1", ring:get_node(tostring(i))) + end + end); + + it("should support adding a second node", function () + ring:add_node("node2"); + end); + + it("should fail to remove a non-existent node", function () + assert.is_falsy(ring:remove_node("node3")); + end); + + it("should succeed to remove a node", function () + assert.is_truthy(ring:remove_node("node1")); + end); + + it("should return the only node for all keys", function () + for i = 1, 100 do + assert.is_equal("node2", ring:get_node(tostring(i))) + end + end); + + it("should support adding multiple nodes", function () + ring:add_nodes({ "node1", "node3", "node4", "node5" }); + end); + + it("should disrupt a minimal number of keys on node removal", function () + local orig_ring = ring:clone(); + local node_tallies = {}; + + local n = 1000; + + for i = 1, n do + local key = tostring(i); + local node = ring:get_node(key); + node_tallies[node] = (node_tallies[node] or 0) + 1; + end + + --[[ + for node, key_count in pairs(node_tallies) do + print(node, key_count, ("%.2f%%"):format((key_count/n)*100)); + end + ]] + + ring:remove_node("node5"); + + local disrupted_keys = 0; + for i = 1, n do + local key = tostring(i); + if orig_ring:get_node(key) ~= ring:get_node(key) then + disrupted_keys = disrupted_keys + 1; + end + end + assert.is_equal(node_tallies["node5"], disrupted_keys); + end); + + it("should support removing multiple nodes", function () + ring:remove_nodes({"node2", "node3", "node4", "node5"}); + end); + + it("should return a single node for all keys if only one node remains", function () + for i = 1, 100 do + assert.is_equal("node1", ring:get_node(tostring(i))) + end + end); + +end); -- cgit v1.2.3 From 236abc4afed5321e0da406e369a8b23dac6fef83 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 30 May 2019 13:41:05 +0200 Subject: util.format: Handle formats expecting an integer in Lua 5.3+ (fixes #1371) --- spec/util_format_spec.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'spec') diff --git a/spec/util_format_spec.lua b/spec/util_format_spec.lua index b9652d19..82b70205 100644 --- a/spec/util_format_spec.lua +++ b/spec/util_format_spec.lua @@ -12,6 +12,7 @@ describe("util.format", function() assert.equal("[true]", format("%d", true)); assert.equal("% [true]", format("%%", true)); assert.equal("{ }", format("%q", { })); + assert.equal("[1.5]", format("%d", 1.5)); end); end); end); -- cgit v1.2.3 From 2661a6f5a32731100287df9564c45cbe2406e0f0 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 30 May 2019 13:54:11 +0200 Subject: util.format: Handle integer formats the same way on Lua versions without integer support --- spec/util_format_spec.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'spec') diff --git a/spec/util_format_spec.lua b/spec/util_format_spec.lua index 82b70205..50509630 100644 --- a/spec/util_format_spec.lua +++ b/spec/util_format_spec.lua @@ -13,6 +13,7 @@ describe("util.format", function() assert.equal("% [true]", format("%%", true)); assert.equal("{ }", format("%q", { })); assert.equal("[1.5]", format("%d", 1.5)); + assert.equal("[7.3786976294838e+19]", format("%d", 73786976294838206464)); end); end); end); -- cgit v1.2.3 From 56b07603dd018dc6cfd67bf0b34bb5539455a761 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 29 Jul 2019 00:51:03 +0200 Subject: util.array: Add tests --- spec/util_array_spec.lua | 154 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 spec/util_array_spec.lua (limited to 'spec') diff --git a/spec/util_array_spec.lua b/spec/util_array_spec.lua new file mode 100644 index 00000000..acd2e882 --- /dev/null +++ b/spec/util_array_spec.lua @@ -0,0 +1,154 @@ +local array = require "util.array"; +describe("util.array", function () + describe("creation", function () + describe("from tablle", function () + it("works", function () + local a = array({"a", "b", "c"}); + assert.same({"a", "b", "c"}, a); + end); + end); + + describe("from iterator", function () + it("works", function () + -- collects the first value, ie the keys + local a = array(ipairs({true, true, true})); + assert.same({1, 2, 3}, a); + end); + end); + + describe("collect", function () + it("works", function () + -- collects the first value, ie the keys + local a = array.collect(ipairs({true, true, true})); + assert.same({1, 2, 3}, a); + end); + end); + + end); + + describe("metatable", function () + describe("operator", function () + describe("addition", function () + it("works", function () + local a = array({ "a", "b" }); + local b = array({ "c", "d" }); + assert.same({"a", "b", "c", "d"}, a + b); + end); + end); + + describe("equality", function () + it("works", function () + local a1 = array({ "a", "b" }); + local a2 = array({ "a", "b" }); + local b = array({ "c", "d" }); + assert.truthy(a1 == a2); + assert.falsy(a1 == b); + end); + end); + + describe("division", function () + it("works", function () + local a = array({ "a", "b", "c" }); + local b = a / function (i) if i ~= "b" then return i .. "x" end end; + assert.same({ "ax", "cx" }, b); + end); + end); + + end); + end); + + describe("methods", function () + describe("map", function () + it("works", function () + local a = array({ "a", "b", "c" }); + local b = a:map(string.upper); + assert.same({ "A", "B", "C" }, b); + end); + end); + + describe("filter", function () + it("works", function () + local a = array({ "a", "b", "c" }); + a:filter(function (i) return i ~= "b" end); + assert.same({ "a", "c" }, a); + end); + end); + + describe("sort", function () + it("works", function () + local a = array({ 5, 4, 3, 1, 2, }); + a:sort(); + assert.same({ 1, 2, 3, 4, 5, }, a); + end); + end); + + describe("unique", function () + it("works", function () + local a = array({ "a", "b", "c", "c", "a", "b" }); + a:unique(); + assert.same({ "a", "b", "c" }, a); + end); + end); + + describe("pluck", function () + it("works", function () + local a = array({ { a = 1, b = -1 }, { a = 2, b = -2 }, }); + a:pluck("a"); + assert.same({ 1, 2 }, a); + end); + end); + + + describe("reverse", function () + it("works", function () + local a = array({ "a", "b", "c" }); + a:reverse(); + assert.same({ "c", "b", "a" }, a); + end); + end); + + -- TODO :shuffle + + describe("append", function () + it("works", function () + local a = array({ "a", "b", "c" }); + a:append(array({ "d", "e", })); + assert.same({ "a", "b", "c", "d", "e" }, a); + end); + end); + + describe("push", function () + it("works", function () + local a = array({ "a", "b", "c" }); + a:push("d"):push("e"); + assert.same({ "a", "b", "c", "d", "e" }, a); + end); + end); + + describe("pop", function () + it("works", function () + local a = array({ "a", "b", "c" }); + assert.equal("c", a:pop()); + assert.same({ "a", "b", }, a); + end); + end); + + describe("concat", function () + it("works", function () + local a = array({ "a", "b", "c" }); + assert.equal("a,b,c", a:concat(",")); + end); + end); + + describe("length", function () + it("works", function () + local a = array({ "a", "b", "c" }); + assert.equal(3, a:length()); + end); + end); + + end); + + -- TODO The various array.foo(array ina, array outa) functions +end); + -- cgit v1.2.3 From ab82920e54c61272770c93051deeb29396171228 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 29 Jul 2019 17:26:03 +0200 Subject: util.error: Add tests --- spec/util_error_spec.lua | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 spec/util_error_spec.lua (limited to 'spec') diff --git a/spec/util_error_spec.lua b/spec/util_error_spec.lua new file mode 100644 index 00000000..d8534c2b --- /dev/null +++ b/spec/util_error_spec.lua @@ -0,0 +1,68 @@ +local errors = require "util.error" + +describe("util.error", function () + describe("new()", function () + it("works", function () + local err = errors.new("bork", "bork bork"); + assert.not_nil(err); + assert.equal("cancel", err.type); + assert.equal("undefined-condition", err.condition); + assert.same("bork bork", err.context); + end); + + describe("templates", function () + it("works", function () + local templates = { + ["fail"] = { + type = "wait", + condition = "internal-server-error", + }; + }; + local err = errors.new("fail", { traceback = "in some file, somewhere" }, templates); + assert.equal("wait", err.type); + assert.equal("internal-server-error", err.condition); + assert.same({ traceback = "in some file, somewhere" }, err.context); + end); + end); + + end); + + describe("is_err()", function () + it("works", function () + assert.truthy(errors.is_err(errors.new())); + assert.falsy(errors.is_err("not an error")); + end); + end); + + describe("coerce", function () + it("works", function () + local ok, err = errors.coerce(nil, "it dun goofed"); + assert.is_nil(ok); + assert.truthy(errors.is_err(err)) + end); + end); + + describe("from_stanza", function () + it("works", function () + local st = require "util.stanza"; + local m = st.message({ type = "chat" }); + local e = st.error_reply(m, "modify", "bad-request"); + local err = errors.from_stanza(e); + assert.truthy(errors.is_err(err)); + assert.equal("modify", err.type); + assert.equal("bad-request", err.condition); + assert.equal(e, err.context.stanza); + end); + end); + + describe("__tostring", function () + it("doesn't throw", function () + assert.has_no.errors(function () + -- See 6f317e51544d + tostring(errors.new()); + end); + end); + end); + +end); + -- cgit v1.2.3 From 59c1712dfe1ba856aa8c3bd3e0dfa5c8db7ccec1 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 31 Aug 2019 16:04:50 +0200 Subject: MUC: Add a test covering basic room creation, messages and destruction --- spec/scansion/muc_create_destroy.scs | 242 +++++++++++++++++++++++++++++++++++ 1 file changed, 242 insertions(+) create mode 100644 spec/scansion/muc_create_destroy.scs (limited to 'spec') diff --git a/spec/scansion/muc_create_destroy.scs b/spec/scansion/muc_create_destroy.scs new file mode 100644 index 00000000..b24ef4a2 --- /dev/null +++ b/spec/scansion/muc_create_destroy.scs @@ -0,0 +1,242 @@ +# MUC creation, basic messages and destruction + +[Client] Romeo + jid: romeo@localhost/mK0dD6Ha + password: password + +[Client] Juliet + jid: juliet@localhost/lVwkim_k + password: password + +----- + +Romeo connects + +Romeo sends: + + + + +Romeo receives: + + + + + + + + + +Romeo receives: + + + + +Romeo sends: + + + + + + +Romeo receives: + + +Juliet connects + +Romeo sends: + + Where are thou my Juliet? + + +Romeo receives: + + Where are thou my Juliet? + + +Juliet sends: + + + + +Juliet receives: + + + + + + + +Juliet receives: + + + + + + + + +Juliet receives: + + Where are thou my Juliet? + + + + +Juliet receives: + + + + +Romeo receives: + + + + + + + +Juliet sends: + + /me jumps out from behind a tree + + +Romeo receives: + + /me jumps out from behind a tree + + +Juliet receives: + + /me jumps out from behind a tree + + +Juliet sends: + + Here I am! + + +Romeo receives: + + Here I am! + + +Juliet receives: + + Here I am! + + +Romeo sends: + + What is this place? + + +Romeo receives: + + What is this place? + + +Juliet receives: + + What is this place? + + +Juliet sends: + + I think we're in a script! + + +Romeo receives: + + I think we're in a script! + + +Juliet receives: + + I think we're in a script! + + +Romeo sends: + + Oh no! Does that mean our love is not real?! + + +Romeo receives: + + Oh no! Does that mean our love is not real?! + + +Juliet receives: + + Oh no! Does that mean our love is not real?! + + +Juliet sends: + + I refuse to accept this! Let's burn this place to the ground! + + +Romeo receives: + + I refuse to accept this! Let's burn this place to the ground! + + +Juliet receives: + + I refuse to accept this! Let's burn this place to the ground! + + +Romeo sends: + + Yes! + + +Romeo receives: + + Yes! + + +Juliet receives: + + Yes! + + +Romeo sends: + + + + We refuse to live in this fantasy! + + + + +Juliet receives: + + + + We refuse to live in this fantasy! + + + + + + +Romeo receives: + + + + We refuse to live in this fantasy! + + + + + + +Romeo receives: + + +Juliet disconnects + +Romeo disconnects + +# recording ended on 2019-08-31T13:45:32Z -- cgit v1.2.3 From 887ccb25c5a26f7d645e626b3ad915cf84793dde Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 31 Aug 2019 16:15:51 +0200 Subject: MUC: Fix delay tag @from in test to be the room JID (#1054 came back) --- spec/scansion/muc_create_destroy.scs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec') diff --git a/spec/scansion/muc_create_destroy.scs b/spec/scansion/muc_create_destroy.scs index b24ef4a2..4b16fbf2 100644 --- a/spec/scansion/muc_create_destroy.scs +++ b/spec/scansion/muc_create_destroy.scs @@ -79,8 +79,8 @@ Juliet receives: Juliet receives: Where are thou my Juliet? - - + + Juliet receives: -- cgit v1.2.3 From f724d890d28484d3c6d818b93c348019ce1256fb Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 7 Sep 2019 00:46:06 +0200 Subject: tests: Disable TLS in scansion tests They were not using TLS before. With a36af4570b39 TLS context creation will succeed even without a certificate, so TLS will be offered, but since there is no certificate it does not work. --- spec/scansion/prosody.cfg.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/scansion/prosody.cfg.lua b/spec/scansion/prosody.cfg.lua index fd742db6..1c359b27 100644 --- a/spec/scansion/prosody.cfg.lua +++ b/spec/scansion/prosody.cfg.lua @@ -8,7 +8,7 @@ modules_enabled = { -- Generally required "roster"; -- Allow users to have a roster. Recommended ;) "saslauth"; -- Authentication for clients and servers. Recommended if you want to log in. - "tls"; -- Add support for secure TLS on c2s/s2s connections + --"tls"; -- Add support for secure TLS on c2s/s2s connections "dialback"; -- s2s dialback support "disco"; -- Service discovery -- cgit v1.2.3 From 52198503001e9e701fc89036972d7374ca14b249 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 21 Sep 2019 17:52:07 +0200 Subject: MUC: Update test for vcard-temp changes Should this XEP-0398 behavior even be covered here? The original lines came from a recording. --- spec/scansion/muc_create_destroy.scs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'spec') diff --git a/spec/scansion/muc_create_destroy.scs b/spec/scansion/muc_create_destroy.scs index 4b16fbf2..9a66c160 100644 --- a/spec/scansion/muc_create_destroy.scs +++ b/spec/scansion/muc_create_destroy.scs @@ -19,7 +19,8 @@ Romeo sends: Romeo receives: - + + @@ -61,7 +62,9 @@ Juliet sends: Juliet receives: - + + + @@ -69,7 +72,9 @@ Juliet receives: Juliet receives: - + + + @@ -90,7 +95,9 @@ Juliet receives: Romeo receives: - + + + -- cgit v1.2.3 From 9f70749716ef88e9fa5017e41d6dfb7b177f6cea Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 21 Sep 2019 18:16:45 +0200 Subject: MUC: Fix XML syntax error in test How did this even happen? --- spec/scansion/muc_create_destroy.scs | 1 + 1 file changed, 1 insertion(+) (limited to 'spec') diff --git a/spec/scansion/muc_create_destroy.scs b/spec/scansion/muc_create_destroy.scs index 9a66c160..fea759a3 100644 --- a/spec/scansion/muc_create_destroy.scs +++ b/spec/scansion/muc_create_destroy.scs @@ -19,6 +19,7 @@ Romeo sends: Romeo receives: + -- cgit v1.2.3 From 843104372c0ec065a89d09f25079f68b98314c31 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 30 Sep 2019 08:22:30 +0100 Subject: util.promise: Add some additional tests to cover callback return values --- spec/util_promise_spec.lua | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'spec') diff --git a/spec/util_promise_spec.lua b/spec/util_promise_spec.lua index 65d252f6..0008c6a2 100644 --- a/spec/util_promise_spec.lua +++ b/spec/util_promise_spec.lua @@ -248,6 +248,30 @@ describe("util.promise", function () assert.spy(cb3).was_called(1); assert.spy(cb3).was_called_with("goodbye"); end); + + it("ordinary values", function () + local p = promise.resolve() + local cb = spy.new(function () + return "hello" + end); + local cb2 = spy.new(function () end); + p:next(cb):next(cb2); + assert.spy(cb).was_called(1); + assert.spy(cb2).was_called(1); + assert.spy(cb2).was_called_with("hello"); + end); + + it("nil", function () + local p = promise.resolve() + local cb = spy.new(function () + return + end); + local cb2 = spy.new(function () end); + p:next(cb):next(cb2); + assert.spy(cb).was_called(1); + assert.spy(cb2).was_called(1); + assert.spy(cb2).was_called_with(nil); + end); end); describe("race()", function () -- cgit v1.2.3 From 8b19b4435f6feded2bfffa4ee5a11716579ec7ea Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 20 Oct 2019 20:53:41 +0200 Subject: util.interpolation: Test #1452 --- spec/util_interpolation_spec.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/util_interpolation_spec.lua b/spec/util_interpolation_spec.lua index 88d9f844..9fcad469 100644 --- a/spec/util_interpolation_spec.lua +++ b/spec/util_interpolation_spec.lua @@ -1,5 +1,5 @@ local template = [[ -{greet!}, {name?world}! +{greet!?Hi}, {name?world}! ]]; local expect1 = [[ Hello, WORLD! @@ -7,11 +7,15 @@ Hello, WORLD! local expect2 = [[ Hello, world! ]]; +local expect3 = [[ +Hi, YOU! +]]; describe("util.interpolation", function () it("renders", function () local render = require "util.interpolation".new("%b{}", string.upper); assert.equal(expect1, render(template, { greet = "Hello", name = "world" })); assert.equal(expect2, render(template, { greet = "Hello" })); + assert.equal(expect3, render(template, { name = "you" })); end); end); -- cgit v1.2.3 From c0a72783661d8008519a0283ac7f107661f89c6b Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 20 Oct 2019 20:56:29 +0200 Subject: util.interpolation: Test array syntax --- spec/util_interpolation_spec.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'spec') diff --git a/spec/util_interpolation_spec.lua b/spec/util_interpolation_spec.lua index 9fcad469..4106e10b 100644 --- a/spec/util_interpolation_spec.lua +++ b/spec/util_interpolation_spec.lua @@ -10,6 +10,13 @@ Hello, world! local expect3 = [[ Hi, YOU! ]]; +local template_array = [[ +{foo#{idx}. {item} +}]] +local expect_array = [[ +1. HELLO +2. WORLD +]] describe("util.interpolation", function () it("renders", function () @@ -17,5 +24,6 @@ describe("util.interpolation", function () assert.equal(expect1, render(template, { greet = "Hello", name = "world" })); assert.equal(expect2, render(template, { greet = "Hello" })); assert.equal(expect3, render(template, { name = "you" })); + assert.equal(expect_array, render(template_array, { foo = { "Hello", "World" } })); end); end); -- cgit v1.2.3 From 9889cb8bb4c614939a4a82624b0e7e3539b80b63 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 20 Oct 2019 20:58:19 +0200 Subject: util.interpolation: Test map syntax --- spec/util_interpolation_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'spec') diff --git a/spec/util_interpolation_spec.lua b/spec/util_interpolation_spec.lua index 4106e10b..eb49e53b 100644 --- a/spec/util_interpolation_spec.lua +++ b/spec/util_interpolation_spec.lua @@ -17,6 +17,12 @@ local expect_array = [[ 1. HELLO 2. WORLD ]] +local template_map = [[ +{foo%{idx}: {item!} +}]] +local expect_map = [[ +FOO: bar +]] describe("util.interpolation", function () it("renders", function () @@ -25,5 +31,6 @@ describe("util.interpolation", function () assert.equal(expect2, render(template, { greet = "Hello" })); assert.equal(expect3, render(template, { name = "you" })); assert.equal(expect_array, render(template_array, { foo = { "Hello", "World" } })); + assert.equal(expect_map, render(template_map, { foo = { foo = "bar" } })); end); end); -- cgit v1.2.3 From b5b9b70c88a1287f034bceccdd953fe805bc78c6 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 27 Oct 2019 14:45:57 +0000 Subject: util.pubsub, pubsub.lib and tests: Add text to precondition-not-met error (fixes #1455) --- spec/scansion/pubsub_preconditions.scs | 234 +++++++++++++++++++++++++++++++++ spec/util_pubsub_spec.lua | 2 +- 2 files changed, 235 insertions(+), 1 deletion(-) create mode 100644 spec/scansion/pubsub_preconditions.scs (limited to 'spec') diff --git a/spec/scansion/pubsub_preconditions.scs b/spec/scansion/pubsub_preconditions.scs new file mode 100644 index 00000000..25afaa8d --- /dev/null +++ b/spec/scansion/pubsub_preconditions.scs @@ -0,0 +1,234 @@ +# Pubsub preconditions are enforced + +[Client] Romeo + password: password + jid: jqpcrbq2@localhost + +----- + +Romeo connects + +Romeo sends: + + + + + + + + + + +Romeo receives: + + + + + + + + +Romeo sends: + + + + + + +Romeo receives: + + + + + + http://jabber.org/protocol/pubsub#node_config + + + + + + + 1 + + + 1 + + + + + + + + presence + + + + + + publishers + + + 1 + + + 1 + + + + + headline + + + 1 + + + 1 + + + + + + +Romeo sends: + + + + + + http://jabber.org/protocol/pubsub#node_config + + + Nice tunes + + + + + + 1 + + + 1 + + + + + + + + presence + + + + + + publishers + + + 1 + + + 1 + + + + + headline + + + 1 + + + 1 + + + + + + +Romeo receives: + + +Romeo sends: + + + + +Romeo receives: + + + + + + +Romeo sends: + + + + + + + + + + + http://jabber.org/protocol/pubsub#publish-options + + + whitelist + + + + + + +Romeo receives: + + + + Field does not match: access_model + + + + +Romeo disconnects + diff --git a/spec/util_pubsub_spec.lua b/spec/util_pubsub_spec.lua index c982fb36..a48bd400 100644 --- a/spec/util_pubsub_spec.lua +++ b/spec/util_pubsub_spec.lua @@ -107,7 +107,7 @@ describe("util.pubsub", function () it("fails to publish to a node with differing config", function () local ok, err = service:publish("node", true, "1", "item 2", { myoption = false }); assert.falsy(ok); - assert.equals("precondition-not-met", err); + assert.equals("precondition-not-met", err.pubsub_condition); end); it("allows to publish to a node with differing config when only defaults are suggested", function () -- cgit v1.2.3 From 03adb505558555cd2449bea0ae83c0a89c82a399 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 1 Nov 2019 18:31:12 +0100 Subject: util.error: Add well-known field 'code' in error templates Intended to be for HTTP-ish numeric status codes --- spec/util_error_spec.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'spec') diff --git a/spec/util_error_spec.lua b/spec/util_error_spec.lua index d8534c2b..ca053285 100644 --- a/spec/util_error_spec.lua +++ b/spec/util_error_spec.lua @@ -16,11 +16,13 @@ describe("util.error", function () ["fail"] = { type = "wait", condition = "internal-server-error", + code = 555; }; }; local err = errors.new("fail", { traceback = "in some file, somewhere" }, templates); assert.equal("wait", err.type); assert.equal("internal-server-error", err.condition); + assert.equal(555, err.code); assert.same({ traceback = "in some file, somewhere" }, err.context); end); end); -- cgit v1.2.3 From fb0fee842496d9cf89464479406352161f2888bd Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 2 Nov 2019 14:22:06 +0100 Subject: MUC: Make nickname field in registration form required Prevents traceback from resourceprep(nil) muc#register_roomnick is also required in XEP-0045 --- spec/scansion/muc_register.scs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'spec') diff --git a/spec/scansion/muc_register.scs b/spec/scansion/muc_register.scs index e1eaf4e0..a077cd76 100644 --- a/spec/scansion/muc_register.scs +++ b/spec/scansion/muc_register.scs @@ -100,7 +100,9 @@ Juliet receives: http://jabber.org/protocol/muc#register - + + + @@ -339,7 +341,9 @@ Romeo receives: http://jabber.org/protocol/muc#register - + + + -- cgit v1.2.3 From a9980f81fadf325ed8f609ae3787c061dba63f94 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 7 Nov 2019 00:20:54 +0100 Subject: util.array: Fix typo in test --- spec/util_array_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/util_array_spec.lua b/spec/util_array_spec.lua index acd2e882..04d0cc28 100644 --- a/spec/util_array_spec.lua +++ b/spec/util_array_spec.lua @@ -1,7 +1,7 @@ local array = require "util.array"; describe("util.array", function () describe("creation", function () - describe("from tablle", function () + describe("from table", function () it("works", function () local a = array({"a", "b", "c"}); assert.same({"a", "b", "c"}, a); -- cgit v1.2.3 From e0e0b24f003bcebc564fcebeb745717a4e08b5b7 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 17 Nov 2019 15:06:22 +0100 Subject: util.interpolation: Test template filters --- spec/util_interpolation_spec.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/util_interpolation_spec.lua b/spec/util_interpolation_spec.lua index eb49e53b..21d1abe0 100644 --- a/spec/util_interpolation_spec.lua +++ b/spec/util_interpolation_spec.lua @@ -17,6 +17,15 @@ local expect_array = [[ 1. HELLO 2. WORLD ]] +local template_func_pipe = [[ +{foo|sort#{idx}. {item} +}]] +local expect_func_pipe = [[ +1. A +2. B +3. C +4. D +]] local template_map = [[ {foo%{idx}: {item!} }]] @@ -26,11 +35,12 @@ FOO: bar describe("util.interpolation", function () it("renders", function () - local render = require "util.interpolation".new("%b{}", string.upper); + local render = require "util.interpolation".new("%b{}", string.upper, { sort = function (t) table.sort(t) return t end }); assert.equal(expect1, render(template, { greet = "Hello", name = "world" })); assert.equal(expect2, render(template, { greet = "Hello" })); assert.equal(expect3, render(template, { name = "you" })); assert.equal(expect_array, render(template_array, { foo = { "Hello", "World" } })); + assert.equal(expect_func_pipe, render(template_func_pipe, { foo = { "c", "a", "d", "b", } })); assert.equal(expect_map, render(template_map, { foo = { foo = "bar" } })); end); end); -- cgit v1.2.3 From a7579e93f5833154aef8d67f068064d71b5dc731 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 17 Nov 2019 15:32:28 +0100 Subject: util.interpolation: Add commented test case for passing nil to filter --- spec/util_interpolation_spec.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'spec') diff --git a/spec/util_interpolation_spec.lua b/spec/util_interpolation_spec.lua index 21d1abe0..76000d94 100644 --- a/spec/util_interpolation_spec.lua +++ b/spec/util_interpolation_spec.lua @@ -41,6 +41,7 @@ describe("util.interpolation", function () assert.equal(expect3, render(template, { name = "you" })); assert.equal(expect_array, render(template_array, { foo = { "Hello", "World" } })); assert.equal(expect_func_pipe, render(template_func_pipe, { foo = { "c", "a", "d", "b", } })); + -- assert.equal("", render(template_func_pipe, { foo = nil })); -- FIXME assert.equal(expect_map, render(template_map, { foo = { foo = "bar" } })); end); end); -- cgit v1.2.3 From 7ed435c0548a7c735c74234f081e267302970be6 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 24 Nov 2019 00:02:48 +0100 Subject: MUC: Add testcase for #1466 --- spec/scansion/muc_nickname_change.scs | 127 ++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 spec/scansion/muc_nickname_change.scs (limited to 'spec') diff --git a/spec/scansion/muc_nickname_change.scs b/spec/scansion/muc_nickname_change.scs new file mode 100644 index 00000000..73f81203 --- /dev/null +++ b/spec/scansion/muc_nickname_change.scs @@ -0,0 +1,127 @@ +# MUC: Change nickname +# Make sure a role is not reset, see #1466 + +[Client] Romeo + jid: user@localhost + password: password + +[Client] Juliet + jid: user2@localhost + password: password + +----- + +Romeo connects + +Romeo sends: + + + + +Romeo receives: + + + + + + + + +Romeo receives: + + +Romeo sends: + + + + + http://jabber.org/protocol/muc#roomconfig + + + 1 + + + + + +Romeo receives: + + +Juliet connects + +Juliet sends: + + + + +Juliet receives: + + + + + + +Juliet receives: + + + + + + + + +Juliet receives: + + +Romeo receives: + + + + + + +Romeo sends: + + + + + http://jabber.org/protocol/muc#roomconfig + + + 0 + + + + + +Romeo receives: + + +Juliet receives: + + + + + + +Juliet sends: + + + +Juliet receives: + + + + + + + + +Juliet receives: + + + + + + + -- cgit v1.2.3 From b340e5e4628e2f5c136fe1f4300821d89ed4cb94 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 25 Nov 2019 20:44:05 +0100 Subject: util.stanza: Check that argument to reply is a stanza --- spec/util_stanza_spec.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'spec') diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua index 38503ab7..7d710888 100644 --- a/spec/util_stanza_spec.lua +++ b/spec/util_stanza_spec.lua @@ -170,6 +170,12 @@ describe("util.stanza", function() assert.are.equal(r.attr.type, "result"); assert.are.equal(#r.tags, 0, "A reply should not include children of the original stanza"); end); + + it("should reject not-stanzas", function () + assert.has.error_match(function () + st.reply(not "a stanza"); + end, "expected stanza"); + end); end); describe("#error_reply()", function() -- cgit v1.2.3 From 11095184a53cc144e37560b7bbbf4de19ce669c7 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 25 Nov 2019 20:46:55 +0100 Subject: util.stanza: Remove redundant check for attrs A stanza can't not have attrs if created the correct way --- spec/util_stanza_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'spec') diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua index 7d710888..3b9084fa 100644 --- a/spec/util_stanza_spec.lua +++ b/spec/util_stanza_spec.lua @@ -176,6 +176,13 @@ describe("util.stanza", function() st.reply(not "a stanza"); end, "expected stanza"); end); + + it("should reject not-stanzas", function () + assert.has.error_match(function () + st.reply({name="x"}); + end, "expected stanza"); + end); + end); describe("#error_reply()", function() -- cgit v1.2.3 From 52b7181979bcee9000acf1c90e85934976e4da6a Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 25 Nov 2019 20:52:01 +0100 Subject: util.stanza: Check that argument to error_reply is a stanza --- spec/util_stanza_spec.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'spec') diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua index 3b9084fa..23cdbeb9 100644 --- a/spec/util_stanza_spec.lua +++ b/spec/util_stanza_spec.lua @@ -214,6 +214,12 @@ describe("util.stanza", function() assert.are.equal(#r.tags, 1); assert.are.equal(r.tags[1].tags[1].name, "service-unavailable"); end); + + it("should reject not-stanzas", function () + assert.has.error_match(function () + st.error_reply(not "a stanza", "modify", "bad-request"); + end, "expected stanza"); + end); end); describe("should reject #invalid", function () -- cgit v1.2.3 From 54da2ab6f7fec145d05ac8682c50a776bb993880 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 25 Nov 2019 20:52:03 +0100 Subject: util.stanza: Check that argument to error_reply is NOT a stanza of type error Replying to an error is Very Bad --- spec/util_stanza_spec.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'spec') diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua index 23cdbeb9..04458303 100644 --- a/spec/util_stanza_spec.lua +++ b/spec/util_stanza_spec.lua @@ -220,6 +220,16 @@ describe("util.stanza", function() st.error_reply(not "a stanza", "modify", "bad-request"); end, "expected stanza"); end); + + it("should reject stanzas of type error", function () + assert.has.error_match(function () + st.error_reply(st.message({type="error"}), "cancel", "conflict"); + end, "got stanza of type error"); + assert.has.error_match(function () + st.error_reply(st.error_reply(st.message({type="chat"}), "modify", "forbidden"), "cancel", "service-unavailable"); + end, "got stanza of type error"); + end); + end); describe("should reject #invalid", function () -- cgit v1.2.3 From be23b274f685f5eac73b79231491f4f0141f1c1c Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 25 Nov 2019 20:59:36 +0100 Subject: util.stanza: Support the 'by' attribute on errors This is to be used when the entity generating the error is not the same as the one the stanza was directed to, e.g. an intermediate server. --- spec/util_stanza_spec.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua index 04458303..b754f59d 100644 --- a/spec/util_stanza_spec.lua +++ b/spec/util_stanza_spec.lua @@ -191,13 +191,14 @@ describe("util.stanza", function() local s = st.stanza("s", { to = "touser", from = "fromuser", id = "123" }) :tag("child1"); -- Make reply stanza - local r = st.error_reply(s, "cancel", "service-unavailable"); + local r = st.error_reply(s, "cancel", "service-unavailable", nil, "host"); assert.are.equal(r.name, s.name); assert.are.equal(r.id, s.id); assert.are.equal(r.attr.to, s.attr.from); assert.are.equal(r.attr.from, s.attr.to); assert.are.equal(#r.tags, 1); assert.are.equal(r.tags[1].tags[1].name, "service-unavailable"); + assert.are.equal(r.tags[1].attr.by, "host"); end); it("should work for ", function() -- cgit v1.2.3 From 057fbeaf06876cfbfbba24bbc317de313fa9e84b Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 25 Nov 2019 23:47:49 +0100 Subject: MUC: Indicate origin of password related errors --- spec/scansion/muc_password.scs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/scansion/muc_password.scs b/spec/scansion/muc_password.scs index 82611183..63c821e0 100644 --- a/spec/scansion/muc_password.scs +++ b/spec/scansion/muc_password.scs @@ -58,7 +58,7 @@ Juliet sends: Juliet receives: - + -- cgit v1.2.3 From c26f8beac4075c8d031ed9a620fac77653d1bb07 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 25 Nov 2019 23:51:41 +0100 Subject: MUC: Indicate origin of registration related errors --- spec/scansion/muc_register.scs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec') diff --git a/spec/scansion/muc_register.scs b/spec/scansion/muc_register.scs index a077cd76..5d1f5f3e 100644 --- a/spec/scansion/muc_register.scs +++ b/spec/scansion/muc_register.scs @@ -177,7 +177,7 @@ Rosaline sends: Rosaline receives: - + @@ -288,7 +288,7 @@ Rosaline sends: Rosaline receives: - + -- cgit v1.2.3 From b1aadaced9b8012b55c8b9ee158bfaf6f24ea147 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 30 Nov 2019 14:00:13 +0100 Subject: tests: Disable s2s in scansion tests These are all c2s tests, no need to have s2s enabled. --- spec/scansion/prosody.cfg.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/scansion/prosody.cfg.lua b/spec/scansion/prosody.cfg.lua index 1c359b27..3f804c4e 100644 --- a/spec/scansion/prosody.cfg.lua +++ b/spec/scansion/prosody.cfg.lua @@ -9,7 +9,7 @@ modules_enabled = { "roster"; -- Allow users to have a roster. Recommended ;) "saslauth"; -- Authentication for clients and servers. Recommended if you want to log in. --"tls"; -- Add support for secure TLS on c2s/s2s connections - "dialback"; -- s2s dialback support + --"dialback"; -- s2s dialback support "disco"; -- Service discovery -- Not essential, but recommended @@ -53,6 +53,9 @@ modules_enabled = { --"scansion_record"; -- Records things that happen in scansion test case format } +modules_disabled = { + "s2s"; +} certificate = "certs" allow_registration = false -- cgit v1.2.3 From 8d23fdfc77ff7ba88e749662dd3eaeefbf951f47 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 9 Dec 2019 11:57:10 +0000 Subject: configmanager tests: Split long line --- spec/core_configmanager_spec.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/core_configmanager_spec.lua b/spec/core_configmanager_spec.lua index afb7d492..7958ec6b 100644 --- a/spec/core_configmanager_spec.lua +++ b/spec/core_configmanager_spec.lua @@ -9,7 +9,9 @@ describe("core.configmanager", function() configmanager.set("*", "testkey1", 321); assert.are.equal(321, configmanager.get("*", "testkey1"), "Retrieving a set global key"); - assert.are.equal(321, configmanager.get("example.com", "testkey1"), "Retrieving a set key of undefined host, of which only a globally set one exists"); + assert.are.equal(321, configmanager.get("example.com", "testkey1"), + "Retrieving a set key of undefined host, of which only a globally set one exists" + ); configmanager.set("example.com", ""); -- Creates example.com host in config assert.are.equal(321, configmanager.get("example.com", "testkey1"), "Retrieving a set key, of which only a globally set one exists"); -- cgit v1.2.3 From 75ff6ee528124979ae6a5a3b2f12d6f3d76eadd3 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 9 Dec 2019 12:43:32 +0000 Subject: net.http.parser tests: Expand tests to include validation of results --- spec/net_http_parser_spec.lua | 108 +++++++++++++++++++++++++++++++++--------- 1 file changed, 86 insertions(+), 22 deletions(-) (limited to 'spec') diff --git a/spec/net_http_parser_spec.lua b/spec/net_http_parser_spec.lua index 6bba087c..8310a451 100644 --- a/spec/net_http_parser_spec.lua +++ b/spec/net_http_parser_spec.lua @@ -1,16 +1,68 @@ -local httpstreams = { [[ +local http_parser = require "net.http.parser"; + +local function test_stream(stream, expect) + local success_cb = spy.new(function (packet) + assert.is_table(packet); + assert.is_equal(expect.body, packet.body); + end); + + stream = stream:gsub("\n", "\r\n"); + local parser = http_parser.new(success_cb, error, stream:sub(1,4) == "HTTP" and "client" or "server") + for chunk in stream:gmatch("..?.?") do + parser:feed(chunk); + end + + assert.spy(success_cb).was_called(expect.count or 1); +end + + +describe("net.http.parser", function() + describe("parser", function() + it("should handle requests with no content-length or body", function () + test_stream( +[[ GET / HTTP/1.1 Host: example.com -]], [[ +]], + { + body = ""; + } + ); + end); + + it("should handle responses with empty body", function () + test_stream( +[[ HTTP/1.1 200 OK Content-Length: 0 -]], [[ +]], + { + body = ""; + } + ); + end); + + it("should handle simple responses", function () + test_stream( + +[[ HTTP/1.1 200 OK Content-Length: 7 Hello +]], + { + body = "Hello\r\n", count = 1; + } + ); + end); + + it("should handle chunked encoding in responses", function () + test_stream( + +[[ HTTP/1.1 200 OK Transfer-Encoding: chunked @@ -25,28 +77,40 @@ o 0 -]] -} +]], + { + body = "Hello", count = 1; + } + ); + end); + it("should handle a stream of responses", function () + test_stream( -local http_parser = require "net.http.parser"; +[[ +HTTP/1.1 200 OK +Content-Length: 5 -describe("net.http.parser", function() - describe("#new()", function() - it("should work", function() - for _, stream in ipairs(httpstreams) do - local success; - local function success_cb(packet) - success = true; - end - stream = stream:gsub("\n", "\r\n"); - local parser = http_parser.new(success_cb, error, stream:sub(1,4) == "HTTP" and "client" or "server") - for chunk in stream:gmatch("..?.?") do - parser:feed(chunk); - end - - assert.is_true(success); - end +Hello +HTTP/1.1 200 OK +Transfer-Encoding: chunked + +1 +H +1 +e +2 +ll +1 +o +0 + + +]], + { + body = "Hello", count = 2; + } + ); end); end); end); -- cgit v1.2.3 From 71d99b65fa50afebb0241199d4000a8a7c50e1d1 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 14 Dec 2019 22:43:12 +0100 Subject: util.sasl: Add stub tests Random uncommitted file I found when cleaning out my work dir --- spec/util_sasl_spec.lua | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 spec/util_sasl_spec.lua (limited to 'spec') diff --git a/spec/util_sasl_spec.lua b/spec/util_sasl_spec.lua new file mode 100644 index 00000000..368291b3 --- /dev/null +++ b/spec/util_sasl_spec.lua @@ -0,0 +1,43 @@ +local sasl = require "util.sasl"; + +-- profile * mechanism +-- callbacks could use spies instead + +describe("util.sasl", function () + describe("plain_test profile", function () + local profile = { + plain_test = function (_, username, password, realm) + assert.equals("user", username) + assert.equals("pencil", password) + assert.equals("sasl.test", realm) + return true, true; + end; + }; + it("works with PLAIN", function () + local plain = sasl.new("sasl.test", profile); + assert.truthy(plain:select("PLAIN")); + assert.truthy(plain:process("\000user\000pencil")); + assert.equals("user", plain.username); + end); + end); + + describe("plain profile", function () + local profile = { + plain = function (_, username, realm) + assert.equals("user", username) + assert.equals("sasl.test", realm) + return "pencil", true; + end; + }; + + it("works with PLAIN", function () + local plain = sasl.new("sasl.test", profile); + assert.truthy(plain:select("PLAIN")); + assert.truthy(plain:process("\000user\000pencil")); + assert.equals("user", plain.username); + end); + + -- TODO SCRAM + end); +end); + -- cgit v1.2.3 From 4e34c40ece0eb19f85720d63b1b0372f59e5616d Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 14 Dec 2019 22:47:41 +0100 Subject: util.stanza: Accept util.error object to error_reply If we're moving towards util.error as the standard error container then this makes sense. This may allow for future extensibility without needing a lot of optional arguments. --- spec/util_stanza_spec.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'spec') diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua index b754f59d..d38a609f 100644 --- a/spec/util_stanza_spec.lua +++ b/spec/util_stanza_spec.lua @@ -1,5 +1,6 @@ local st = require "util.stanza"; +local errors = require "util.error"; describe("util.stanza", function() describe("#preserialize()", function() @@ -231,6 +232,22 @@ describe("util.stanza", function() end, "got stanza of type error"); end); + it("should accept util.error objects", function () + local s = st.message({ to = "touser", from = "fromuser", id = "123", type = "chat" }, "Hello"); + local e = errors.new({ type = "modify", condition = "not-acceptable", text = "Bork bork bork" }); + local r = st.error_reply(s, e); + + assert.are.equal(r.name, s.name); + assert.are.equal(r.id, s.id); + assert.are.equal(r.attr.to, s.attr.from); + assert.are.equal(r.attr.from, s.attr.to); + assert.are.equal(r.attr.type, "error"); + assert.are.equal(r.tags[1].name, "error"); + assert.are.equal(r.tags[1].attr.type, e.type); + assert.are.equal(r.tags[1].tags[1].name, e.condition); + assert.are.equal(r.tags[1].tags[2]:get_text(), e.text); + end); + end); describe("should reject #invalid", function () -- cgit v1.2.3 From 6b533ad772fb32d00a2f87cb53a87ee9f3a6d689 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 16 Dec 2019 02:02:47 +0100 Subject: util.dataforms: Improve descriptions in tests --- spec/util_dataforms_spec.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'spec') diff --git a/spec/util_dataforms_spec.lua b/spec/util_dataforms_spec.lua index 89759035..085128d1 100644 --- a/spec/util_dataforms_spec.lua +++ b/spec/util_dataforms_spec.lua @@ -110,7 +110,7 @@ describe("util.dataforms", function () xform = some_form:form(); end); - it("works", function () + it("XML serialization looks like it should", function () assert.truthy(xform); assert.truthy(st.is_stanza(xform)); assert.equal("x", xform.name); @@ -316,7 +316,7 @@ describe("util.dataforms", function () end); describe(":data", function () - it("works", function () + it("returns something", function () assert.truthy(some_form:data(xform)); end); end); @@ -402,7 +402,7 @@ describe("util.dataforms", function () end); end); - describe("validation", function () + describe("datatype validation", function () local f = dataforms.new { { name = "number", @@ -411,12 +411,12 @@ describe("util.dataforms", function () }, }; - it("works", function () + it("integer roundtrip works", function () local d = f:data(f:form({number = 1})); assert.equal(1, d.number); end); - it("works", function () + it("integer error handling works", function () local d,e = f:data(f:form({number = "nan"})); assert.not_equal(1, d.number); assert.table(e); -- cgit v1.2.3 From 173990157fad6d4507e8ce2dc214e7bf35a17822 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 19 Dec 2019 10:03:16 +0000 Subject: rostermanager, mod_presence: Support for subscription preapproval (fixes #686) --- spec/scansion/presence_preapproval.scs | 74 ++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 spec/scansion/presence_preapproval.scs (limited to 'spec') diff --git a/spec/scansion/presence_preapproval.scs b/spec/scansion/presence_preapproval.scs new file mode 100644 index 00000000..ce6158d2 --- /dev/null +++ b/spec/scansion/presence_preapproval.scs @@ -0,0 +1,74 @@ +# server supports contact subscription pre-approval (RFC 6121 3.4) + +[Client] Alice + jid: preappove-a@localhost + password: password + +[Client] Bob + jid: preapprove-b@localhost + password: password + +--------- + +Alice connects + +Alice sends: + + +Alice receives: + + +Alice sends: + + +Bob connects + +Bob sends: + + + + +Bob receives: + + + + + +Bob sends: + + +Bob receives: + + +Bob sends: + + +Bob receives: + + + + + + + + +Bob receives: + + +Bob disconnects + +Alice sends: + + + + +Alice receives: + + + + + + +Alice disconnects + +Bob disconnects -- cgit v1.2.3 From 228ec67d9790822defd4cf7d64bb1de6f479f0aa Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 19 Dec 2019 16:22:12 +0100 Subject: scansion: Trim trailing whitespace in tests --- spec/scansion/basic_message.scs | 6 +++--- spec/scansion/keep_full_sub_req.scs | 2 +- spec/scansion/muc_members_only_change.scs | 2 +- spec/scansion/muc_register.scs | 2 +- spec/scansion/presence_preapproval.scs | 4 ++-- spec/scansion/pubsub_basic.scs | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) (limited to 'spec') diff --git a/spec/scansion/basic_message.scs b/spec/scansion/basic_message.scs index fb21c465..1258dbf5 100644 --- a/spec/scansion/basic_message.scs +++ b/spec/scansion/basic_message.scs @@ -79,7 +79,7 @@ Juliet's phone receives: Hello Juliet, are you there? - + # Romeo sends another bare-JID message, it should be delivered # instantly to Juliet's phone @@ -92,7 +92,7 @@ Romeo sends: Juliet's phone receives: Oh, hi! - + # Juliet's laptop goes online, but with a negative priority @@ -122,7 +122,7 @@ Romeo sends: Juliet's phone receives: How are you? - + # Romeo sends direct to Juliet's full JID, and she should receive it diff --git a/spec/scansion/keep_full_sub_req.scs b/spec/scansion/keep_full_sub_req.scs index 244c1d55..41ffec0d 100644 --- a/spec/scansion/keep_full_sub_req.scs +++ b/spec/scansion/keep_full_sub_req.scs @@ -30,7 +30,7 @@ Bob sends: Bob receives: - + Bob receives: diff --git a/spec/scansion/muc_members_only_change.scs b/spec/scansion/muc_members_only_change.scs index dc40b5a0..a708dbfb 100644 --- a/spec/scansion/muc_members_only_change.scs +++ b/spec/scansion/muc_members_only_change.scs @@ -94,7 +94,7 @@ Romeo sends: - + # As a non-member, Juliet must now be removed from the room Romeo receives: diff --git a/spec/scansion/muc_register.scs b/spec/scansion/muc_register.scs index 5d1f5f3e..81612829 100644 --- a/spec/scansion/muc_register.scs +++ b/spec/scansion/muc_register.scs @@ -328,7 +328,7 @@ Romeo receives: # Romeo updates his own registration - + Romeo sends: diff --git a/spec/scansion/presence_preapproval.scs b/spec/scansion/presence_preapproval.scs index ce6158d2..e34ac7cf 100644 --- a/spec/scansion/presence_preapproval.scs +++ b/spec/scansion/presence_preapproval.scs @@ -39,7 +39,7 @@ Bob sends: Bob receives: - + Bob sends: @@ -50,7 +50,7 @@ Bob receives: - + Bob receives: diff --git a/spec/scansion/pubsub_basic.scs b/spec/scansion/pubsub_basic.scs index d983ff66..0adf6857 100644 --- a/spec/scansion/pubsub_basic.scs +++ b/spec/scansion/pubsub_basic.scs @@ -32,7 +32,7 @@ Juliet connects -- -- -- --- +-- -- Juliet receives: -- -- cgit v1.2.3 From e0bcb4d7d43745ce677edabc1cebe6a53644723d Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 23 Dec 2019 21:33:10 +0100 Subject: tests: Silence [luacheck] warnings --- spec/core_storagemanager_spec.lua | 6 ++++++ spec/util_async_spec.lua | 2 ++ spec/util_pubsub_spec.lua | 6 ++++++ 3 files changed, 14 insertions(+) (limited to 'spec') diff --git a/spec/core_storagemanager_spec.lua b/spec/core_storagemanager_spec.lua index fd2f8742..c3534cd5 100644 --- a/spec/core_storagemanager_spec.lua +++ b/spec/core_storagemanager_spec.lua @@ -119,6 +119,7 @@ describe("storagemanager", function () describe("can be queried", function () it("for all items", function () + -- luacheck: ignore 211/err local data, err = archive:find("user", {}); assert.truthy(data); local count = 0; @@ -135,6 +136,7 @@ describe("storagemanager", function () end); it("by JID", function () + -- luacheck: ignore 211/err local data, err = archive:find("user", { with = "contact@example.com"; }); @@ -153,6 +155,7 @@ describe("storagemanager", function () end); it("by time (end)", function () + -- luacheck: ignore 211/err local data, err = archive:find("user", { ["end"] = test_time; }); @@ -171,6 +174,7 @@ describe("storagemanager", function () end); it("by time (start)", function () + -- luacheck: ignore 211/err local data, err = archive:find("user", { ["start"] = test_time; }); @@ -189,6 +193,7 @@ describe("storagemanager", function () end); it("by time (start+end)", function () + -- luacheck: ignore 211/err local data, err = archive:find("user", { ["start"] = test_time; ["end"] = test_time+1; @@ -239,6 +244,7 @@ describe("storagemanager", function () end); it("can be purged", function () + -- luacheck: ignore 211/err local ok, err = archive:delete("user"); assert.truthy(ok); local data, err = archive:find("user", { diff --git a/spec/util_async_spec.lua b/spec/util_async_spec.lua index d2de8c94..8123503b 100644 --- a/spec/util_async_spec.lua +++ b/spec/util_async_spec.lua @@ -544,6 +544,8 @@ describe("util.async", function() assert.equal(r1.state, "ready"); end); + -- luacheck: ignore 211/rf + -- FIXME what's rf? it("should support multiple done() calls", function () local processed_item; local wait, done; diff --git a/spec/util_pubsub_spec.lua b/spec/util_pubsub_spec.lua index a48bd400..75f893e3 100644 --- a/spec/util_pubsub_spec.lua +++ b/spec/util_pubsub_spec.lua @@ -101,6 +101,7 @@ describe("util.pubsub", function () assert(service:publish("node", true, "1", "item 1", { myoption = true })); local ok, config = assert(service:get_node_config("node", true)); + assert.truthy(ok); assert.equals(true, config.myoption); end); @@ -229,6 +230,7 @@ describe("util.pubsub", function () end); it("should be the default", function () local ok, config = service:get_node_config("test", true); + assert.truthy(ok); assert.equal("open", config.access_model); end); it("should allow anyone to subscribe", function () @@ -250,6 +252,7 @@ describe("util.pubsub", function () end); it("should be present in the configuration", function () local ok, config = service:get_node_config("test", true); + assert.truthy(ok); assert.equal("whitelist", config.access_model); end); it("should not allow anyone to subscribe", function () @@ -294,6 +297,7 @@ describe("util.pubsub", function () end); it("should be the default", function () local ok, config = service:get_node_config("test", true); + assert.truthy(ok); assert.equal("publishers", config.publish_model); end); it("should not allow anyone to publish", function () @@ -304,6 +308,7 @@ describe("util.pubsub", function () end); it("should allow publishers to publish", function () assert(service:set_affiliation("test", true, "mypublisher", "publisher")); + -- luacheck: ignore 211/err local ok, err = service:publish("test", "mypublisher", "item1", "foo"); assert.is_true(ok); end); @@ -342,6 +347,7 @@ describe("util.pubsub", function () end); it("should allow publishers to publish without a subscription", function () assert(service:set_affiliation("test", true, "mypublisher", "publisher")); + -- luacheck: ignore 211/err local ok, err = service:publish("test", "mypublisher", "item1", "foo"); assert.is_true(ok); end); -- cgit v1.2.3 From d8c2888045cb5bd396bd17dc42fbaf2355688683 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 26 Dec 2019 01:52:14 +0100 Subject: util.pubsub: Cover subscription filter in a partial test I'm not sure I understand spies well enough to test that the arguments and return values are as expected. Better than nothing at least. --- spec/util_pubsub_spec.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'spec') diff --git a/spec/util_pubsub_spec.lua b/spec/util_pubsub_spec.lua index 75f893e3..23cdf2a0 100644 --- a/spec/util_pubsub_spec.lua +++ b/spec/util_pubsub_spec.lua @@ -483,4 +483,30 @@ describe("util.pubsub", function () end); + describe("subscriber filter", function () + it("works", function () + local filter = spy.new(function (subs) + return {["modified"] = true}; + end); + local broadcaster = spy.new(function (notif_type, node_name, subscribers, item) -- luacheck: ignore 212 + end); + local service = pubsub.new({ + subscriber_filter = filter; + broadcaster = broadcaster; + }); + + local ok = service:create("node", true); + assert.truthy(ok); + + local ok = service:add_subscription("node", true, "someone"); + assert.truthy(ok); + + local ok = service:publish("node", true, "1", "item"); + assert.truthy(ok); + -- TODO how to match table arguments? + assert.spy(filter).was_called(); + assert.spy(broadcaster).was_called(); + end); + end); + end); -- cgit v1.2.3 From 30d0c690a3eef472603c991a9e1d067c8a851f7d Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 29 Dec 2019 01:11:55 +0100 Subject: util.pubsub: Ignore unused argument in tests [luacheck] --- spec/util_pubsub_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/util_pubsub_spec.lua b/spec/util_pubsub_spec.lua index 23cdf2a0..f876089e 100644 --- a/spec/util_pubsub_spec.lua +++ b/spec/util_pubsub_spec.lua @@ -485,7 +485,7 @@ describe("util.pubsub", function () describe("subscriber filter", function () it("works", function () - local filter = spy.new(function (subs) + local filter = spy.new(function (subs) -- luacheck: ignore 212/subs return {["modified"] = true}; end); local broadcaster = spy.new(function (notif_type, node_name, subscribers, item) -- luacheck: ignore 212 -- cgit v1.2.3 From 0563faba739b930c600b52e13aca95101cdb8653 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 2 Jan 2020 13:17:03 +0100 Subject: net.websocket.frames: Add test case for masked data ASCI is pretty neat in how lower case alphabet XOR space is upper case --- spec/net_websocket_frames_spec.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'spec') diff --git a/spec/net_websocket_frames_spec.lua b/spec/net_websocket_frames_spec.lua index d4df3a54..6922d523 100644 --- a/spec/net_websocket_frames_spec.lua +++ b/spec/net_websocket_frames_spec.lua @@ -32,6 +32,17 @@ describe("net.websocket.frames", function () ["RSV2"] = false; ["RSV3"] = false; }; + masked_data = { + ["opcode"] = 0; + ["length"] = 5; + ["data"] = "hello"; + ["FIN"] = true; + ["MASK"] = true; + ["RSV1"] = false; + ["RSV2"] = false; + ["RSV3"] = false; + ["key"] = { 0x20, 0x20, 0x20, 0x20, }; + }; } describe("build", function () @@ -40,6 +51,7 @@ describe("net.websocket.frames", function () assert.equal("\0\0", build(test_frames.simple_empty)); assert.equal("\0\5hello", build(test_frames.simple_data)); assert.equal("\128\0", build(test_frames.simple_fin)); + assert.equal("\128\133 HELLO", build(test_frames.masked_data)); end); end); @@ -49,6 +61,7 @@ describe("net.websocket.frames", function () assert.same(test_frames.simple_empty, parse("\0\0")); assert.same(test_frames.simple_data, parse("\0\5hello")); assert.same(test_frames.simple_fin, parse("\128\0")); + assert.same(test_frames.masked_data, parse("\128\133 HELLO")); end); end); -- cgit v1.2.3 From cd9906cb2d3d5ec8801a5d2d5a832a3cb5009259 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 2 Jan 2020 13:17:43 +0100 Subject: net.websocket.frames: Add ping and pong test cases --- spec/net_websocket_frames_spec.lua | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'spec') diff --git a/spec/net_websocket_frames_spec.lua b/spec/net_websocket_frames_spec.lua index 6922d523..7eed73c9 100644 --- a/spec/net_websocket_frames_spec.lua +++ b/spec/net_websocket_frames_spec.lua @@ -43,6 +43,26 @@ describe("net.websocket.frames", function () ["RSV3"] = false; ["key"] = { 0x20, 0x20, 0x20, 0x20, }; }; + ping = { + ["opcode"] = 0x9; + ["length"] = 4; + ["data"] = "ping"; + ["FIN"] = true; + ["MASK"] = false; + ["RSV1"] = false; + ["RSV2"] = false; + ["RSV3"] = false; + }; + pong = { + ["opcode"] = 0xa; + ["length"] = 4; + ["data"] = "pong"; + ["FIN"] = true; + ["MASK"] = false; + ["RSV1"] = false; + ["RSV2"] = false; + ["RSV3"] = false; + }; } describe("build", function () @@ -52,6 +72,8 @@ describe("net.websocket.frames", function () assert.equal("\0\5hello", build(test_frames.simple_data)); assert.equal("\128\0", build(test_frames.simple_fin)); assert.equal("\128\133 HELLO", build(test_frames.masked_data)); + assert.equal("\137\4ping", build(test_frames.ping)); + assert.equal("\138\4pong", build(test_frames.pong)); end); end); @@ -62,6 +84,8 @@ describe("net.websocket.frames", function () assert.same(test_frames.simple_data, parse("\0\5hello")); assert.same(test_frames.simple_fin, parse("\128\0")); assert.same(test_frames.masked_data, parse("\128\133 HELLO")); + assert.same(test_frames.ping, parse("\137\4ping")); + assert.same(test_frames.pong, parse("\138\4pong")); end); end); -- cgit v1.2.3 From a0bb180c36219f617f01d42b4a49c5f38b839582 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 14 Jan 2020 23:39:47 +0100 Subject: util.array: Add a test case for a behavior change in Lua 5.3 In Lua 5.1 and 5.2 the __eq metamethod is not invoked if the other argument is of a different metatable, but in Lua 5.3 it is. --- spec/util_array_spec.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'spec') diff --git a/spec/util_array_spec.lua b/spec/util_array_spec.lua index 04d0cc28..1d9da947 100644 --- a/spec/util_array_spec.lua +++ b/spec/util_array_spec.lua @@ -43,6 +43,7 @@ describe("util.array", function () local b = array({ "c", "d" }); assert.truthy(a1 == a2); assert.falsy(a1 == b); + assert.falsy(a1 == { "a", "b" }, "Behavior of metatables changed in Lua 5.3"); end); end); -- cgit v1.2.3 From f38173be79e56e6033ab77f5af9d35603f540ddf Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 15 Jan 2020 21:14:06 +0100 Subject: util.json: Test util.array integration This is to expose how [] == json.null due to a change in Lua 5.3 with how the equality metamethod is chosen. --- spec/util_json_spec.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'spec') diff --git a/spec/util_json_spec.lua b/spec/util_json_spec.lua index 43360540..f07cd525 100644 --- a/spec/util_json_spec.lua +++ b/spec/util_json_spec.lua @@ -1,5 +1,6 @@ local json = require "util.json"; +local array = require "util.array"; describe("util.json", function() describe("#encode()", function() @@ -67,4 +68,13 @@ describe("util.json", function() end end); end) + + describe("util.array integration", function () + it("works", function () + assert.equal("[]", json.encode(array())); + assert.equal("[1,2,3]", json.encode(array({1,2,3}))); + assert.equal(getmetatable(array()), getmetatable(json.decode("[]"))); + end); + end); + end); -- cgit v1.2.3 From 98ab88a9fff327e8a1f76ad41da29a149ba014c8 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 26 Jan 2020 16:53:03 +0100 Subject: scansion tests: Remove daemonize option, not needed --- spec/scansion/prosody.cfg.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'spec') diff --git a/spec/scansion/prosody.cfg.lua b/spec/scansion/prosody.cfg.lua index 3f804c4e..6a72584d 100644 --- a/spec/scansion/prosody.cfg.lua +++ b/spec/scansion/prosody.cfg.lua @@ -80,7 +80,6 @@ mam_smart_enable = true -- For advanced logging see https://prosody.im/doc/logging log = "*console" -daemonize = true pidfile = "prosody.pid" VirtualHost "localhost" -- cgit v1.2.3 From 0bcbbed75359c7460463e6f33b81a74dcb1b801f Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 24 Feb 2020 01:24:25 +0100 Subject: util.jwt: Basic JSON Web Token library supporting HS256 tokens --- spec/util_jwt_spec.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 spec/util_jwt_spec.lua (limited to 'spec') diff --git a/spec/util_jwt_spec.lua b/spec/util_jwt_spec.lua new file mode 100644 index 00000000..5e688f7b --- /dev/null +++ b/spec/util_jwt_spec.lua @@ -0,0 +1,20 @@ +local jwt = require "util.jwt"; + +describe("util.jwt", function () + it("validates", function () + local key = "secret"; + local token = jwt.sign(key, { payload = "this" }); + assert.string(token); + local ok, parsed = jwt.verify(key, token); + assert.truthy(ok) + assert.same({ payload = "this" }, parsed); + end); + it("rejects invalid", function () + local key = "secret"; + local token = jwt.sign("wrong", { payload = "this" }); + assert.string(token); + local ok, err = jwt.verify(key, token); + assert.falsy(ok) + end); +end); + -- cgit v1.2.3 From d9c8eeb88981ca0a617e545674105b7b9b3ec4ae Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 24 Feb 2020 09:10:28 +0100 Subject: util.jwt: Remove unused return value from tests [luacheck] --- spec/util_jwt_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/util_jwt_spec.lua b/spec/util_jwt_spec.lua index 5e688f7b..b391a870 100644 --- a/spec/util_jwt_spec.lua +++ b/spec/util_jwt_spec.lua @@ -13,7 +13,7 @@ describe("util.jwt", function () local key = "secret"; local token = jwt.sign("wrong", { payload = "this" }); assert.string(token); - local ok, err = jwt.verify(key, token); + local ok = jwt.verify(key, token); assert.falsy(ok) end); end); -- cgit v1.2.3 From 1d5af5f0a385ffbe4c46569d8fd8696c8c989a60 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 11 Mar 2020 14:36:56 +0000 Subject: storagemanager: Add tests for map stores --- spec/core_storagemanager_spec.lua | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'spec') diff --git a/spec/core_storagemanager_spec.lua b/spec/core_storagemanager_spec.lua index c3534cd5..9ecb0cb4 100644 --- a/spec/core_storagemanager_spec.lua +++ b/spec/core_storagemanager_spec.lua @@ -90,6 +90,44 @@ describe("storagemanager", function () end); end); + describe("map stores", function () + -- These tests rely on being executed in order, disable any order + -- randomization for this block + randomize(false); + + local store, kv_store; + it("may be opened", function () + store = assert(sm.open(test_host, "test-map", "map")); + end); + + it("may be opened as a keyval store", function () + kv_store = assert(sm.open(test_host, "test-map", "keyval")); + end); + + it("may set a specific key for a user", function () + assert(store:set("user9999", "foo", "bar")); + assert.same(kv_store:get("user9999"), { foo = "bar" }); + end); + + it("may get a specific key for a user", function () + assert.equal("bar", store:get("user9999", "foo")); + end); + + it("may remove data for a user", function () + assert(store:set("user9999", "foo", nil)); + do + local ret, err = store:get("user9999", "foo"); + assert.is_nil(ret); + assert.is_nil(err); + end + do + local ret, err = kv_store:get("user9999"); + assert.is_nil(ret); + assert.is_nil(err); + end + end); + end); + describe("archive stores", function () randomize(false); -- cgit v1.2.3 From 33b9b2b91ec31f328dcd080832c3caf7a24cb93a Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 11 Mar 2020 15:57:53 +0000 Subject: mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests) --- spec/core_storagemanager_spec.lua | 74 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) (limited to 'spec') diff --git a/spec/core_storagemanager_spec.lua b/spec/core_storagemanager_spec.lua index 9ecb0cb4..69afd87a 100644 --- a/spec/core_storagemanager_spec.lua +++ b/spec/core_storagemanager_spec.lua @@ -62,6 +62,8 @@ describe("storagemanager", function () sm.initialize_host(test_host); assert(mm.load(test_host, "storage_"..backend_config.storage)); + local sql_it = backend_config.sql and it or pending; + describe("key-value stores", function () -- These tests rely on being executed in order, disable any order -- randomization for this block @@ -113,15 +115,83 @@ describe("storagemanager", function () assert.equal("bar", store:get("user9999", "foo")); end); - it("may remove data for a user", function () + sql_it("may find all users with a specific key", function () + assert.is_function(store.find_key); + assert(store:set("user9999b", "bar", "bar")); + assert(store:set("user9999c", "foo", "blah")); + local ret, err = store:find_key("foo"); + assert.is_nil(err); + assert.same({ user9999 = "bar", user9999c = "blah" }, ret); + end); + + sql_it("rejects empty or non-string keys to find_key", function () + assert.is_function(store.find_key); + do + local ret, err = store:find_key(""); + assert.is_nil(ret); + assert.is_not_nil(err); + end + do + local ret, err = store:find_key(true); + assert.is_nil(ret); + assert.is_not_nil(err); + end + end); + + sql_it("rejects empty or non-string keys to delete_key", function () + assert.is_function(store.delete_key); + do + local ret, err = store:delete_key(""); + assert.is_nil(ret); + assert.is_not_nil(err); + end + do + local ret, err = store:delete_key(true); + assert.is_nil(ret); + assert.is_not_nil(err); + end + end); + + sql_it("may delete all instances of a specific key", function () + assert.is_function(store.delete_key); + assert(store:set("user9999b", "foo", "hello")); + + local ret, err = store:delete_key("bar"); + -- Ensure key was deleted + do + local ret, err = store:get("user9999b", "bar"); + assert.is_nil(ret); + assert.is_nil(err); + end + -- Ensure other users/keys are intact + do + local ret, err = store:get("user9999", "foo"); + assert.equal("bar", ret); + assert.is_nil(err); + end + do + local ret, err = store:get("user9999b", "foo"); + assert.equal("hello", ret); + assert.is_nil(err); + end + do + local ret, err = store:get("user9999c", "foo"); + assert.equal("blah", ret); + assert.is_nil(err); + end + end); + + it("may remove data for a specific key for a user", function () assert(store:set("user9999", "foo", nil)); do local ret, err = store:get("user9999", "foo"); assert.is_nil(ret); assert.is_nil(err); end + + assert(store:set("user9999b", "foo", nil)); do - local ret, err = kv_store:get("user9999"); + local ret, err = store:get("user9999b", "foo"); assert.is_nil(ret); assert.is_nil(err); end -- cgit v1.2.3 From e35a4db4984013d82c90bd99fa1cbb15396fa415 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 11 Mar 2020 16:07:36 +0000 Subject: storagemanager: Fix unused variable in tests [luacheck] --- spec/core_storagemanager_spec.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/core_storagemanager_spec.lua b/spec/core_storagemanager_spec.lua index 69afd87a..dd80f4b8 100644 --- a/spec/core_storagemanager_spec.lua +++ b/spec/core_storagemanager_spec.lua @@ -64,6 +64,7 @@ describe("storagemanager", function () local sql_it = backend_config.sql and it or pending; + describe("key-value stores", function () -- These tests rely on being executed in order, disable any order -- randomization for this block @@ -156,7 +157,7 @@ describe("storagemanager", function () assert.is_function(store.delete_key); assert(store:set("user9999b", "foo", "hello")); - local ret, err = store:delete_key("bar"); + assert(store:delete_key("bar")); -- Ensure key was deleted do local ret, err = store:get("user9999b", "bar"); -- cgit v1.2.3 From 81f5c3e319792bec5d53c30334f3f54537aeb32b Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 11 Mar 2020 16:29:57 +0000 Subject: storagemanager: Add support for :find_key() and :delete_key() to map store shim --- spec/core_storagemanager_spec.lua | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'spec') diff --git a/spec/core_storagemanager_spec.lua b/spec/core_storagemanager_spec.lua index dd80f4b8..848f7910 100644 --- a/spec/core_storagemanager_spec.lua +++ b/spec/core_storagemanager_spec.lua @@ -62,9 +62,6 @@ describe("storagemanager", function () sm.initialize_host(test_host); assert(mm.load(test_host, "storage_"..backend_config.storage)); - local sql_it = backend_config.sql and it or pending; - - describe("key-value stores", function () -- These tests rely on being executed in order, disable any order -- randomization for this block @@ -116,7 +113,7 @@ describe("storagemanager", function () assert.equal("bar", store:get("user9999", "foo")); end); - sql_it("may find all users with a specific key", function () + it("may find all users with a specific key", function () assert.is_function(store.find_key); assert(store:set("user9999b", "bar", "bar")); assert(store:set("user9999c", "foo", "blah")); @@ -125,7 +122,7 @@ describe("storagemanager", function () assert.same({ user9999 = "bar", user9999c = "blah" }, ret); end); - sql_it("rejects empty or non-string keys to find_key", function () + it("rejects empty or non-string keys to find_key", function () assert.is_function(store.find_key); do local ret, err = store:find_key(""); @@ -139,7 +136,7 @@ describe("storagemanager", function () end end); - sql_it("rejects empty or non-string keys to delete_key", function () + it("rejects empty or non-string keys to delete_key", function () assert.is_function(store.delete_key); do local ret, err = store:delete_key(""); @@ -153,7 +150,7 @@ describe("storagemanager", function () end end); - sql_it("may delete all instances of a specific key", function () + it("may delete all instances of a specific key", function () assert.is_function(store.delete_key); assert(store:set("user9999b", "foo", "hello")); -- cgit v1.2.3 From cb6148d155ea02a68e40b8afb5861451750499ad Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 11 Mar 2020 16:32:41 +0000 Subject: storagemanager, mod_storage_sql: Rename methods to :get_all() and :delete_all() --- spec/core_storagemanager_spec.lua | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'spec') diff --git a/spec/core_storagemanager_spec.lua b/spec/core_storagemanager_spec.lua index 848f7910..b228c5fd 100644 --- a/spec/core_storagemanager_spec.lua +++ b/spec/core_storagemanager_spec.lua @@ -114,47 +114,47 @@ describe("storagemanager", function () end); it("may find all users with a specific key", function () - assert.is_function(store.find_key); + assert.is_function(store.get_all); assert(store:set("user9999b", "bar", "bar")); assert(store:set("user9999c", "foo", "blah")); - local ret, err = store:find_key("foo"); + local ret, err = store:get_all("foo"); assert.is_nil(err); assert.same({ user9999 = "bar", user9999c = "blah" }, ret); end); - it("rejects empty or non-string keys to find_key", function () - assert.is_function(store.find_key); + it("rejects empty or non-string keys to get_all", function () + assert.is_function(store.get_all); do - local ret, err = store:find_key(""); + local ret, err = store:get_all(""); assert.is_nil(ret); assert.is_not_nil(err); end do - local ret, err = store:find_key(true); + local ret, err = store:get_all(true); assert.is_nil(ret); assert.is_not_nil(err); end end); - it("rejects empty or non-string keys to delete_key", function () - assert.is_function(store.delete_key); + it("rejects empty or non-string keys to delete_all", function () + assert.is_function(store.delete_all); do - local ret, err = store:delete_key(""); + local ret, err = store:delete_all(""); assert.is_nil(ret); assert.is_not_nil(err); end do - local ret, err = store:delete_key(true); + local ret, err = store:delete_all(true); assert.is_nil(ret); assert.is_not_nil(err); end end); it("may delete all instances of a specific key", function () - assert.is_function(store.delete_key); + assert.is_function(store.delete_all); assert(store:set("user9999b", "foo", "hello")); - assert(store:delete_key("bar")); + assert(store:delete_all("bar")); -- Ensure key was deleted do local ret, err = store:get("user9999b", "bar"); -- cgit v1.2.3 From 64bb781dfec9b44618da58991aab292b1e360be1 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 12 Mar 2020 16:01:31 +0000 Subject: MUC: Support for broadcasting unavailable presence for affiliated offline users Activated when muc#roomconfig_presencebroadcast includes the "none" role. --- spec/scansion/muc_show_offline.scs | 544 +++++++++++++++++++++++++++++++++++++ 1 file changed, 544 insertions(+) create mode 100644 spec/scansion/muc_show_offline.scs (limited to 'spec') diff --git a/spec/scansion/muc_show_offline.scs b/spec/scansion/muc_show_offline.scs new file mode 100644 index 00000000..755a4774 --- /dev/null +++ b/spec/scansion/muc_show_offline.scs @@ -0,0 +1,544 @@ +# MUC: Room registration and presence broadcast of unavailable members + +[Client] Romeo + jid: user@localhost + password: password + +[Client] Juliet + jid: user2@localhost + password: password + +[Client] Rosaline + jid: user3@localhost + password: password + +----- + +Romeo connects + +Romeo sends: + + + + +Romeo receives: + + + + + + + + +Romeo receives: + + +# Submit config form +Romeo sends: + + + + + http://jabber.org/protocol/muc#roomconfig + + + none + participant + moderator + + + + + +Romeo receives: + + + +Romeo sends: + + + + + + +Romeo receives: + + + + + + +Romeo receives: + + +# Juliet connects, and joins the room +Juliet connects + +Juliet sends: + + + + +Juliet receives: + + +Juliet receives: + + +Juliet receives: + + +Romeo receives: + + +# Juliet retrieves the registration form + +Juliet sends: + + + + +Juliet receives: + + + + + http://jabber.org/protocol/muc#register + + + + + + + + +Juliet sends: + + + + + http://jabber.org/protocol/muc#register + + + Juliet + + + + + +Juliet receives: + + + + + + + +Juliet receives: + + +# Juliet discovers her reserved nick + +Juliet sends: + + + + +Juliet receives: + + + + + + +# Juliet leaves the room: + +Juliet sends: + + +Juliet receives: + + + + + + + +Romeo receives: + + + + + + +# Rosaline connect and tries to join the room as Juliet + +Rosaline connects + +Rosaline sends: + + + + +Rosaline receives: + + + + + + + +# In a heated moment, Juliet unregisters from the room + +Juliet sends: + + + + + + +Juliet receives: + + +# Romeo is notified of Juliet's sad decision + +Romeo receives: + + + + + + +# Rosaline attempts once more to sneak into the room, disguised as Juliet + +Rosaline sends: + + + + +Rosaline receives: + + + + + + +Rosaline receives: + + + + + + + +Romeo receives: + + + + + + +# On discovering the ruse, Romeo restores Juliet's nick and status within the room + +Romeo sends: + + + + + + +# Rosaline is evicted from the room + +Romeo receives: + + + + + This nickname is reserved + + + + +# An out-of-room affiliation change is received for Juliet + +Romeo receives: + + + + + + +Romeo receives: + + +Rosaline receives: + + + + + This nickname is reserved + + + + + +# Rosaline, frustrated, attempts to get back into the room... + +Rosaline sends: + + + + +# ...but once again, is denied + +Rosaline receives: + + + + + + + +# Juliet, however, quietly joins the room with success + +Juliet sends: + + + + +Juliet receives: + + +Juliet receives: + + +Juliet receives: + + +Romeo receives: + + +# Romeo checks whether he has reserved his own nick yet + +Romeo sends: + + + + +# But no nick is returned, as he hasn't registered yet! + +Romeo receives: + + + + +# Romeo updates his own registration + +Romeo sends: + + + + +Romeo receives: + + + + + http://jabber.org/protocol/muc#register + + + + + + + + +Romeo sends: + + + + + http://jabber.org/protocol/muc#register + + + Romeo + + + + + +Romeo receives: + + + + + + + +Romeo receives: + + +Juliet receives: + + + + + + +# Romeo discovers his reserved nick + +Romeo sends: + + + + +Romeo receives: + + + + + + +# To check the status of the room is as expected, Romeo requests the member list + +Romeo sends: + + + + + + +Romeo receives: + + + + + + +Juliet sends: + + +Juliet receives: + + +Romeo receives: + + +# Rosaline joins as herself + +Rosaline sends: + + + + +Rosaline receives: + + +Rosaline receives: + + + + + + +Rosaline receives: + + +Rosaline receives: + + +Romeo receives: + + + + + + +# Rosaline tries to register her own nickname, but unaffiliated +# registration is disabled by default + +Rosaline sends: + + + + +Rosaline receives: + + + + + + +Rosaline sends: + + + + + http://jabber.org/protocol/muc#register + + + Romeo + + + + + +Rosaline receives: + + + + + + +# Romeo reserves her nickname for her + +Romeo sends: + + + + + + +Romeo receives: + + + + + + + + +Romeo receives: + + +Rosaline receives: + + + + + + + + + +# Romeo sets their their own nickname via admin query (see #1273) +Romeo sends: + + + + + + +Romeo receives: + + + + + + + + + +Romeo receives: + + -- cgit v1.2.3 From 96f172c685a3073f9ac29560bc95620afb365b47 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 20 Mar 2020 18:52:41 +0100 Subject: MUC: Add test for destroying a room by ad-hoc command Testing ad-hoc commands was not easily doable before 49312378ba1d relaxed the need for state and an extra roundtrip to execute commands --- spec/scansion/muc_create_destroy.scs | 67 ++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'spec') diff --git a/spec/scansion/muc_create_destroy.scs b/spec/scansion/muc_create_destroy.scs index fea759a3..195200bb 100644 --- a/spec/scansion/muc_create_destroy.scs +++ b/spec/scansion/muc_create_destroy.scs @@ -8,6 +8,10 @@ jid: juliet@localhost/lVwkim_k password: password +[Client] Admin + jid: admin@localhost/DfNgg9VE + password: password + ----- Romeo connects @@ -245,6 +249,69 @@ Romeo receives: Juliet disconnects +Romeo sends: + + + + +Romeo receives: + + + + + + + + + + + +Romeo receives: + + + + +Romeo sends: + + + + + + +Romeo receives: + + +Admin connects + +Admin sends: + + + + + elsewhere@conference.localhost + + + + + +Romeo receives: + + + + + + + + Romeo disconnects +Admin receives: + + + The following rooms were destroyed: elsewhere@conference.localhost + + + +Admin disconnects + # recording ended on 2019-08-31T13:45:32Z -- cgit v1.2.3 From a4b069589cd555050a9a6e71b185e3a540f8c42d Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Fri, 10 Apr 2020 20:20:14 +0200 Subject: spec: Add test cases for util.http.contains_token --- spec/util_http_spec.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'spec') diff --git a/spec/util_http_spec.lua b/spec/util_http_spec.lua index d38645f7..c6087450 100644 --- a/spec/util_http_spec.lua +++ b/spec/util_http_spec.lua @@ -89,4 +89,23 @@ describe("util.http", function() assert.equal("/foo/", http.normalize_path("/foo/", true)); end); end); + + describe("contains_token", function () + it("is present in field", function () + assert.is_true(http.contains_token("foo", "foo")); + assert.is_true(http.contains_token("foo, bar", "foo")); + assert.is_true(http.contains_token("foo,bar", "foo")); + assert.is_true(http.contains_token("bar, foo,baz", "foo")); + end); + + it("is absent from field", function () + assert.is_false(http.contains_token("bar", "foo")); + assert.is_false(http.contains_token("fooo", "foo")); + assert.is_false(http.contains_token("foo o,bar", "foo")); + end); + + it("is weird", function () + assert.is_(http.contains_token("fo o", "foo")); + end); + end); end); -- cgit v1.2.3 From 1f92aa928062b406778e78ab9c1030b8d6be5bed Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 11 Apr 2020 17:59:39 +0200 Subject: spec: Include a hacky moduleapi stub to allow test to proceed --- spec/muc_util_spec.lua | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'spec') diff --git a/spec/muc_util_spec.lua b/spec/muc_util_spec.lua index cef68e80..3b2da4d0 100644 --- a/spec/muc_util_spec.lua +++ b/spec/muc_util_spec.lua @@ -3,11 +3,23 @@ local muc_util; local st = require "util.stanza"; do - local old_pp = package.path; - package.path = "./?.lib.lua;"..package.path; - muc_util = require "plugins.muc.util"; - package.path = old_pp; -end + -- XXX Hack for lack of a mock moduleapi + local env = setmetatable({ + module = { + _shared = {}; + -- Close enough to the real module:shared() for our purposes here + shared = function (self, name) + local t = self._shared[name]; + if t == nil then + t = {}; + self._shared[name] = t; + end + return t; + end; + } + }, { __index = _ENV or _G }); + muc_util = require "util.envload".envloadfile("plugins/muc/util.lib.lua", env)(); + end describe("muc/util", function () describe("filter_muc_x()", function () -- cgit v1.2.3 From f0ac29acf0d1d6cd947ac2e20dc6bcbbbddf76f6 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 12 Apr 2020 17:03:05 +0200 Subject: util.stanza: Add method returning stanza with added indentation Adds indentation and line breaks to stanzas, to make stanzas easier to read for humans. --- spec/util_stanza_spec.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'spec') diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua index d38a609f..efe3e47e 100644 --- a/spec/util_stanza_spec.lua +++ b/spec/util_stanza_spec.lua @@ -459,4 +459,12 @@ describe("util.stanza", function() assert.equal("true", s2.attr["my-awesome-ns\1bar"]); end); end); + + describe("indent", function () + local s = st.stanza("foo"):text("\n"):tag("bar"):tag("baz"):up():text_tag("cow", "moo"); + assert.equal("\n\t\n\t\t\n\t\tmoo\n\t\n", tostring(s:indent())); + assert.equal("\n \n \n moo\n \n", tostring(s:indent(1, " "))); + assert.equal("\n\t\t\n\t\t\t\n\t\t\tmoo\n\t\t\n\t", tostring(s:indent(2, "\t"))); + end); + end); -- cgit v1.2.3 From 9036462dcbb26ca029ee4d7709f4d8d2a377734c Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 20 Apr 2020 18:17:57 +0200 Subject: mod_version: Add scansion test Why was this module enabled in the config for tests if it wasn't tested? --- spec/scansion/prosody.cfg.lua | 2 ++ spec/scansion/version.scs | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 spec/scansion/version.scs (limited to 'spec') diff --git a/spec/scansion/prosody.cfg.lua b/spec/scansion/prosody.cfg.lua index 6a72584d..d7444e7a 100644 --- a/spec/scansion/prosody.cfg.lua +++ b/spec/scansion/prosody.cfg.lua @@ -84,6 +84,8 @@ pidfile = "prosody.pid" VirtualHost "localhost" +hide_os_type = true -- absense tested for in version.scs + Component "conference.localhost" "muc" storage = "memory" diff --git a/spec/scansion/version.scs b/spec/scansion/version.scs new file mode 100644 index 00000000..6c841dd9 --- /dev/null +++ b/spec/scansion/version.scs @@ -0,0 +1,27 @@ +# XEP-0092: Software Version / mod_version + +[Client] Romeo + password: password + jid: romeo@localhost/dfaZpuxV + +----- + +Romeo connects + +Romeo sends: + + + + +# Version string would vary so we can't do an exact match atm +# Inclusion of is disabled in the config, it should be absent +Romeo receives: + + + Prosody + + + + + +Romeo disconnects -- cgit v1.2.3 From 5955cc392426300b07c9cbfdb80371a14de6b729 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 20 Apr 2020 18:20:24 +0200 Subject: scansion: Mock time libraries during tests The passage of time does not need test coverage, just look in a mirror. --- spec/scansion/prosody.cfg.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'spec') diff --git a/spec/scansion/prosody.cfg.lua b/spec/scansion/prosody.cfg.lua index d7444e7a..88a5e0c9 100644 --- a/spec/scansion/prosody.cfg.lua +++ b/spec/scansion/prosody.cfg.lua @@ -1,5 +1,16 @@ --luacheck: ignore +-- Mock time functions to simplify tests +function _G.os.time() + return 1219439344; +end +package.preload["util.time"] = function () + return { + now = function () return 1219439344.1; end; + monotonic = function () return 0.1; end; + } +end + admins = { "admin@localhost" } use_libevent = true -- cgit v1.2.3 From 85b09097dc5367e4223595c7debbb92a401cfd12 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 20 Apr 2020 19:22:54 +0200 Subject: mod_uptime: Add scansion test coverage Once the Prosody is up, who cares when it comes down? That's not my department, says scanison. --- spec/scansion/uptime.scs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 spec/scansion/uptime.scs (limited to 'spec') diff --git a/spec/scansion/uptime.scs b/spec/scansion/uptime.scs new file mode 100644 index 00000000..188b9eb5 --- /dev/null +++ b/spec/scansion/uptime.scs @@ -0,0 +1,21 @@ +# XEP-0012: Last Activity / mod_uptime + +[Client] Romeo + jid: romeo@localhost + password: password + +----- + +Romeo connects + +Romeo sends: + + + + +Romeo receives: + + + + +Romeo disconnects -- cgit v1.2.3 From 8be4a3edd7de37c5c06beb3479ec6c84b510f95a Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 20 Apr 2020 18:33:05 +0200 Subject: mod_lastactivity: Add basic scansion test coverage When run on Lua 5.3 produces an issue similar to #1536 --- spec/scansion/lastactivity.scs | 45 ++++++++++++++++++++++++++++++++++++++++++ spec/scansion/prosody.cfg.lua | 1 + 2 files changed, 46 insertions(+) create mode 100644 spec/scansion/lastactivity.scs (limited to 'spec') diff --git a/spec/scansion/lastactivity.scs b/spec/scansion/lastactivity.scs new file mode 100644 index 00000000..44f4e516 --- /dev/null +++ b/spec/scansion/lastactivity.scs @@ -0,0 +1,45 @@ +# XEP-0012: Last Activity / mod_lastactivity + +[Client] Romeo + jid: romeo@localhost + password: password + +----- + +Romeo connects + +Romeo sends: + + Hello + + +Romeo receives: + + Hello + + +Romeo sends: + + Goodbye + + +Romeo receives: + + Goodbye + + +# mod_lastlog saves time + status message from the last unavailable presence + +Romeo sends: + + + + +Romeo receives: + + Goodbye + + +Romeo disconnects + +# recording ended on 2020-04-20T14:39:47Z diff --git a/spec/scansion/prosody.cfg.lua b/spec/scansion/prosody.cfg.lua index 88a5e0c9..b7d6ccd5 100644 --- a/spec/scansion/prosody.cfg.lua +++ b/spec/scansion/prosody.cfg.lua @@ -59,6 +59,7 @@ modules_enabled = { --"motd"; -- Send a message to users when they log in --"legacyauth"; -- Legacy authentication. Only used by some old clients and bots. --"proxy65"; -- Enables a file transfer proxy service which clients behind NAT can use + "lastactivity"; -- Useful for testing --"scansion_record"; -- Records things that happen in scansion test case format -- cgit v1.2.3 From 16c54b170580328dd57bb35a68281d5e385b82dc Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 22 Apr 2020 21:35:33 +0200 Subject: util.hashes: Use generic name of PBKDF2-HMAC-SHA1 function in tests --- spec/util_hashes_spec.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'spec') diff --git a/spec/util_hashes_spec.lua b/spec/util_hashes_spec.lua index 1e6187bb..5c616a8d 100644 --- a/spec/util_hashes_spec.lua +++ b/spec/util_hashes_spec.lua @@ -4,34 +4,34 @@ local hex = require "util.hex"; -- Also see spec for util.hmac where HMAC test cases reside -describe("PBKDF2-SHA1", function () +describe("PBKDF2-HMAC-SHA1", function () it("test vector 1", function () local P = "password" local S = "salt" local c = 1 local DK = "0c60c80f961f0e71f3a9b524af6012062fe037a6"; - assert.equal(DK, hex.to(hashes.scram_Hi_sha1(P, S, c))); + assert.equal(DK, hex.to(hashes.pbkdf2_hmac_sha1(P, S, c))); end); it("test vector 2", function () local P = "password" local S = "salt" local c = 2 local DK = "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957"; - assert.equal(DK, hex.to(hashes.scram_Hi_sha1(P, S, c))); + assert.equal(DK, hex.to(hashes.pbkdf2_hmac_sha1(P, S, c))); end); it("test vector 3", function () local P = "password" local S = "salt" local c = 4096 local DK = "4b007901b765489abead49d926f721d065a429c1"; - assert.equal(DK, hex.to(hashes.scram_Hi_sha1(P, S, c))); + assert.equal(DK, hex.to(hashes.pbkdf2_hmac_sha1(P, S, c))); end); it("test vector 4 #SLOW", function () local P = "password" local S = "salt" local c = 16777216 local DK = "eefe3d61cd4da4e4e9945b3d6ba2158c2634e984"; - assert.equal(DK, hex.to(hashes.scram_Hi_sha1(P, S, c))); + assert.equal(DK, hex.to(hashes.pbkdf2_hmac_sha1(P, S, c))); end); end); -- cgit v1.2.3 From 701c5f48110cb004925ba659b7221b18713ad2c7 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 22 Apr 2020 21:38:36 +0200 Subject: util.hashes: Fix output length of PBKDF2-HMAC-SHA256 Somehow it got SHA1's 20 byte output instead of the proper 32 = 256/8 --- spec/util_hashes_spec.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'spec') diff --git a/spec/util_hashes_spec.lua b/spec/util_hashes_spec.lua index 5c616a8d..3639dd4e 100644 --- a/spec/util_hashes_spec.lua +++ b/spec/util_hashes_spec.lua @@ -35,3 +35,21 @@ describe("PBKDF2-HMAC-SHA1", function () end); end); +describe("PBKDF2-HMAC-SHA256", function () + it("test vector 1", function () + local P = "password"; + local S = "salt"; + local c = 1 + local DK = "120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b"; + assert.equal(DK, hex.to(hashes.pbkdf2_hmac_sha256(P, S, c))); + end); + it("test vector 2", function () + local P = "password"; + local S = "salt"; + local c = 2 + local DK = "ae4d0c95af6b46d32d0adff928f06dd02a303f8ef3c251dfd6e2d85a95474c43"; + assert.equal(DK, hex.to(hashes.pbkdf2_hmac_sha256(P, S, c))); + end); +end); + + -- cgit v1.2.3 From 114ff031fcf2aa12596b80bd91dac1b30694b6b8 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 23 Apr 2020 15:17:42 +0100 Subject: MUC tests: Add missing 'affiliation' attribute --- spec/scansion/muc_show_offline.scs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/scansion/muc_show_offline.scs b/spec/scansion/muc_show_offline.scs index 755a4774..57b75ec7 100644 --- a/spec/scansion/muc_show_offline.scs +++ b/spec/scansion/muc_show_offline.scs @@ -205,7 +205,7 @@ Juliet receives: Romeo receives: - + -- cgit v1.2.3 From da2a13287ee51d1dc1e1db92c3972c72b5d40081 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 23 Apr 2020 18:05:00 +0200 Subject: util.rsm: Add tests Based on examples from XEP-0059 --- spec/util_rsm_spec.lua | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 spec/util_rsm_spec.lua (limited to 'spec') diff --git a/spec/util_rsm_spec.lua b/spec/util_rsm_spec.lua new file mode 100644 index 00000000..c8ddc47d --- /dev/null +++ b/spec/util_rsm_spec.lua @@ -0,0 +1,82 @@ +local rsm = require "util.rsm"; +local xml = require "util.xml"; + +local function strip(s) + return (s:gsub(">%s+<", "><")); +end + +describe("util.rsm", function () + describe("parse", function () + it("works", function () + local test = xml.parse(strip([[ + + 10 + + ]])); + assert.same({ max = 10 }, rsm.parse(test)); + end); + + it("works", function () + local test = xml.parse(strip([[ + + saint@example.org + peterpan@neverland.lit + 800 + + ]])); + assert.same({ first = { index = 0, "saint@example.org" }, last = "peterpan@neverland.lit", count = 800 }, rsm.parse(test)); + end); + + it("works", function () + local test = xml.parse(strip([[ + + 10 + peter@pixyland.org + + ]])); + assert.same({ max = 10, before = "peter@pixyland.org" }, rsm.parse(test)); + end); + + end); + + describe("generate", function () + it("works", function () + local test = xml.parse(strip([[ + + 10 + + ]])); + local res = rsm.generate({ max = 10 }); + assert.same(test:get_child_text("max"), res:get_child_text("max")); + end); + + it("works", function () + local test = xml.parse(strip([[ + + saint@example.org + peterpan@neverland.lit + 800 + + ]])); + local res = rsm.generate({ first = { index = 0, "saint@example.org" }, last = "peterpan@neverland.lit", count = 800 }); + assert.same(test:get_child("first").attr.index, res:get_child("first").attr.index); + assert.same(test:get_child_text("first"), res:get_child_text("first")); + assert.same(test:get_child_text("last"), res:get_child_text("last")); + assert.same(test:get_child_text("count"), res:get_child_text("count")); + end); + + it("works", function () + local test = xml.parse(strip([[ + + 10 + peter@pixyland.org + + ]])); + local res = rsm.generate({ max = 10, before = "peter@pixyland.org" }); + assert.same(test:get_child_text("max"), res:get_child_text("max")); + assert.same(test:get_child_text("before"), res:get_child_text("before")); + end); + + end); +end); + -- cgit v1.2.3 From 67372d19bdab286a5900494a0be694aacec7d9b6 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 23 Apr 2020 18:17:54 +0200 Subject: util.rsm: Test that Lua 5.3 floats are not encoded with decimal point The 'max' 'count' and 'index' fields are integers and should be encoded as such on the wire. Care needs to be taken because tostring(1.0) in Lua 5.3+ returns to "1.0" while in previous Lua versions it would return "1". --- spec/util_rsm_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'spec') diff --git a/spec/util_rsm_spec.lua b/spec/util_rsm_spec.lua index c8ddc47d..08fb1b02 100644 --- a/spec/util_rsm_spec.lua +++ b/spec/util_rsm_spec.lua @@ -77,6 +77,13 @@ describe("util.rsm", function () assert.same(test:get_child_text("before"), res:get_child_text("before")); end); + it("handles floats", function () + local r1 = rsm.generate({ max = 10.0, count = 100.0, first = { index = 1.0, "foo" } }); + assert.equal("10", r1:get_child_text("max")); + assert.equal("100", r1:get_child_text("count")); + assert.equal("1", r1:get_child("first").attr.index); + end); + end); end); -- cgit v1.2.3 From 6b456feb2939af36b454f8b53b0bda32f3aa7613 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 9 May 2020 00:07:42 +0200 Subject: spec/scansion/blocking: Don't send stanzas after disconnecting Probably casued by mod_scansion_record catching the unavailable presence generated by Prosody on disconnect. See #1549 --- spec/scansion/blocking.scs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'spec') diff --git a/spec/scansion/blocking.scs b/spec/scansion/blocking.scs index 6a9f199e..5bb5a41b 100644 --- a/spec/scansion/blocking.scs +++ b/spec/scansion/blocking.scs @@ -145,16 +145,16 @@ Juliet receives: # Bye -Juliet disconnects - Juliet sends: +Juliet disconnects + Romeo receives: -Romeo disconnects - Romeo sends: +Romeo disconnects + -- cgit v1.2.3 From 0cf5e523843ae039f2aa005995cd320d7fe2ff1f Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 11 May 2020 21:41:02 +0200 Subject: spec/storage: Reset build context of test stanza make comparisons easier While building a stanza there's a .last_add field keeping track of where in the XML tree tags are being added. This field does not survive a roundtrip through preserialize / deserialize. :reset() removes this, which simplifes comparisons after such a roundtrip. --- spec/core_storagemanager_spec.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/core_storagemanager_spec.lua b/spec/core_storagemanager_spec.lua index b228c5fd..29ab014f 100644 --- a/spec/core_storagemanager_spec.lua +++ b/spec/core_storagemanager_spec.lua @@ -206,7 +206,8 @@ describe("storagemanager", function () local test_stanza = st.stanza("test", { xmlns = "urn:example:foo" }) :tag("foo"):up() - :tag("foo"):up(); + :tag("foo"):up() + :reset(); local test_time = 1539204123; local test_data = { -- cgit v1.2.3 From 82714e54a8dca7ff60365758dd497c3c9c270633 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 11 May 2020 21:56:19 +0200 Subject: mod_storage_internal: Implement key-value API --- spec/core_storagemanager_spec.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'spec') diff --git a/spec/core_storagemanager_spec.lua b/spec/core_storagemanager_spec.lua index 29ab014f..96ccceb6 100644 --- a/spec/core_storagemanager_spec.lua +++ b/spec/core_storagemanager_spec.lua @@ -439,6 +439,21 @@ describe("storagemanager", function () assert.equal(2, count); assert(archive:delete("user-issue1073")); end); + + it("can be treated as a map store", function () + assert.falsy(archive:get("mapuser", "no-such-id")); + assert.falsy(archive:set("mapuser", "no-such-id", test_stanza)); + + local id = archive:append("mapuser", nil, test_stanza, test_time, "contact@example.com"); + assert.same(test_stanza, archive:get("mapuser", id)); + + local replacement_stanza = st.stanza("test", { xmlns = "urn:example:foo" }) + :tag("bar"):up() + :reset(); + assert(archive:set("mapuser", id, replacement_stanza)); + assert.same(replacement_stanza, archive:get("mapuser", id)); + end); + end); end); end -- cgit v1.2.3 From d916ce38f6b434552a5ebd2a1751286da9cf2d69 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 15 May 2020 20:55:22 +0200 Subject: mod_storage_internal: Fix keeping old timestamp in archive map API This led to a missing 'when' field on changed items, which would cause a traceack. --- spec/core_storagemanager_spec.lua | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'spec') diff --git a/spec/core_storagemanager_spec.lua b/spec/core_storagemanager_spec.lua index 96ccceb6..a19edbab 100644 --- a/spec/core_storagemanager_spec.lua +++ b/spec/core_storagemanager_spec.lua @@ -445,13 +445,24 @@ describe("storagemanager", function () assert.falsy(archive:set("mapuser", "no-such-id", test_stanza)); local id = archive:append("mapuser", nil, test_stanza, test_time, "contact@example.com"); - assert.same(test_stanza, archive:get("mapuser", id)); + do + local stanza_roundtrip, when, with = archive:get("mapuser", id); + assert.same(test_stanza, stanza_roundtrip, "same stanza is returned"); + assert.equal(test_time, when, "same 'when' is returned"); + assert.equal("contact@example.com", with, "same 'with' is returned"); + end local replacement_stanza = st.stanza("test", { xmlns = "urn:example:foo" }) :tag("bar"):up() :reset(); - assert(archive:set("mapuser", id, replacement_stanza)); - assert.same(replacement_stanza, archive:get("mapuser", id)); + assert(archive:set("mapuser", id, replacement_stanza, test_time+1)); + + do + local replaced, when, with = archive:get("mapuser", id); + assert.same(replacement_stanza, replaced, "replaced stanza is returned"); + assert.equal(test_time+1, when, "modified 'when' is returned"); + assert.equal("contact@example.com", with, "original 'with' is returned"); + end end); end); -- cgit v1.2.3 From 836be9b60d1e2b10ec4cdfb3e58281f18c0a31d0 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 27 May 2020 19:44:12 +0200 Subject: scansion: Add test for mod_server_contact_info / XEP-0157 --- spec/scansion/prosody.cfg.lua | 11 +++++++- spec/scansion/server_contact_info.scs | 53 +++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 spec/scansion/server_contact_info.scs (limited to 'spec') diff --git a/spec/scansion/prosody.cfg.lua b/spec/scansion/prosody.cfg.lua index b7d6ccd5..4cf03de8 100644 --- a/spec/scansion/prosody.cfg.lua +++ b/spec/scansion/prosody.cfg.lua @@ -52,7 +52,7 @@ modules_enabled = { -- Other specific functionality --"limits"; -- Enable bandwidth limiting for XMPP connections --"groups"; -- Shared roster support - --"server_contact_info"; -- Publish contact information for this service + "server_contact_info"; -- Publish contact information for this service --"announce"; -- Send announcement to all online users --"welcome"; -- Welcome users who register accounts --"watchregistrations"; -- Alert admins of registrations @@ -65,6 +65,15 @@ modules_enabled = { --"scansion_record"; -- Records things that happen in scansion test case format } +contact_info = { + abuse = { "mailto:abuse@localhost", "xmpp:abuse@localhost" }; + admin = { "mailto:admin@localhost", "xmpp:admin@localhost" }; + feedback = { "http://localhost/feedback.html", "mailto:feedback@localhost", "xmpp:feedback@localhost" }; + sales = { "xmpp:sales@localhost" }; + security = { "xmpp:security@localhost" }; + support = { "https://localhost/support.html", "xmpp:support@localhost" }; +} + modules_disabled = { "s2s"; } diff --git a/spec/scansion/server_contact_info.scs b/spec/scansion/server_contact_info.scs new file mode 100644 index 00000000..15537e11 --- /dev/null +++ b/spec/scansion/server_contact_info.scs @@ -0,0 +1,53 @@ +# XEP-0157: Contact Addresses for XMPP Services +# mod_server_contact_info + +[Client] Romeo + jid: romeo@localhost + password: password + +----- + +Romeo connects + +Romeo sends: + + + + +# Ignore other disco#info features, identities etc + +Romeo receives: + + + + + http://jabber.org/network/serverinfo + + + mailto:abuse@localhost + xmpp:abuse@localhost + + + mailto:admin@localhost + xmpp:admin@localhost + + + http://localhost/feedback.html + mailto:feedback@localhost + xmpp:feedback@localhost + + + xmpp:sales@localhost + + + xmpp:security@localhost + + + https://localhost/support.html + xmpp:support@localhost + + + + + +Romeo disconnects -- cgit v1.2.3 From 994f59501b9eecf736792d256434ceb7d519adc7 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 4 Jan 2019 08:46:26 +0100 Subject: util.human.units: A library for formatting numbers with SI units --- spec/util_human_units_spec.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 spec/util_human_units_spec.lua (limited to 'spec') diff --git a/spec/util_human_units_spec.lua b/spec/util_human_units_spec.lua new file mode 100644 index 00000000..4326cdd4 --- /dev/null +++ b/spec/util_human_units_spec.lua @@ -0,0 +1,15 @@ +local units = require "util.human.units"; + +describe("util.human.units", function () + describe("format", function () + it("formats numbers with SI units", function () + assert.equal("1 km", units.format(1000, "m")); + assert.equal("1 GJ", units.format(1000000000, "J")); + assert.equal("1 ms", units.format(1/1000, "s")); + assert.equal("10 ms", units.format(10/1000, "s")); + assert.equal("1 ns", units.format(1/1000000000, "s")); + assert.equal("1 KiB", units.format(1024, "B", 'b')); + assert.equal("1 MiB", units.format(1024*1024, "B", 'b')); + end); + end); +end); -- cgit v1.2.3 From 838f8ebd5bb26c2c96644af9e4f80ea7e150d976 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 29 May 2020 17:53:00 +0200 Subject: util.ringbuffer: Add some initial tests --- spec/util_ringbuffer_spec.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 spec/util_ringbuffer_spec.lua (limited to 'spec') diff --git a/spec/util_ringbuffer_spec.lua b/spec/util_ringbuffer_spec.lua new file mode 100644 index 00000000..5d63b24b --- /dev/null +++ b/spec/util_ringbuffer_spec.lua @@ -0,0 +1,17 @@ +local rb = require "util.ringbuffer"; +describe("util.ringbuffer", function () + describe("#new", function () + it("has a constructor", function () + assert.Function(rb.new); + end); + it("can be created", function () + assert.truthy(rb.new()); + end); + end); + describe(":write", function () + local b = rb.new(); + it("works", function () + assert.truthy(b:write("hi")); + end); + end); +end); -- cgit v1.2.3 From 0bb1474ce668f50c568e7751ac553cbf0acdba77 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 29 May 2020 18:11:42 +0200 Subject: util.ringbuffer: Prevent creation of zero-size buffer --- spec/util_ringbuffer_spec.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'spec') diff --git a/spec/util_ringbuffer_spec.lua b/spec/util_ringbuffer_spec.lua index 5d63b24b..ccb5493a 100644 --- a/spec/util_ringbuffer_spec.lua +++ b/spec/util_ringbuffer_spec.lua @@ -7,6 +7,11 @@ describe("util.ringbuffer", function () it("can be created", function () assert.truthy(rb.new()); end); + it("won't create an empty buffer", function () + assert.has_error(function () + rb.new(0); + end); + end); end); describe(":write", function () local b = rb.new(); -- cgit v1.2.3 From 4bab7af07d4707eda9246156e20610d95967679c Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 4 Jun 2020 16:11:08 +0200 Subject: util.ringbuffer: Prevent creation of buffer with negative size Previously this would have been (unsigned)-1 which is a large positive integer. --- spec/util_ringbuffer_spec.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'spec') diff --git a/spec/util_ringbuffer_spec.lua b/spec/util_ringbuffer_spec.lua index ccb5493a..9512bfd4 100644 --- a/spec/util_ringbuffer_spec.lua +++ b/spec/util_ringbuffer_spec.lua @@ -12,6 +12,11 @@ describe("util.ringbuffer", function () rb.new(0); end); end); + it("won't create a negatively sized buffer", function () + assert.has_error(function () + rb.new(-1); + end); + end); end); describe(":write", function () local b = rb.new(); -- cgit v1.2.3 From 14a436817d5faaa1942abb6263a43ca3847f5c5c Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 4 Jun 2020 15:19:20 +0100 Subject: util.ringbuffer: Add :sub() and :byte() methods equivalent to the string methods --- spec/util_ringbuffer_spec.lua | 58 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'spec') diff --git a/spec/util_ringbuffer_spec.lua b/spec/util_ringbuffer_spec.lua index 9512bfd4..72656899 100644 --- a/spec/util_ringbuffer_spec.lua +++ b/spec/util_ringbuffer_spec.lua @@ -24,4 +24,62 @@ describe("util.ringbuffer", function () assert.truthy(b:write("hi")); end); end); + describe(":sub", function () + -- Helper function to compare buffer:sub() with string:sub() + local function test_sub(b, x, y) + local s = b:read(#b, true); + local string_result, buffer_result = s:sub(x, y), b:sub(x, y); + assert.equals(string_result, buffer_result, ("buffer:sub(%d, %s) does not match string:sub()"):format(x, y and ("%d"):format(y) or "nil")); + end + + it("works", function () + local b = rb.new(); + b:write("hello world"); + assert.equals("hello", b:sub(1, 5)); + end); + + it("supports optional end parameter", function () + local b = rb.new(); + b:write("hello world"); + assert.equals("hello world", b:sub(1)); + assert.equals("world", b:sub(-5)); + end); + + it("is equivalent to string:sub", function () + local b = rb.new(6); + b:write("foobar"); + b:read(3); + b:write("foo"); + for i = -13, 13 do + for j = -13, 13 do + test_sub(b, i, j); + end + end + end); + end); + + describe(":byte", function () + -- Helper function to compare buffer:byte() with string:byte() + local function test_byte(b, x, y) + local s = b:read(#b, true); + local string_result, buffer_result = {s:byte(x, y)}, {b:byte(x, y)}; + assert.same(string_result, buffer_result, ("buffer:byte(%d, %s) does not match string:byte()"):format(x, y and ("%d"):format(y) or "nil")); + end + + it("is equivalent to string:byte", function () + local b = rb.new(6); + b:write("foobar"); + b:read(3); + b:write("foo"); + test_byte(b, 1); + test_byte(b, 3); + test_byte(b, -1); + test_byte(b, -3); + for i = -13, 13 do + for j = -13, 13 do + test_byte(b, i, j); + end + end + end); + end); end); -- cgit v1.2.3 From 4a0cb5a30643224dd6a9ebd91e53e257badaf7f9 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 6 Jun 2020 16:43:28 +0200 Subject: util.human.io: Fix right-alignment --- spec/scansion/prosody.cfg.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'spec') diff --git a/spec/scansion/prosody.cfg.lua b/spec/scansion/prosody.cfg.lua index 4cf03de8..3fa36ab9 100644 --- a/spec/scansion/prosody.cfg.lua +++ b/spec/scansion/prosody.cfg.lua @@ -13,7 +13,9 @@ end admins = { "admin@localhost" } -use_libevent = true +network_backend = "epoll" +network_settings = { +} modules_enabled = { -- Generally required @@ -99,7 +101,7 @@ mam_smart_enable = true -- Logging configuration -- For advanced logging see https://prosody.im/doc/logging -log = "*console" +log = {debug = "*console" } pidfile = "prosody.pid" -- cgit v1.2.3 From 9e0186b0ed9b0005807b5d383faf8626fdf36168 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 8 Jun 2020 14:01:02 +0100 Subject: util.promise: Add all_settled, which follows semantics of allSettled from ES2020 --- spec/util_promise_spec.lua | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'spec') diff --git a/spec/util_promise_spec.lua b/spec/util_promise_spec.lua index 0008c6a2..6fb5d6bd 100644 --- a/spec/util_promise_spec.lua +++ b/spec/util_promise_spec.lua @@ -353,6 +353,60 @@ describe("util.promise", function () assert.equal("fail", result); end); end); + describe("all_settled()", function () + it("works with fulfilled promises", function () + local p1, p2 = promise.resolve("yep"), promise.resolve("nope"); + local p = promise.all_settled({ p1, p2 }); + local result; + p:next(function (v) + result = v; + end); + assert.same({ + { status = "fulfilled", value = "yep" }; + { status = "fulfilled", value = "nope" }; + }, result); + end); + it("works with pending promises", function () + local r1, r2; + local p1, p2 = promise.new(function (resolve) r1 = resolve end), promise.new(function (resolve) r2 = resolve end); + local p = promise.all_settled({ p1, p2 }); + + local result; + local cb = spy.new(function (v) + result = v; + end); + p:next(cb); + assert.spy(cb).was_called(0); + r2("yep"); + assert.spy(cb).was_called(0); + r1("nope"); + assert.spy(cb).was_called(1); + assert.same({ + { status = "fulfilled", value = "nope" }; + { status = "fulfilled", value = "yep" }; + }, result); + end); + it("works when some promises reject", function () + local r1, r2; + local p1, p2 = promise.new(function (resolve) r1 = resolve end), promise.new(function (_, reject) r2 = reject end); + local p = promise.all_settled({ p1, p2 }); + + local result; + local cb = spy.new(function (v) + result = v; + end); + p:next(cb); + assert.spy(cb).was_called(0); + r2("this fails"); + assert.spy(cb).was_called(0); + r1("this succeeds"); + assert.spy(cb).was_called(1); + assert.same({ + { status = "fulfilled", value = "this succeeds" }; + { status = "rejected", reason = "this fails" }; + }, result); + end); + end); describe("catch()", function () it("works", function () local result; -- cgit v1.2.3 From f2dbf366426578b2ba233168f8e09cbca0ceec59 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 12 Jun 2020 16:59:06 +0100 Subject: storage tests: Add tests for archive queries before/after specific ids Also increased the size of the test data for easier debugging with more complex tests. --- spec/core_storagemanager_spec.lua | 52 +++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 5 deletions(-) (limited to 'spec') diff --git a/spec/core_storagemanager_spec.lua b/spec/core_storagemanager_spec.lua index a19edbab..d07dc4ec 100644 --- a/spec/core_storagemanager_spec.lua +++ b/spec/core_storagemanager_spec.lua @@ -215,12 +215,16 @@ describe("storagemanager", function () { nil, test_stanza, test_time+1, "contact2@example.com" }; { nil, test_stanza, test_time+2, "contact2@example.com" }; { nil, test_stanza, test_time-1, "contact2@example.com" }; + { nil, test_stanza, test_time-1, "contact3@example.com" }; + { nil, test_stanza, test_time+0, "contact3@example.com" }; + { nil, test_stanza, test_time+1, "contact3@example.com" }; }; it("can be added to", function () for _, data_item in ipairs(test_data) do - local ok = archive:append("user", unpack(data_item, 1, 4)); - assert.truthy(ok); + local id = archive:append("user", unpack(data_item, 1, 4)); + assert.truthy(id); + data_item[1] = id; end end); @@ -277,7 +281,7 @@ describe("storagemanager", function () assert.equal(2, #item.tags); assert(test_time >= when); end - assert.equal(2, count); + assert.equal(4, count); end); it("by time (start)", function () @@ -296,7 +300,7 @@ describe("storagemanager", function () assert.equal(2, #item.tags); assert(test_time <= when); end - assert.equal(#test_data -1, count); + assert.equal(#test_data - 2, count); end); it("by time (start+end)", function () @@ -317,7 +321,45 @@ describe("storagemanager", function () assert(when >= test_time, ("%d >= %d"):format(when, test_time)); assert(when <= test_time+1, ("%d <= %d"):format(when, test_time+1)); end - assert.equal(2, count); + assert.equal(4, count); + end); + + it("by id (after)", function () + -- luacheck: ignore 211/err + local data, err = archive:find("user", { + ["after"] = test_data[2][1]; + }); + assert.truthy(data); + local count = 0; + for id, item in data do + count = count + 1; + assert.truthy(id); + assert.equal(test_data[2+count][1], id); + assert(st.is_stanza(item)); + assert.equal("test", item.name); + assert.equal("urn:example:foo", item.attr.xmlns); + assert.equal(2, #item.tags); + end + assert.equal(5, count); + end); + + it("by id (before)", function () + -- luacheck: ignore 211/err + local data, err = archive:find("user", { + ["before"] = test_data[4][1]; + }); + assert.truthy(data); + local count = 0; + for id, item in data do + count = count + 1; + assert.truthy(id); + assert.equal(test_data[count][1], id); + assert(st.is_stanza(item)); + assert.equal("test", item.name); + assert.equal("urn:example:foo", item.attr.xmlns); + assert.equal(2, #item.tags); + end + assert.equal(3, count); end); end); -- cgit v1.2.3 From 44803031d0b89fad13326770f8f245e2b0c5906e Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 21 Jun 2020 19:06:37 +0200 Subject: MUC: Remove XEP-0091 Legacy Delayed Delivery from test Long time Obsolete XEP. The element is apparently not included when mod_muc_mam is enabled, and deleting this seems like the sanity-preserving approach. --- spec/scansion/muc_create_destroy.scs | 1 - 1 file changed, 1 deletion(-) (limited to 'spec') diff --git a/spec/scansion/muc_create_destroy.scs b/spec/scansion/muc_create_destroy.scs index 195200bb..789d4c41 100644 --- a/spec/scansion/muc_create_destroy.scs +++ b/spec/scansion/muc_create_destroy.scs @@ -90,7 +90,6 @@ Juliet receives: Where are thou my Juliet? - Juliet receives: -- cgit v1.2.3 From 93400f60fb40d8bf1b32977b76446d2e6fc78049 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 21 Jun 2020 19:09:47 +0200 Subject: scansion tests: Enable mod_muc_mam during tests (expect breakage) --- spec/scansion/prosody.cfg.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'spec') diff --git a/spec/scansion/prosody.cfg.lua b/spec/scansion/prosody.cfg.lua index 3fa36ab9..e75bb74f 100644 --- a/spec/scansion/prosody.cfg.lua +++ b/spec/scansion/prosody.cfg.lua @@ -111,6 +111,10 @@ hide_os_type = true -- absense tested for in version.scs Component "conference.localhost" "muc" storage = "memory" + modules_enabled = { + "muc_mam"; + } + Component "pubsub.localhost" "pubsub" storage = "memory" -- cgit v1.2.3 From dd0274b8c7499ceac91696cfcfb8e0b799bf0f52 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 23 Jun 2020 16:50:26 +0100 Subject: util.ringbuffer: Add test for :discard() --- spec/util_ringbuffer_spec.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'spec') diff --git a/spec/util_ringbuffer_spec.lua b/spec/util_ringbuffer_spec.lua index 72656899..9a50fd20 100644 --- a/spec/util_ringbuffer_spec.lua +++ b/spec/util_ringbuffer_spec.lua @@ -24,6 +24,17 @@ describe("util.ringbuffer", function () assert.truthy(b:write("hi")); end); end); + + describe(":discard", function () + local b = rb.new(); + it("works", function () + assert.truthy(b:write("hello world")); + assert.truthy(b:discard(6)); + assert.equal(5, #b); + assert.equal("world", b:read(5)); + end); + end); + describe(":sub", function () -- Helper function to compare buffer:sub() with string:sub() local function test_sub(b, x, y) -- cgit v1.2.3 From b9a670dace9252eaaf3de5871e5a1c6d355989fb Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 24 Jun 2020 12:34:20 +0100 Subject: util.ringbuffer: Ensure unsigned chars are always returned from :byte() --- spec/util_ringbuffer_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'spec') diff --git a/spec/util_ringbuffer_spec.lua b/spec/util_ringbuffer_spec.lua index 9a50fd20..5657b3f6 100644 --- a/spec/util_ringbuffer_spec.lua +++ b/spec/util_ringbuffer_spec.lua @@ -92,5 +92,12 @@ describe("util.ringbuffer", function () end end end); + + it("works with characters > 127", function () + local b = rb.new(); + b:write(string.char(0, 140)); + local r = { b:byte(1, 2) }; + assert.same({ 0, 140 }, r); + end); end); end); -- cgit v1.2.3 From f3add85e3c05049f24a498fd28783cff54f25b3b Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 24 Jun 2020 13:00:11 +0100 Subject: util.ringbuffer: Add some additional asserts to tests --- spec/util_ringbuffer_spec.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'spec') diff --git a/spec/util_ringbuffer_spec.lua b/spec/util_ringbuffer_spec.lua index 5657b3f6..3c052937 100644 --- a/spec/util_ringbuffer_spec.lua +++ b/spec/util_ringbuffer_spec.lua @@ -45,20 +45,20 @@ describe("util.ringbuffer", function () it("works", function () local b = rb.new(); - b:write("hello world"); + assert.truthy(b:write("hello world")); assert.equals("hello", b:sub(1, 5)); end); it("supports optional end parameter", function () local b = rb.new(); - b:write("hello world"); + assert.truthy(b:write("hello world")); assert.equals("hello world", b:sub(1)); assert.equals("world", b:sub(-5)); end); it("is equivalent to string:sub", function () local b = rb.new(6); - b:write("foobar"); + assert.truthy(b:write("foobar")); b:read(3); b:write("foo"); for i = -13, 13 do @@ -79,7 +79,7 @@ describe("util.ringbuffer", function () it("is equivalent to string:byte", function () local b = rb.new(6); - b:write("foobar"); + assert.truthy(b:write("foo"..string.char(0, 140).."obar")); b:read(3); b:write("foo"); test_byte(b, 1); -- cgit v1.2.3 From 558a365575c4ac2d601c19fcbd2bd6fd27078ac6 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 25 Jun 2020 15:45:13 +0100 Subject: util.ringbuffer: Fix accidentally committed test change (thanks buildbot) --- spec/util_ringbuffer_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/util_ringbuffer_spec.lua b/spec/util_ringbuffer_spec.lua index 3c052937..633885a8 100644 --- a/spec/util_ringbuffer_spec.lua +++ b/spec/util_ringbuffer_spec.lua @@ -79,7 +79,7 @@ describe("util.ringbuffer", function () it("is equivalent to string:byte", function () local b = rb.new(6); - assert.truthy(b:write("foo"..string.char(0, 140).."obar")); + assert.truthy(b:write("foobar")); b:read(3); b:write("foo"); test_byte(b, 1); -- cgit v1.2.3 From fb8e10737dfe14aaaa5fbc0295044f1f57dc9ad0 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 26 Jun 2020 16:41:31 +0100 Subject: util.dbuffer: dynamic string buffer Similar to util.ringbuffer (and shares almost identical API). Differences: - size limit is optional and dynamic - does not allocate a fixed buffer of max_size bytes - focus on simply storing references to existing string objects where possible, avoiding unnecessary allocations - references are still stored in a ring buffer to enable use as a fast FIFO Optional second parameter to new() provides the number of ring buffer segments. On Lua 5.2 on my laptop, a segment is ~19 bytes. If the ring buffer fills up, the next write will compact all strings into a single item. --- spec/util_dbuffer_spec.lua | 95 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 spec/util_dbuffer_spec.lua (limited to 'spec') diff --git a/spec/util_dbuffer_spec.lua b/spec/util_dbuffer_spec.lua new file mode 100644 index 00000000..854f3125 --- /dev/null +++ b/spec/util_dbuffer_spec.lua @@ -0,0 +1,95 @@ +local dbuffer = require "util.dbuffer"; +describe("util.dbuffer", function () + describe("#new", function () + it("has a constructor", function () + assert.Function(dbuffer.new); + end); + it("can be created", function () + assert.truthy(dbuffer.new()); + end); + it("won't create an empty buffer", function () + assert.falsy(dbuffer.new(0)); + end); + it("won't create a negatively sized buffer", function () + assert.falsy(dbuffer.new(-1)); + end); + end); + describe(":write", function () + local b = dbuffer.new(); + it("works", function () + assert.truthy(b:write("hi")); + end); + end); + + describe(":discard", function () + local b = dbuffer.new(); + it("works", function () + assert.truthy(b:write("hello world")); + assert.truthy(b:discard(6)); + assert.equal(5, #b); + assert.equal("world", b:read(5)); + end); + end); + + describe(":sub", function () + -- Helper function to compare buffer:sub() with string:sub() + local s = "hello world"; + local function test_sub(b, x, y) + local string_result, buffer_result = s:sub(x, y), b:sub(x, y); + assert.equals(string_result, buffer_result, ("buffer:sub(%d, %s) does not match string:sub()"):format(x, y and ("%d"):format(y) or "nil")); + end + + it("works", function () + local b = dbuffer.new(); + assert.truthy(b:write("hello world")); + assert.equals("hello", b:sub(1, 5)); + end); + + it("supports optional end parameter", function () + local b = dbuffer.new(); + assert.truthy(b:write("hello world")); + assert.equals("hello world", b:sub(1)); + assert.equals("world", b:sub(-5)); + end); + + it("is equivalent to string:sub", function () + local b = dbuffer.new(11); + assert.truthy(b:write(s)); + for i = -13, 13 do + for j = -13, 13 do + test_sub(b, i, j); + end + end + end); + end); + + describe(":byte", function () + -- Helper function to compare buffer:byte() with string:byte() + local s = "hello world" + local function test_byte(b, x, y) + local string_result, buffer_result = {s:byte(x, y)}, {b:byte(x, y)}; + assert.same(string_result, buffer_result, ("buffer:byte(%d, %s) does not match string:byte()"):format(x, y and ("%d"):format(y) or "nil")); + end + + it("is equivalent to string:byte", function () + local b = dbuffer.new(11); + assert.truthy(b:write(s)); + test_byte(b, 1); + test_byte(b, 3); + test_byte(b, -1); + test_byte(b, -3); + for i = -13, 13 do + for j = -13, 13 do + test_byte(b, i, j); + end + end + end); + + it("works with characters > 127", function () + local b = dbuffer.new(); + b:write(string.char(0, 140)); + local r = { b:byte(1, 2) }; + assert.same({ 0, 140 }, r); + end); + end); +end); -- cgit v1.2.3 From 8cc0b83179bde14826b91dd7e3c8ad986446923d Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 28 Jun 2020 12:26:04 +0100 Subject: util.dbuffer: Don't use # operator in tests, Lua 5.1 doesn't support __len --- spec/util_dbuffer_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/util_dbuffer_spec.lua b/spec/util_dbuffer_spec.lua index 854f3125..1a0c2992 100644 --- a/spec/util_dbuffer_spec.lua +++ b/spec/util_dbuffer_spec.lua @@ -26,7 +26,7 @@ describe("util.dbuffer", function () it("works", function () assert.truthy(b:write("hello world")); assert.truthy(b:discard(6)); - assert.equal(5, #b); + assert.equal(5, b:length()); assert.equal("world", b:read(5)); end); end); -- cgit v1.2.3 From c2ba37df93033723e3dd10de2f8e8676bb68d27f Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 28 Jun 2020 14:58:32 +0200 Subject: util.human.io: Add brief test of table generation --- spec/util_human_io_spec.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 spec/util_human_io_spec.lua (limited to 'spec') diff --git a/spec/util_human_io_spec.lua b/spec/util_human_io_spec.lua new file mode 100644 index 00000000..ead117df --- /dev/null +++ b/spec/util_human_io_spec.lua @@ -0,0 +1,29 @@ +describe("util.human.io", function () + local human_io + setup(function () + human_io = require "util.human.io"; + end); + describe("table", function () + + it("alignment works", function () + local row = human_io.table({ + { + width = 3, + align = "right" + }, + { + width = 3, + }, + }); + + assert.equal(" 1 | . ", row({ 1, "." })); + assert.equal(" 10 | .. ", row({ 10, ".." })); + assert.equal("100 | ...", row({ 100, "..." })); + assert.equal("10… | ..…", row({ 1000, "...." })); + + end); + end); +end); + + + -- cgit v1.2.3 From 67cf276ba2e23710c9ab2abd7e2f7b377aab1070 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 29 Jun 2020 12:51:28 +0100 Subject: util.dbuffer: If no bytes parameter passed to read, return remainder of frontmost chunk --- spec/util_dbuffer_spec.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'spec') diff --git a/spec/util_dbuffer_spec.lua b/spec/util_dbuffer_spec.lua index 1a0c2992..c4fa22b2 100644 --- a/spec/util_dbuffer_spec.lua +++ b/spec/util_dbuffer_spec.lua @@ -21,6 +21,21 @@ describe("util.dbuffer", function () end); end); + describe(":read", function () + it("supports optional bytes parameter", function () + -- should return the frontmost chunk + local b = dbuffer.new(); + assert.truthy(b:write("hello")); + assert.truthy(b:write(" ")); + assert.truthy(b:write("world")); + assert.equal("h", b:read(1)); + + assert.equal("ello", b:read()); + assert.equal(" ", b:read()); + assert.equal("world", b:read()); + end); + end); + describe(":discard", function () local b = dbuffer.new(); it("works", function () -- cgit v1.2.3 From 14cdec45c594346fe87eb9a5f76e08f3924aba48 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 8 Jul 2020 21:39:10 +0200 Subject: util.indexedbheap: Add failing test case for #1572 This approximates what happens if you add a timer far in the future, then reschedule it to right now. --- spec/util_indexedbheap_spec.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 spec/util_indexedbheap_spec.lua (limited to 'spec') diff --git a/spec/util_indexedbheap_spec.lua b/spec/util_indexedbheap_spec.lua new file mode 100644 index 00000000..a76f94cb --- /dev/null +++ b/spec/util_indexedbheap_spec.lua @@ -0,0 +1,15 @@ +local ibh = require"util.indexedbheap"; +local h +setup(function () + h = ibh.create(); +end) +describe("util.indexedbheap", function () + pending("item can be moved from end to top", function () + h:insert("a", 1); + h:insert("b", 2); + h:insert("c", 3); + local id = h:insert("*", 10); + h:reprioritize(id, 0); + assert.same({ 0, "*", id }, { h:pop() }); + end) +end); -- cgit v1.2.3 From b15a51597b6aa5a93b467c75d19ea7e0172561bf Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 9 Jul 2020 02:17:49 +0200 Subject: scansion/prosody.cfg: Fix typo --- spec/scansion/prosody.cfg.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/scansion/prosody.cfg.lua b/spec/scansion/prosody.cfg.lua index e75bb74f..c3f56108 100644 --- a/spec/scansion/prosody.cfg.lua +++ b/spec/scansion/prosody.cfg.lua @@ -107,7 +107,7 @@ pidfile = "prosody.pid" VirtualHost "localhost" -hide_os_type = true -- absense tested for in version.scs +hide_os_type = true -- absence tested for in version.scs Component "conference.localhost" "muc" storage = "memory" -- cgit v1.2.3 From 1c0950bc362d76da12c33ea7e0f87545556c2a82 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 27 May 2020 19:47:52 +0200 Subject: mod_server_contact_info: Add status-addresses field XEP-0157 version 1.1.0 --- spec/scansion/prosody.cfg.lua | 1 + spec/scansion/server_contact_info.scs | 3 +++ 2 files changed, 4 insertions(+) (limited to 'spec') diff --git a/spec/scansion/prosody.cfg.lua b/spec/scansion/prosody.cfg.lua index c3f56108..0bf68ddb 100644 --- a/spec/scansion/prosody.cfg.lua +++ b/spec/scansion/prosody.cfg.lua @@ -73,6 +73,7 @@ contact_info = { feedback = { "http://localhost/feedback.html", "mailto:feedback@localhost", "xmpp:feedback@localhost" }; sales = { "xmpp:sales@localhost" }; security = { "xmpp:security@localhost" }; + status = { "gopher://status.localhost" }; support = { "https://localhost/support.html", "xmpp:support@localhost" }; } diff --git a/spec/scansion/server_contact_info.scs b/spec/scansion/server_contact_info.scs index 15537e11..6efc7fd1 100644 --- a/spec/scansion/server_contact_info.scs +++ b/spec/scansion/server_contact_info.scs @@ -42,6 +42,9 @@ Romeo receives: xmpp:security@localhost + + gopher://status.localhost + https://localhost/support.html xmpp:support@localhost -- cgit v1.2.3 From 91d2ab91086d2aebcbc4d47a5bce05c6cd3abdcb Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 1 Aug 2020 18:41:23 +0200 Subject: net.http.parser: Allow specifying sink for large request bodies This enables uses such as saving uploaded files directly to a file on disk or streaming parsing of payloads. See #726 --- spec/net_http_parser_spec.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'spec') diff --git a/spec/net_http_parser_spec.lua b/spec/net_http_parser_spec.lua index 8310a451..4ac3cab9 100644 --- a/spec/net_http_parser_spec.lua +++ b/spec/net_http_parser_spec.lua @@ -3,7 +3,9 @@ local http_parser = require "net.http.parser"; local function test_stream(stream, expect) local success_cb = spy.new(function (packet) assert.is_table(packet); - assert.is_equal(expect.body, packet.body); + if packet.body ~= false then + assert.is_equal(expect.body, packet.body); + end end); stream = stream:gsub("\n", "\r\n"); @@ -79,7 +81,7 @@ o ]], { - body = "Hello", count = 1; + body = "Hello", count = 2; } ); end); @@ -108,7 +110,7 @@ o ]], { - body = "Hello", count = 2; + body = "Hello", count = 3; } ); end); -- cgit v1.2.3 From 1c0e4300ab36e37cb2ba83e5dca9f9247785bed6 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 16 Aug 2020 12:55:55 +0200 Subject: util.dataforms: Convert media element sizes to avoid error on Lua 5.3 The stanza API does not accept number values and threw an error due to the height and width attributes of the media element (XEP-0221). This part had no test coverage previously, explaining why it was not discovered until now. --- spec/util_dataforms_spec.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'spec') diff --git a/spec/util_dataforms_spec.lua b/spec/util_dataforms_spec.lua index 085128d1..ae6098be 100644 --- a/spec/util_dataforms_spec.lua +++ b/spec/util_dataforms_spec.lua @@ -106,6 +106,21 @@ describe("util.dataforms", function () name = "text-single-field", value = "text-single-value", }, + { + -- XEP-0221 + -- TODO Validate the XML produced by this. + type = "text-single", + label = "text-single-with-media-label", + name = "text-single-with-media-field", + media = { + height = 24, + width = 32, + { + type = "image/png", + uri = "data:", + }, + }, + }, }); xform = some_form:form(); end); -- cgit v1.2.3 From 8de93db692033a56ab3a516c9aadf6b27060e2a7 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 16 Aug 2020 20:30:02 +0200 Subject: util.dataforms: Add more XEP-0211 media element test coverage --- spec/util_dataforms_spec.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'spec') diff --git a/spec/util_dataforms_spec.lua b/spec/util_dataforms_spec.lua index ae6098be..0df9fb1d 100644 --- a/spec/util_dataforms_spec.lua +++ b/spec/util_dataforms_spec.lua @@ -438,5 +438,33 @@ describe("util.dataforms", function () assert.string(e.number); end); end); + describe("media element", function () + it("produced media element correctly", function () + local f; + for field in xform:childtags("field") do + if field.attr.var == "text-single-with-media-field" then + f = field; + break; + end + end + + assert.truthy(st.is_stanza(f)); + assert.equal("text-single-with-media-field", f.attr.var); + assert.equal("text-single", f.attr.type); + assert.equal("text-single-with-media-label", f.attr.label); + assert.equal(0, iter.count(f:childtags("value"))); + + local m = f:get_child("media", "urn:xmpp:media-element"); + assert.truthy(st.is_stanza(m)); + assert.equal("24", m.attr.height); + assert.equal("32", m.attr.width); + assert.equal(1, iter.count(m:childtags("uri"))); + + local u = m:get_child("uri"); + assert.truthy(st.is_stanza(u)); + assert.equal("image/png", u.attr.type); + assert.equal("data:", u:get_text()); + end); + end); end); -- cgit v1.2.3 From 9115d2a366b8c588a22041c3e35c97b8d8a37af2 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 20 Aug 2020 15:22:19 +0100 Subject: util.dbuffer: Fix traceback when :collapse() is called on empty buffer --- spec/util_dbuffer_spec.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'spec') diff --git a/spec/util_dbuffer_spec.lua b/spec/util_dbuffer_spec.lua index c4fa22b2..b7f80dc9 100644 --- a/spec/util_dbuffer_spec.lua +++ b/spec/util_dbuffer_spec.lua @@ -46,6 +46,13 @@ describe("util.dbuffer", function () end); end); + describe(":collapse()", function () + it("works on an empty buffer", function () + local b = dbuffer.new(); + b:collapse(); + end); + end); + describe(":sub", function () -- Helper function to compare buffer:sub() with string:sub() local s = "hello world"; @@ -106,5 +113,10 @@ describe("util.dbuffer", function () local r = { b:byte(1, 2) }; assert.same({ 0, 140 }, r); end); + + it("works on an empty buffer", function () + local b = dbuffer.new(); + assert.equal("", b:sub(1,1)); + end); end); end); -- cgit v1.2.3 From 076d8b698f664a8a47a38e16f54157cb702f43a8 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 21 Aug 2020 13:41:51 +0100 Subject: net.http.parser: Add failing test for (large?) chunk-encoded responses --- spec/inputs/http/httpstream-chunked-test.txt | 15 +++++++++++++++ spec/net_http_parser_spec.lua | 12 ++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 spec/inputs/http/httpstream-chunked-test.txt (limited to 'spec') diff --git a/spec/inputs/http/httpstream-chunked-test.txt b/spec/inputs/http/httpstream-chunked-test.txt new file mode 100644 index 00000000..56efa067 --- /dev/null +++ b/spec/inputs/http/httpstream-chunked-test.txt @@ -0,0 +1,15 @@ +HTTP/1.1 200 OK +Cache-Control: max-age=0, must-revalidate, private +Content-Type: application/json +Date: Fri, 21 Aug 2020 12:18:51 GMT +Expires: Fri, 21 Aug 2020 12:18:51 GMT +Server: Apache/2.4.38 (Debian) +Set-Cookie: PHPSESSID=00000000000000000000000000; path=/; HttpOnly +Strict-Transport-Security: max-age=29030400 +X-Powered-By: PHP/7.4.7 +Transfer-Encoding: chunked + +2b4d +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +0 + diff --git a/spec/net_http_parser_spec.lua b/spec/net_http_parser_spec.lua index 4ac3cab9..6a35d717 100644 --- a/spec/net_http_parser_spec.lua +++ b/spec/net_http_parser_spec.lua @@ -1,4 +1,5 @@ local http_parser = require "net.http.parser"; +local sha1 = require "util.hashes".sha1; local function test_stream(stream, expect) local success_cb = spy.new(function (packet) @@ -115,4 +116,15 @@ o ); end); end); + + pending("should handle large chunked responses", function () + local data = io.open("spec/inputs/httpstream-chunked-test.txt", "rb"):read("*a"); + + -- Just a sanity check... text editors and things may mess with line endings, etc. + assert.equal("25930f021785ae14053a322c2dbc1897c3769720", sha1(data, true), "test data malformed"); + + test_stream(data, { + body = string.rep("~", 11085), count = 2; + }); + end); end); -- cgit v1.2.3 From 70b697de98ce0501cd5d139890c9c428acd71f14 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 21 Aug 2020 13:49:10 +0100 Subject: net.http.parser: Fix incorrect path in test --- spec/net_http_parser_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/net_http_parser_spec.lua b/spec/net_http_parser_spec.lua index 6a35d717..1a15302d 100644 --- a/spec/net_http_parser_spec.lua +++ b/spec/net_http_parser_spec.lua @@ -118,7 +118,7 @@ o end); pending("should handle large chunked responses", function () - local data = io.open("spec/inputs/httpstream-chunked-test.txt", "rb"):read("*a"); + local data = io.open("spec/inputs/http/httpstream-chunked-test.txt", "rb"):read("*a"); -- Just a sanity check... text editors and things may mess with line endings, etc. assert.equal("25930f021785ae14053a322c2dbc1897c3769720", sha1(data, true), "test data malformed"); -- cgit v1.2.3 From 76dd86054ce12963190255a135cf7c16ba4c4615 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 21 Aug 2020 14:12:51 +0100 Subject: net.http.parser: Switch tests so that CRLF conversion of input data is optional --- spec/net_http_parser_spec.lua | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'spec') diff --git a/spec/net_http_parser_spec.lua b/spec/net_http_parser_spec.lua index 1a15302d..1a86dbba 100644 --- a/spec/net_http_parser_spec.lua +++ b/spec/net_http_parser_spec.lua @@ -1,6 +1,10 @@ local http_parser = require "net.http.parser"; local sha1 = require "util.hashes".sha1; +local function CRLF(s) + return (s:gsub("\n", "\r\n")); +end + local function test_stream(stream, expect) local success_cb = spy.new(function (packet) assert.is_table(packet); @@ -9,7 +13,6 @@ local function test_stream(stream, expect) end end); - stream = stream:gsub("\n", "\r\n"); local parser = http_parser.new(success_cb, error, stream:sub(1,4) == "HTTP" and "client" or "server") for chunk in stream:gmatch("..?.?") do parser:feed(chunk); @@ -23,7 +26,7 @@ describe("net.http.parser", function() describe("parser", function() it("should handle requests with no content-length or body", function () test_stream( -[[ +CRLF[[ GET / HTTP/1.1 Host: example.com @@ -36,7 +39,7 @@ Host: example.com it("should handle responses with empty body", function () test_stream( -[[ +CRLF[[ HTTP/1.1 200 OK Content-Length: 0 @@ -50,7 +53,7 @@ Content-Length: 0 it("should handle simple responses", function () test_stream( -[[ +CRLF[[ HTTP/1.1 200 OK Content-Length: 7 @@ -65,7 +68,7 @@ Hello it("should handle chunked encoding in responses", function () test_stream( -[[ +CRLF[[ HTTP/1.1 200 OK Transfer-Encoding: chunked @@ -90,7 +93,7 @@ o it("should handle a stream of responses", function () test_stream( -[[ +CRLF[[ HTTP/1.1 200 OK Content-Length: 5 @@ -117,7 +120,7 @@ o end); end); - pending("should handle large chunked responses", function () + it("should handle large chunked responses", function () local data = io.open("spec/inputs/http/httpstream-chunked-test.txt", "rb"):read("*a"); -- Just a sanity check... text editors and things may mess with line endings, etc. -- cgit v1.2.3 From 54e37ffe8d4562adc974a61359a8bfef8e0dcd29 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 21 Aug 2020 14:14:29 +0100 Subject: net.http.parser: Allow configuration of the chunk size fed to the parser --- spec/net_http_parser_spec.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/net_http_parser_spec.lua b/spec/net_http_parser_spec.lua index 1a86dbba..f71cad20 100644 --- a/spec/net_http_parser_spec.lua +++ b/spec/net_http_parser_spec.lua @@ -1,6 +1,8 @@ local http_parser = require "net.http.parser"; local sha1 = require "util.hashes".sha1; +local parser_input_bytes = 3; + local function CRLF(s) return (s:gsub("\n", "\r\n")); end @@ -14,7 +16,7 @@ local function test_stream(stream, expect) end); local parser = http_parser.new(success_cb, error, stream:sub(1,4) == "HTTP" and "client" or "server") - for chunk in stream:gmatch("..?.?") do + for chunk in stream:gmatch("."..string.rep(".?", parser_input_bytes-1)) do parser:feed(chunk); end -- cgit v1.2.3 From b289d05cfbde014799fcf66fec36895bee5be071 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 18 Jul 2020 15:36:25 +0200 Subject: mod_external_services: XEP-0215: External Service Discovery --- spec/scansion/extdisco.scs | 57 +++++++++++++++++++++++++++++++++++++++++++ spec/scansion/prosody.cfg.lua | 12 +++++++++ 2 files changed, 69 insertions(+) create mode 100644 spec/scansion/extdisco.scs (limited to 'spec') diff --git a/spec/scansion/extdisco.scs b/spec/scansion/extdisco.scs new file mode 100644 index 00000000..fd73c9da --- /dev/null +++ b/spec/scansion/extdisco.scs @@ -0,0 +1,57 @@ +# XEP-0215: External Service Discovery + +[Client] Romeo + password: password + jid: user@localhost/mFquWxSr + +----- + +Romeo connects + +Romeo sends: + + + + +Romeo receives: + + + + + + + + + + +Romeo sends: + + + + +Romeo receives: + + + + + + + +Romeo sends: + + + + + + +Romeo receives: + + + + + + + +Romeo disconnects + +# recording ended on 2020-07-18T16:47:57Z diff --git a/spec/scansion/prosody.cfg.lua b/spec/scansion/prosody.cfg.lua index 0bf68ddb..4e43d312 100644 --- a/spec/scansion/prosody.cfg.lua +++ b/spec/scansion/prosody.cfg.lua @@ -62,6 +62,7 @@ modules_enabled = { --"legacyauth"; -- Legacy authentication. Only used by some old clients and bots. --"proxy65"; -- Enables a file transfer proxy service which clients behind NAT can use "lastactivity"; + "external_services"; -- Useful for testing --"scansion_record"; -- Records things that happen in scansion test case format @@ -77,6 +78,17 @@ contact_info = { support = { "https://localhost/support.html", "xmpp:support@localhost" }; } +external_service_host = "default.example" +external_service_port = 9876 +external_service_secret = "" +external_services = { + {type = "stun"; transport = "udp"}; + {type = "turn"; transport = "udp"; secret = true}; + {type = "turn"; transport = "udp"; secret = "foo"}; + {type = "ftp"; transport = "tcp"; port = 2121; username = "john"; password = "password"}; + {type = "ftp"; transport = "tcp"; host = "ftp.example.com"; port = 21; username = "john"; password = "password"}; +} + modules_disabled = { "s2s"; } -- cgit v1.2.3 From e21429d8e4533f765072f432b138a68092dab3fa Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 24 Aug 2020 17:07:37 +0200 Subject: util.dbuffer: Add failing test case involving :sub after :discard --- spec/util_dbuffer_spec.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'spec') diff --git a/spec/util_dbuffer_spec.lua b/spec/util_dbuffer_spec.lua index b7f80dc9..26fa7da6 100644 --- a/spec/util_dbuffer_spec.lua +++ b/spec/util_dbuffer_spec.lua @@ -67,6 +67,15 @@ describe("util.dbuffer", function () assert.equals("hello", b:sub(1, 5)); end); + pending("works after discard", function () + local b = dbuffer.new(256); + assert.truthy(b:write("foo")); + assert.truthy(b:write("bar")); + assert.equals("foobar", b:sub(1, 6)); + assert.truthy(b:discard(3)) -- until the space + assert.equals("bar", b:sub(1, 3)); + end); + it("supports optional end parameter", function () local b = dbuffer.new(); assert.truthy(b:write("hello world")); -- cgit v1.2.3 From 7fa4cc8de0ffb0a0914c1861987a19cf666febf6 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 24 Aug 2020 16:18:13 +0100 Subject: util.dbuffer: Fix :sub() not working with partially-consumed chunks (thanks Zash for test case) This also appears to fix some bugs with chunk-encoded streams in net.http.parser. --- spec/util_dbuffer_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/util_dbuffer_spec.lua b/spec/util_dbuffer_spec.lua index 26fa7da6..554a7e54 100644 --- a/spec/util_dbuffer_spec.lua +++ b/spec/util_dbuffer_spec.lua @@ -67,7 +67,7 @@ describe("util.dbuffer", function () assert.equals("hello", b:sub(1, 5)); end); - pending("works after discard", function () + it("works after discard", function () local b = dbuffer.new(256); assert.truthy(b:write("foo")); assert.truthy(b:write("bar")); -- cgit v1.2.3 From 21ecc6ca399493eb88e75f2979d64a779cd34f50 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 24 Aug 2020 17:28:48 +0200 Subject: util.dbuffer: Simplify test case An earlier theory involved the bug being related to collapsing multiple items, so it exercised that too. Also correct the comment, it referred to the space in "hello world" in an earlier version before the test string was changed to "foobar", which was what was tested in a REPL --- spec/util_dbuffer_spec.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'spec') diff --git a/spec/util_dbuffer_spec.lua b/spec/util_dbuffer_spec.lua index 554a7e54..af404042 100644 --- a/spec/util_dbuffer_spec.lua +++ b/spec/util_dbuffer_spec.lua @@ -69,10 +69,9 @@ describe("util.dbuffer", function () it("works after discard", function () local b = dbuffer.new(256); - assert.truthy(b:write("foo")); - assert.truthy(b:write("bar")); + assert.truthy(b:write("foobar")); assert.equals("foobar", b:sub(1, 6)); - assert.truthy(b:discard(3)) -- until the space + assert.truthy(b:discard(3)); -- consume "foo" assert.equals("bar", b:sub(1, 3)); end); -- cgit v1.2.3 From 403f320d905ae32f2b1f7568c229675b71667473 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 28 Aug 2020 18:43:37 +0200 Subject: util.jid: Add test coverage for XEP-0106: JID Escaping functions --- spec/util_jid_spec.lua | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'spec') diff --git a/spec/util_jid_spec.lua b/spec/util_jid_spec.lua index c075212f..17cadbee 100644 --- a/spec/util_jid_spec.lua +++ b/spec/util_jid_spec.lua @@ -75,6 +75,56 @@ describe("util.jid", function() end); end); + local jid_escaping_test_vectors = { + -- From https://xmpp.org/extensions/xep-0106.xml#examples sans @example.com + [[space cadet]], [[space\20cadet]], + [[call me "ishmael"]], [[call\20me\20\22ishmael\22]], + [[at&t guy]], [[at\26t\20guy]], + [[d'artagnan]], [[d\27artagnan]], + [[/.fanboy]], [[\2f.fanboy]], + [[::foo::]], [[\3a\3afoo\3a\3a]], + [[]], [[\3cfoo\3e]], + [[user@host]], [[user\40host]], + [[c:\net]], [[c\3a\net]], + [[c:\\net]], [[c\3a\\net]], + [[c:\cool stuff]], [[c\3a\cool\20stuff]], + [[c:\5commas]], [[c\3a\5c5commas]], + + -- Section 4.2 + [[\3and\2is\5cool]], [[\5c3and\2is\5c5cool]], + + -- From aioxmpp + [[\5c]], [[\5c5c]], + -- [[\5C]], [[\5C]], + [[\2plus\2is\4]], [[\2plus\2is\4]], + [[foo\bar]], [[foo\bar]], + [[foo\41r]], [[foo\41r]], + -- additional test vectors + [[call\20me]], [[call\5c20me]], + }; + + describe("#escape()", function () + it("should work", function () + for i = 1, #jid_escaping_test_vectors, 2 do + local original = jid_escaping_test_vectors[i]; + local escaped = jid_escaping_test_vectors[i+1]; + + assert.are.equal(escaped, jid.escape(original), ("Escapes '%s' -> '%s'"):format(original, escaped)); + end + end); + end) + + describe("#unescape()", function () + it("should work", function () + for i = 1, #jid_escaping_test_vectors, 2 do + local original = jid_escaping_test_vectors[i]; + local escaped = jid_escaping_test_vectors[i+1]; + + assert.are.equal(original, jid.unescape(escaped), ("Unescapes '%s' -> '%s'"):format(escaped, original)); + end + end); + end) + it("should work with nodes", function() local function test(_jid, expected_node) assert.are.equal(jid.node(_jid), expected_node, "Unexpected node for "..tostring(_jid)); -- cgit v1.2.3 From c909bca762b655dd798b9f0f5c937feced7aa655 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 3 Sep 2020 12:59:43 +0100 Subject: util.events: Add set_debug_hook() method Hook signature: ret = debug_hook(handler, event_name, event_data) --- spec/util_events_spec.lua | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'spec') diff --git a/spec/util_events_spec.lua b/spec/util_events_spec.lua index fee60f8f..95303cce 100644 --- a/spec/util_events_spec.lua +++ b/spec/util_events_spec.lua @@ -208,5 +208,43 @@ describe("util.events", function () assert.spy(h).was_called(2); end); end); + + describe("debug hooks", function () + it("should get called", function () + local d = spy.new(function (handler, event_name, event_data) + return handler(event_data); + end); + + e.add_handler("myevent", h); + e.fire_event("myevent"); + + assert.spy(h).was_called(1); + assert.spy(d).was_called(0); + + assert.is_nil(e.set_debug_hook(d)); + + e.fire_event("myevent", { mydata = true }); + + assert.spy(h).was_called(2); + assert.spy(d).was_called(1); + assert.spy(d).was_called_with(h, "myevent", { mydata = true }); + + assert.equal(d, e.set_debug_hook(nil)); + + e.fire_event("myevent", { mydata = false }); + + assert.spy(h).was_called(3); + assert.spy(d).was_called(1); + end); + it("setting should return any existing debug hook", function () + local function f() end + local function g() end + assert.is_nil(e.set_debug_hook(f)); + assert.is_equal(f, e.set_debug_hook(g)); + assert.is_equal(g, e.set_debug_hook(f)); + assert.is_equal(f, e.set_debug_hook(nil)); + assert.is_nil(e.set_debug_hook(f)); + end); + end); end); end); -- cgit v1.2.3 From e419f0b5f4fd61a6e0e2f96f497bb72ddddc1a98 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 3 Sep 2020 13:10:46 +0100 Subject: util.event: Add luacheck annotation to unused parameter in tests --- spec/util_events_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/util_events_spec.lua b/spec/util_events_spec.lua index 95303cce..fcfa6e53 100644 --- a/spec/util_events_spec.lua +++ b/spec/util_events_spec.lua @@ -211,7 +211,7 @@ describe("util.events", function () describe("debug hooks", function () it("should get called", function () - local d = spy.new(function (handler, event_name, event_data) + local d = spy.new(function (handler, event_name, event_data) --luacheck: ignore 212/event_name return handler(event_data); end); -- cgit v1.2.3 From 0ca2e88384f6ec512879cf4cfbe2627b984762d5 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 9 Sep 2020 17:10:33 +0100 Subject: util.interpolation: Add '~' as the opposite of '&' (render sub-block if falsy) One more magic character consumed! --- spec/util_interpolation_spec.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/util_interpolation_spec.lua b/spec/util_interpolation_spec.lua index 76000d94..98ed3b74 100644 --- a/spec/util_interpolation_spec.lua +++ b/spec/util_interpolation_spec.lua @@ -32,7 +32,15 @@ local template_map = [[ local expect_map = [[ FOO: bar ]] - +local template_not = [[ +{thing~Thing is nil}{thing&Thing is not nil} +]] +local expect_not_true = [[ +Thing is not nil +]] +local expect_not_nil = [[ +Thing is nil +]] describe("util.interpolation", function () it("renders", function () local render = require "util.interpolation".new("%b{}", string.upper, { sort = function (t) table.sort(t) return t end }); @@ -43,5 +51,7 @@ describe("util.interpolation", function () assert.equal(expect_func_pipe, render(template_func_pipe, { foo = { "c", "a", "d", "b", } })); -- assert.equal("", render(template_func_pipe, { foo = nil })); -- FIXME assert.equal(expect_map, render(template_map, { foo = { foo = "bar" } })); + assert.equal(expect_not_true, render(template_not, { thing = true })); + assert.equal(expect_not_nil, render(template_not, { thing = nil })); end); end); -- cgit v1.2.3 From 686adb2d713f0a1b5f8ec27221fcf00f6ece886f Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 9 Sep 2020 17:12:00 +0100 Subject: util.interpolation: Add test for ~ when value is false (not just nil) --- spec/util_interpolation_spec.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'spec') diff --git a/spec/util_interpolation_spec.lua b/spec/util_interpolation_spec.lua index 98ed3b74..614d1f54 100644 --- a/spec/util_interpolation_spec.lua +++ b/spec/util_interpolation_spec.lua @@ -33,13 +33,16 @@ local expect_map = [[ FOO: bar ]] local template_not = [[ -{thing~Thing is nil}{thing&Thing is not nil} +{thing~Thing is falsy}{thing&Thing is truthy} ]] local expect_not_true = [[ -Thing is not nil +Thing is truthy ]] local expect_not_nil = [[ -Thing is nil +Thing is falsy +]] +local expect_not_false = [[ +Thing is falsy ]] describe("util.interpolation", function () it("renders", function () @@ -53,5 +56,6 @@ describe("util.interpolation", function () assert.equal(expect_map, render(template_map, { foo = { foo = "bar" } })); assert.equal(expect_not_true, render(template_not, { thing = true })); assert.equal(expect_not_nil, render(template_not, { thing = nil })); + assert.equal(expect_not_false, render(template_not, { thing = false })); end); end); -- cgit v1.2.3 From bc20052a9b53c466db12e7d35cf6c073c0ee5a3e Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 21 Nov 2019 18:56:43 +0100 Subject: util.dataforms: Add support for validating (integer) ranges --- spec/util_dataforms_spec.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'spec') diff --git a/spec/util_dataforms_spec.lua b/spec/util_dataforms_spec.lua index 0df9fb1d..d2d1264a 100644 --- a/spec/util_dataforms_spec.lua +++ b/spec/util_dataforms_spec.lua @@ -423,6 +423,8 @@ describe("util.dataforms", function () name = "number", type = "text-single", datatype = "xs:integer", + range_min = -10, + range_max = 10, }, }; @@ -437,6 +439,13 @@ describe("util.dataforms", function () assert.table(e); assert.string(e.number); end); + + it("works", function () + local d,e = f:data(f:form({number = 100})); + assert.not_equal(100, d.number); + assert.table(e); + assert.string(e.number); + end); end); describe("media element", function () it("produced media element correctly", function () -- cgit v1.2.3 From ed5841e42b9c6b2ae31ba5f9a5767e67e2fb71d4 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 26 Sep 2020 17:16:34 +0200 Subject: util.error: Add well-known field 'extra' A place for various extra fields and edge cases of the stanza error data model, e.g. the URI field of --- spec/util_error_spec.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'spec') diff --git a/spec/util_error_spec.lua b/spec/util_error_spec.lua index ca053285..136f8b12 100644 --- a/spec/util_error_spec.lua +++ b/spec/util_error_spec.lua @@ -66,5 +66,13 @@ describe("util.error", function () end); end); + describe("extra", function () + it("keeps some extra fields", function () + local err = errors.new({condition="gone",text="Sorry mate, it's all gone",extra={uri="file:///dev/null"}}); + assert.is_table(err.extra); + assert.equal("file:///dev/null", err.extra.uri); + end); + end) + end); -- cgit v1.2.3 From 2f0b85ce29a6b4eaa210a60a5d04610f0401379d Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 26 Sep 2020 17:26:31 +0200 Subject: util.stanza: Support getting 'by' from util.error object --- spec/util_stanza_spec.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua index efe3e47e..ec392611 100644 --- a/spec/util_stanza_spec.lua +++ b/spec/util_stanza_spec.lua @@ -234,7 +234,7 @@ describe("util.stanza", function() it("should accept util.error objects", function () local s = st.message({ to = "touser", from = "fromuser", id = "123", type = "chat" }, "Hello"); - local e = errors.new({ type = "modify", condition = "not-acceptable", text = "Bork bork bork" }); + local e = errors.new({ type = "modify", condition = "not-acceptable", text = "Bork bork bork", extra = { by = "this.test" } }); local r = st.error_reply(s, e); assert.are.equal(r.name, s.name); @@ -246,6 +246,7 @@ describe("util.stanza", function() assert.are.equal(r.tags[1].attr.type, e.type); assert.are.equal(r.tags[1].tags[1].name, e.condition); assert.are.equal(r.tags[1].tags[2]:get_text(), e.text); + assert.are.equal("this.test", r.tags[1].attr.by); end); end); -- cgit v1.2.3 From 3f9988468d11d6e3b94fec0ec1ed4271712bed14 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 26 Sep 2020 17:30:47 +0200 Subject: util.stanza: Support inclusion of URI from util.error object --- spec/util_stanza_spec.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'spec') diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua index ec392611..c4c1d174 100644 --- a/spec/util_stanza_spec.lua +++ b/spec/util_stanza_spec.lua @@ -247,6 +247,11 @@ describe("util.stanza", function() assert.are.equal(r.tags[1].tags[1].name, e.condition); assert.are.equal(r.tags[1].tags[2]:get_text(), e.text); assert.are.equal("this.test", r.tags[1].attr.by); + + local gone = errors.new({ condition = "gone", extra = { uri = "file:///dev/null" } }) + local gonner = st.error_reply(s, gone); + assert.are.equal("gone", gonner.tags[1].tags[1].name); + assert.are.equal("file:///dev/null", gonner.tags[1].tags[1][1]); end); end); -- cgit v1.2.3 From 8c0efc9e55d0980e2ce5872da325724aeaec5dba Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 26 Sep 2020 18:07:33 +0200 Subject: util.stanza: Get 'by' from context instead Zash> should go where? extra.by? context? source? Zash> In Prosody this would usually be module.host or a bare user/room JID MattJ> Zash: context MattJ> context.by, basically the opposite of context.actor --- spec/util_stanza_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua index c4c1d174..cc32bba9 100644 --- a/spec/util_stanza_spec.lua +++ b/spec/util_stanza_spec.lua @@ -234,7 +234,7 @@ describe("util.stanza", function() it("should accept util.error objects", function () local s = st.message({ to = "touser", from = "fromuser", id = "123", type = "chat" }, "Hello"); - local e = errors.new({ type = "modify", condition = "not-acceptable", text = "Bork bork bork", extra = { by = "this.test" } }); + local e = errors.new({ type = "modify", condition = "not-acceptable", text = "Bork bork bork" }, { by = "this.test" }); local r = st.error_reply(s, e); assert.are.equal(r.name, s.name); -- cgit v1.2.3 From 1c53f533b09008be2ed26e3ffccc31c2609cc566 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 26 Sep 2020 18:09:10 +0200 Subject: util.stanza: Support Application-Specific Conditions in util.error --- spec/util_stanza_spec.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua index cc32bba9..ba90eb84 100644 --- a/spec/util_stanza_spec.lua +++ b/spec/util_stanza_spec.lua @@ -252,8 +252,20 @@ describe("util.stanza", function() local gonner = st.error_reply(s, gone); assert.are.equal("gone", gonner.tags[1].tags[1].name); assert.are.equal("file:///dev/null", gonner.tags[1].tags[1][1]); - end); + local e = errors.new({ condition = "internal-server-error", text = "Namespaced thing happened", + extra = {namespace="xmpp:example.test", condition="this-happened"} }) + local r = st.error_reply(s, e); + assert.are.equal("xmpp:example.test", r.tags[1].tags[3].attr.xmlns); + assert.are.equal("this-happened", r.tags[1].tags[3].name); + + local e2 = errors.new({ condition = "internal-server-error", text = "Namespaced thing happened", + extra = {tag=st.stanza("that-happened", { xmlns = "xmpp:example.test", ["another-attribute"] = "here" })} }) + local r2 = st.error_reply(s, e2); + assert.are.equal("xmpp:example.test", r2.tags[1].tags[3].attr.xmlns); + assert.are.equal("that-happened", r2.tags[1].tags[3].name); + assert.are.equal("here", r2.tags[1].tags[3].attr["another-attribute"]); + end); end); describe("should reject #invalid", function () -- cgit v1.2.3 From a7c3fc20a079422cf597a5a20e88c6e58054de39 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 26 Sep 2020 19:00:17 +0200 Subject: spec.stanza spec: Split up util.error related tests --- spec/util_stanza_spec.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'spec') diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua index ba90eb84..a363086c 100644 --- a/spec/util_stanza_spec.lua +++ b/spec/util_stanza_spec.lua @@ -232,6 +232,7 @@ describe("util.stanza", function() end, "got stanza of type error"); end); + describe("util.error integration", function () it("should accept util.error objects", function () local s = st.message({ to = "touser", from = "fromuser", id = "123", type = "chat" }, "Hello"); local e = errors.new({ type = "modify", condition = "not-acceptable", text = "Bork bork bork" }, { by = "this.test" }); @@ -247,12 +248,18 @@ describe("util.stanza", function() assert.are.equal(r.tags[1].tags[1].name, e.condition); assert.are.equal(r.tags[1].tags[2]:get_text(), e.text); assert.are.equal("this.test", r.tags[1].attr.by); + end); + it("should accept util.error objects with an URI", function () + local s = st.message({ to = "touser", from = "fromuser", id = "123", type = "chat" }, "Hello"); local gone = errors.new({ condition = "gone", extra = { uri = "file:///dev/null" } }) local gonner = st.error_reply(s, gone); assert.are.equal("gone", gonner.tags[1].tags[1].name); assert.are.equal("file:///dev/null", gonner.tags[1].tags[1][1]); + end); + it("should accept util.error objects with application specific error", function () + local s = st.message({ to = "touser", from = "fromuser", id = "123", type = "chat" }, "Hello"); local e = errors.new({ condition = "internal-server-error", text = "Namespaced thing happened", extra = {namespace="xmpp:example.test", condition="this-happened"} }) local r = st.error_reply(s, e); @@ -266,6 +273,7 @@ describe("util.stanza", function() assert.are.equal("that-happened", r2.tags[1].tags[3].name); assert.are.equal("here", r2.tags[1].tags[3].attr["another-attribute"]); end); + end); end); describe("should reject #invalid", function () -- cgit v1.2.3 From 815ce25d10e49f4efa7b402c8d5b03a0f63474f1 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 26 Sep 2020 18:12:18 +0200 Subject: util.stanza: Extract Application-Specific Condition from errors API change --- spec/util_stanza_spec.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'spec') diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua index a363086c..535f783b 100644 --- a/spec/util_stanza_spec.lua +++ b/spec/util_stanza_spec.lua @@ -276,6 +276,19 @@ describe("util.stanza", function() end); end); + describe("#get_error()", function () + describe("basics", function () + local s = st.message(); + local e = st.error_reply(s, "cancel", "not-acceptable", "UNACCEPTABLE!!!! ONE MILLION YEARS DUNGEON!") + :tag("dungeon", { xmlns = "urn:uuid:c9026187-5b05-4e70-b265-c3b6338a7d0f", period="1000000years"}); + local typ, cond, text, extra = e:get_error(); + assert.equal("cancel", typ); + assert.equal("not-acceptable", cond); + assert.equal("UNACCEPTABLE!!!! ONE MILLION YEARS DUNGEON!", text); + assert.not_nil(extra) + end) + end) + describe("should reject #invalid", function () local invalid_names = { ["empty string"] = "", ["characters"] = "<>"; -- cgit v1.2.3 From 0354452a9a537d141e61d09b553e1ceadf97cf42 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 26 Sep 2020 18:13:27 +0200 Subject: util.error: Extract error originator from stanza errors --- spec/util_error_spec.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/util_error_spec.lua b/spec/util_error_spec.lua index 136f8b12..9cb1c57b 100644 --- a/spec/util_error_spec.lua +++ b/spec/util_error_spec.lua @@ -48,12 +48,13 @@ describe("util.error", function () it("works", function () local st = require "util.stanza"; local m = st.message({ type = "chat" }); - local e = st.error_reply(m, "modify", "bad-request"); + local e = st.error_reply(m, "modify", "bad-request", nil, "error.example"); local err = errors.from_stanza(e); assert.truthy(errors.is_err(err)); assert.equal("modify", err.type); assert.equal("bad-request", err.condition); assert.equal(e, err.context.stanza); + assert.equal("error.example", err.context.by); end); end); -- cgit v1.2.3 From a51d5912465d8129ab062572d1f2e2bdddf967e6 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 26 Sep 2020 18:15:49 +0200 Subject: util.error: Collect Application-Specific Conditions from stanza errors --- spec/util_error_spec.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/util_error_spec.lua b/spec/util_error_spec.lua index 9cb1c57b..bb85d303 100644 --- a/spec/util_error_spec.lua +++ b/spec/util_error_spec.lua @@ -48,13 +48,14 @@ describe("util.error", function () it("works", function () local st = require "util.stanza"; local m = st.message({ type = "chat" }); - local e = st.error_reply(m, "modify", "bad-request", nil, "error.example"); + local e = st.error_reply(m, "modify", "bad-request", nil, "error.example"):tag("extra", { xmlns = "xmpp:example.test" }); local err = errors.from_stanza(e); assert.truthy(errors.is_err(err)); assert.equal("modify", err.type); assert.equal("bad-request", err.condition); assert.equal(e, err.context.stanza); assert.equal("error.example", err.context.by); + assert.not_nil(err.extra.tag); end); end); -- cgit v1.2.3 From dc446463ab10d466f5c67cab4530156a85d4dd9f Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 28 Sep 2020 18:36:00 +0200 Subject: util.error: Cover registry initialization in test --- spec/util_error_spec.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'spec') diff --git a/spec/util_error_spec.lua b/spec/util_error_spec.lua index bb85d303..6314d9ff 100644 --- a/spec/util_error_spec.lua +++ b/spec/util_error_spec.lua @@ -76,5 +76,25 @@ describe("util.error", function () end); end) + describe("init", function() + it("basics works", function() + local reg = errors.init("test", { + broke = {type = "cancel"; condition = "internal-server-error"; text = "It broke :("}; + nope = {type = "auth"; condition = "not-authorized"; text = "Can't let you do that Dave"}; + }); + + local broke = reg.new("broke"); + assert.equal("cancel", broke.type); + assert.equal("internal-server-error", broke.condition); + assert.equal("It broke :(", broke.text); + assert.equal("test", broke.source); + + local nope = reg.new("nope"); + assert.equal("auth", nope.type); + assert.equal("not-authorized", nope.condition); + assert.equal("Can't let you do that Dave", nope.text); + end); + end); + end); -- cgit v1.2.3 From 5da983d8bdc574f9358a16eb08d700dde3ca7026 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 28 Sep 2020 18:39:51 +0200 Subject: util.error: Add a "compact mode" for registries Inspired by the older registry in pubsub.lib.lua --- spec/util_error_spec.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'spec') diff --git a/spec/util_error_spec.lua b/spec/util_error_spec.lua index 6314d9ff..399b5998 100644 --- a/spec/util_error_spec.lua +++ b/spec/util_error_spec.lua @@ -94,6 +94,27 @@ describe("util.error", function () assert.equal("not-authorized", nope.condition); assert.equal("Can't let you do that Dave", nope.text); end); + + it("compact mode works", function() + local reg = errors.init("test", { + namespace = "spec"; + broke = {"cancel"; "internal-server-error"; "It broke :("}; + nope = {"auth"; "not-authorized"; "Can't let you do that Dave"; "sorry-dave"}; + }); + + local broke = reg.new("broke"); + assert.equal("cancel", broke.type); + assert.equal("internal-server-error", broke.condition); + assert.equal("It broke :(", broke.text); + assert.is_nil(broke.extra); + + local nope = reg.new("nope"); + assert.equal("auth", nope.type); + assert.equal("not-authorized", nope.condition); + assert.equal("Can't let you do that Dave", nope.text); + assert.equal("spec", nope.extra.namespace); + assert.equal("sorry-dave", nope.extra.condition); + end); end); end); -- cgit v1.2.3 From 9dbdb91c471ea765936a15af02b62e4cbf7ba7a2 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 28 Sep 2020 22:13:04 +0200 Subject: util.error: Expand compact registries into normal form internally Also the exposed form on the table returned from init() --- spec/util_error_spec.lua | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'spec') diff --git a/spec/util_error_spec.lua b/spec/util_error_spec.lua index 399b5998..8b995895 100644 --- a/spec/util_error_spec.lua +++ b/spec/util_error_spec.lua @@ -115,6 +115,38 @@ describe("util.error", function () assert.equal("spec", nope.extra.namespace); assert.equal("sorry-dave", nope.extra.condition); end); + + it("registry looks the same regardless of syntax", function() + local normal = errors.init("test", { + broke = {type = "cancel"; condition = "internal-server-error"; text = "It broke :("}; + nope = { + type = "auth"; + condition = "not-authorized"; + text = "Can't let you do that Dave"; + extra = {namespace = "spec"; condition = "sorry-dave"}; + }; + }); + local compact1 = errors.init("test", { + namespace = "spec"; + broke = {"cancel"; "internal-server-error"; "It broke :("}; + nope = {"auth"; "not-authorized"; "Can't let you do that Dave"; "sorry-dave"}; + }); + local compact2 = errors.init("test", "spec", { + broke = {"cancel"; "internal-server-error"; "It broke :("}; + nope = {"auth"; "not-authorized"; "Can't let you do that Dave"; "sorry-dave"}; + }); + local compact3 = errors.init("test", { + broke = {"cancel"; "internal-server-error"; "It broke :("}; + nope = {"auth"; "not-authorized"; "Can't let you do that Dave"}; + }); + assert.same(normal.registry, compact1.registry); + assert.same(normal.registry, compact2.registry); + + assert.same({ + broke = {type = "cancel"; condition = "internal-server-error"; text = "It broke :("}; + nope = {type = "auth"; condition = "not-authorized"; text = "Can't let you do that Dave"}; + }, compact3.registry); + end); end); end); -- cgit v1.2.3 From 33070035bf3e92548e69418e357bec5ca55f6266 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 28 Sep 2020 23:48:02 +0200 Subject: util.error: Drop registry initialization with namespace as key Enough complexity with compact vs normal and with/without namespace --- spec/util_error_spec.lua | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'spec') diff --git a/spec/util_error_spec.lua b/spec/util_error_spec.lua index 8b995895..34edd313 100644 --- a/spec/util_error_spec.lua +++ b/spec/util_error_spec.lua @@ -96,8 +96,7 @@ describe("util.error", function () end); it("compact mode works", function() - local reg = errors.init("test", { - namespace = "spec"; + local reg = errors.init("test", "spec", { broke = {"cancel"; "internal-server-error"; "It broke :("}; nope = {"auth"; "not-authorized"; "Can't let you do that Dave"; "sorry-dave"}; }); @@ -126,26 +125,20 @@ describe("util.error", function () extra = {namespace = "spec"; condition = "sorry-dave"}; }; }); - local compact1 = errors.init("test", { - namespace = "spec"; - broke = {"cancel"; "internal-server-error"; "It broke :("}; - nope = {"auth"; "not-authorized"; "Can't let you do that Dave"; "sorry-dave"}; - }); - local compact2 = errors.init("test", "spec", { + local compact1 = errors.init("test", "spec", { broke = {"cancel"; "internal-server-error"; "It broke :("}; nope = {"auth"; "not-authorized"; "Can't let you do that Dave"; "sorry-dave"}; }); - local compact3 = errors.init("test", { + local compact2 = errors.init("test", { broke = {"cancel"; "internal-server-error"; "It broke :("}; nope = {"auth"; "not-authorized"; "Can't let you do that Dave"}; }); assert.same(normal.registry, compact1.registry); - assert.same(normal.registry, compact2.registry); assert.same({ broke = {type = "cancel"; condition = "internal-server-error"; text = "It broke :("}; nope = {type = "auth"; condition = "not-authorized"; text = "Can't let you do that Dave"}; - }, compact3.registry); + }, compact2.registry); end); end); -- cgit v1.2.3 From fce45aff34dea1959b0640d9a02374c6bb5897de Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 17 Oct 2020 19:00:16 +0200 Subject: util.paths: Add some tests --- spec/util_paths_spec.lua | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 spec/util_paths_spec.lua (limited to 'spec') diff --git a/spec/util_paths_spec.lua b/spec/util_paths_spec.lua new file mode 100644 index 00000000..243b35fb --- /dev/null +++ b/spec/util_paths_spec.lua @@ -0,0 +1,39 @@ +local sep = package.config:match("(.)\n"); +describe("util.paths", function () + local paths = require "util.paths"; + describe("#join()", function () + it("returns single component as-is", function () + assert.equal("foo", paths.join("foo")); + end); + it("joins paths", function () + assert.equal("foo"..sep.."bar", paths.join("foo", "bar")) + end); + it("joins longer paths", function () + assert.equal("foo"..sep.."bar"..sep.."baz", paths.join("foo", "bar", "baz")) + end); + it("joins even longer paths", function () + assert.equal("foo"..sep.."bar"..sep.."baz"..sep.."moo", paths.join("foo", "bar", "baz", "moo")) + end); + end) + + describe("#glob_to_pattern()", function () + it("works", function () + assert.equal("^thing.%..*$", paths.glob_to_pattern("thing?.*")) + end); + + end) + describe("#resolve_relative_path()", function () + it("returns absolute paths as-is", function () + if sep == "/" then + assert.equal("/tmp/path", paths.resolve_relative_path("/run", "/tmp/path")); + elseif sep == "\\" then + assert.equal("C:\\Program Files", paths.resolve_relative_path("A:\\", "C:\\Program Files")); + end + end); + it("resolves relative paths", function () + if sep == "/" then + assert.equal("/run/path", paths.resolve_relative_path("/run", "path")); + end + end); + end) +end) -- cgit v1.2.3 From c812a980682ce678045ee8031b8b0da9237458f0 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 17 Oct 2020 19:24:44 +0200 Subject: util_paths_spec: Trim trailing white space And add spacing between describe() blocks --- spec/util_paths_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/util_paths_spec.lua b/spec/util_paths_spec.lua index 243b35fb..2e8a0c08 100644 --- a/spec/util_paths_spec.lua +++ b/spec/util_paths_spec.lua @@ -20,8 +20,8 @@ describe("util.paths", function () it("works", function () assert.equal("^thing.%..*$", paths.glob_to_pattern("thing?.*")) end); - end) + describe("#resolve_relative_path()", function () it("returns absolute paths as-is", function () if sep == "/" then -- cgit v1.2.3