diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/scansion/bookmarks2.scs | 181 | ||||
-rw-r--r-- | spec/scansion/prosody.cfg.lua | 2 | ||||
-rw-r--r-- | spec/scansion/pubsub_config.scs | 2 | ||||
-rw-r--r-- | spec/scansion/pubsub_max_items.scs | 1 | ||||
-rw-r--r-- | spec/scansion/pubsub_multi_items.scs | 1 | ||||
-rw-r--r-- | spec/scansion/pubsub_preconditions.scs | 2 | ||||
-rw-r--r-- | spec/util_crypto_spec.lua | 21 | ||||
-rw-r--r-- | spec/util_error_spec.lua | 14 | ||||
-rw-r--r-- | spec/util_pubsub_spec.lua | 12 | ||||
-rw-r--r-- | spec/util_queue_spec.lua | 19 | ||||
-rw-r--r-- | spec/util_xtemplate_spec.lua | 4 |
11 files changed, 251 insertions, 8 deletions
diff --git a/spec/scansion/bookmarks2.scs b/spec/scansion/bookmarks2.scs new file mode 100644 index 00000000..0243ca54 --- /dev/null +++ b/spec/scansion/bookmarks2.scs @@ -0,0 +1,181 @@ +# Pubsub: Bookmarks 2.0 + +[Client] Juliet + jid: admin@localhost + password: password + +// admin@localhost is assumed to have node creation privileges + +--------- + +Juliet connects + +-- Generated with https://gitlab.com/xmpp-rs/xmpp-parsers: +-- cargo run --example=generate-caps https://code.matthewwild.co.uk/scansion/ <<< "<query xmlns='http://jabber.org/protocol/disco#info'><identity category='client' name='scansion' type='bot'/><feature var='http://jabber.org/protocol/disco#info'/><feature var='urn:xmpp:bookmarks:1+notify'/></query>" +Juliet sends: + <presence id='presence0'> + <c xmlns='http://jabber.org/protocol/caps' + hash='sha-1' + node='https://code.matthewwild.co.uk/scansion/' + ver='CPuQARM1gCTq2f6/ZjHUzWL2QHg='/> + <c xmlns='urn:xmpp:caps'> + <hash xmlns='urn:xmpp:hashes:2' algo='sha-256'>OTy9GPCvBZRvqzOHmD/ThA1WbBH3tNoeKbdqKQCRPHc=</hash> + <hash xmlns='urn:xmpp:hashes:2' algo='sha3-256'>f/rxDeTf6HyjQ382V3GEG/UfAs5IeclC05jBSBnVQCI=</hash> + <hash xmlns='urn:xmpp:hashes:2' algo='blake2b-256'>ucfqg/NrLj0omE+26hYMrbpcmxHcU4Z3hfAQIF+6tt0=</hash> + </c> + </presence> + +Juliet receives: + <iq from="${Juliet's JID}" id='disco' type='get'> + <query xmlns='http://jabber.org/protocol/disco#info' node='https://code.matthewwild.co.uk/scansion/#CPuQARM1gCTq2f6/ZjHUzWL2QHg='/> + </iq> + +Juliet sends: + <iq to="${Juliet's JID}" id='disco' type='result'> + <query xmlns='http://jabber.org/protocol/disco#info' node='https://code.matthewwild.co.uk/scansion/#CPuQARM1gCTq2f6/ZjHUzWL2QHg='> + <identity category='client' name='scansion' type='bot'/> + <feature var='http://jabber.org/protocol/disco#info'/> + <feature var='urn:xmpp:bookmarks:1+notify'/> + </query> + </iq> + +Juliet sends: + <iq type='set' id='pub0'> + <pubsub xmlns='http://jabber.org/protocol/pubsub'> + <publish node='urn:xmpp:bookmarks:1'> + <item id='theplay@conference.shakespeare.lit'> + <conference xmlns='urn:xmpp:bookmarks:1' + name='The Play's the Thing' + autojoin='true'> + <nick>JC</nick> + </conference> + </item> + </publish> + <publish-options> + <x xmlns='jabber:x:data' type='submit'> + <field var='FORM_TYPE' type='hidden'> + <value>http://jabber.org/protocol/pubsub#publish-options</value> + </field> + <field var='pubsub#persist_items'> + <value>true</value> + </field> + <field var='pubsub#max_items'> + <value>255</value> + </field> + <field var='pubsub#send_last_published_item'> + <value>never</value> + </field> + <field var='pubsub#access_model'> + <value>whitelist</value> + </field> + </x> + </publish-options> + </pubsub> + </iq> + +Juliet receives: + <message type='headline' from="${Juliet's JID}"> + <event xmlns='http://jabber.org/protocol/pubsub#event'> + <items node='urn:xmpp:bookmarks:1'> + <item id='theplay@conference.shakespeare.lit'> + <conference xmlns='urn:xmpp:bookmarks:1' + name='The Play's the Thing' + autojoin='true'> + <nick>JC</nick> + </conference> + </item> + </items> + </event> + </message> + +Juliet receives: + <iq type='result' id='pub0'> + <pubsub xmlns='http://jabber.org/protocol/pubsub'> + <publish node='urn:xmpp:bookmarks:1'> + <item id='theplay@conference.shakespeare.lit'/> + </publish> + </pubsub> + </iq> + +Juliet sends: + <iq type='set' id='pub1'> + <pubsub xmlns='http://jabber.org/protocol/pubsub'> + <publish node='urn:xmpp:bookmarks:1'> + <item id='orchard@conference.shakespeare.lit'> + <conference xmlns='urn:xmpp:bookmarks:1' + name='The Orchard' + autojoin='true'> + <nick>JC</nick> + </conference> + </item> + </publish> + <publish-options> + <x xmlns='jabber:x:data' type='submit'> + <field var='FORM_TYPE' type='hidden'> + <value>http://jabber.org/protocol/pubsub#publish-options</value> + </field> + <field var='pubsub#persist_items'> + <value>true</value> + </field> + <field var='pubsub#max_items'> + <value>255</value> + </field> + <field var='pubsub#send_last_published_item'> + <value>never</value> + </field> + <field var='pubsub#access_model'> + <value>whitelist</value> + </field> + </x> + </publish-options> + </pubsub> + </iq> + +Juliet receives: + <message type='headline' from="${Juliet's JID}"> + <event xmlns='http://jabber.org/protocol/pubsub#event'> + <items node='urn:xmpp:bookmarks:1'> + <item id='orchard@conference.shakespeare.lit'> + <conference xmlns='urn:xmpp:bookmarks:1' + name='The Orchard' + autojoin='true'> + <nick>JC</nick> + </conference> + </item> + </items> + </event> + </message> + +Juliet receives: + <iq type='result' id='pub1'> + <pubsub xmlns='http://jabber.org/protocol/pubsub'> + <publish node='urn:xmpp:bookmarks:1'> + <item id='orchard@conference.shakespeare.lit'/> + </publish> + </pubsub> + </iq> + +Juliet sends: + <iq type='set' id='retract0'> + <pubsub xmlns='http://jabber.org/protocol/pubsub'> + <retract node='urn:xmpp:bookmarks:1' notify='1'> + <item id='theplay@conference.shakespeare.lit'/> + </retract> + </pubsub> + </iq> + +Juliet receives: + <message type='headline' from="${Juliet's JID}"> + <event xmlns='http://jabber.org/protocol/pubsub#event'> + <items node='urn:xmpp:bookmarks:1'> + <retract id='theplay@conference.shakespeare.lit'/> + </items> + </event> + </message> + +Juliet receives: + <iq type='result' id='retract0'/> + +Juliet disconnects + +// vim: syntax=xml: diff --git a/spec/scansion/prosody.cfg.lua b/spec/scansion/prosody.cfg.lua index 48183fc7..58889fd7 100644 --- a/spec/scansion/prosody.cfg.lua +++ b/spec/scansion/prosody.cfg.lua @@ -103,6 +103,8 @@ storage = "memory" mam_smart_enable = true +bounce_blocked_messages = true + -- For the "sql" backend, you can uncomment *one* of the below to configure: --sql = { driver = "SQLite3", database = "prosody.sqlite" } -- Default. 'database' is the filename. --sql = { driver = "MySQL", database = "prosody", username = "prosody", password = "secret", host = "localhost" } diff --git a/spec/scansion/pubsub_config.scs b/spec/scansion/pubsub_config.scs index 57f275cd..a2b2ab68 100644 --- a/spec/scansion/pubsub_config.scs +++ b/spec/scansion/pubsub_config.scs @@ -74,6 +74,7 @@ Romeo receives: </option> <value>presence</value> </field> + <field type="list-multi" var="pubsub#roster_groups_allowed" label="Roster groups allowed to subscribe"/> <field var="pubsub#publish_model" label="Specify the publisher model" type="list-single"> <option label="publishers"> <value>publishers</value> @@ -176,6 +177,7 @@ Romeo sends: </option> <value>presence</value> </field> + <field type="list-multi" var="pubsub#roster_groups_allowed" label="Roster groups allowed to subscribe"/> <field var="pubsub#publish_model" type="list-single" label="Specify the publisher model"> <option label="publishers"> <value>publishers</value> diff --git a/spec/scansion/pubsub_max_items.scs b/spec/scansion/pubsub_max_items.scs index 31480b2e..b0ead5bf 100644 --- a/spec/scansion/pubsub_max_items.scs +++ b/spec/scansion/pubsub_max_items.scs @@ -69,6 +69,7 @@ Alice receives: </option> <value>open</value> </field> + <field type="list-multi" var="pubsub#roster_groups_allowed" label="Roster groups allowed to subscribe"/> <field var="pubsub#publish_model" label="Specify the publisher model" type="list-single"> <option label="publishers"> <value>publishers</value> diff --git a/spec/scansion/pubsub_multi_items.scs b/spec/scansion/pubsub_multi_items.scs index 7f365b94..8c6872e4 100644 --- a/spec/scansion/pubsub_multi_items.scs +++ b/spec/scansion/pubsub_multi_items.scs @@ -69,6 +69,7 @@ Alice receives: </option> <value>open</value> </field> + <field type="list-multi" var="pubsub#roster_groups_allowed" label="Roster groups allowed to subscribe"/> <field var="pubsub#publish_model" label="Specify the publisher model" type="list-single"> <option label="publishers"> <value>publishers</value> diff --git a/spec/scansion/pubsub_preconditions.scs b/spec/scansion/pubsub_preconditions.scs index 286e84d6..fe056fc6 100644 --- a/spec/scansion/pubsub_preconditions.scs +++ b/spec/scansion/pubsub_preconditions.scs @@ -73,6 +73,7 @@ Romeo receives: </option> <value>presence</value> </field> + <field type="list-multi" var="pubsub#roster_groups_allowed" label="Roster groups allowed to subscribe"/> <field var="pubsub#publish_model" label="Specify the publisher model" type="list-single"> <option label="publishers"> <value>publishers</value> @@ -175,6 +176,7 @@ Romeo sends: </option> <value>presence</value> </field> + <field type="list-multi" var="pubsub#roster_groups_allowed" label="Roster groups allowed to subscribe"/> <field var="pubsub#publish_model" type="list-single" label="Specify the publisher model"> <option label="publishers"> <value>publishers</value> diff --git a/spec/util_crypto_spec.lua b/spec/util_crypto_spec.lua index 77d046ac..4a62e0bc 100644 --- a/spec/util_crypto_spec.lua +++ b/spec/util_crypto_spec.lua @@ -3,6 +3,7 @@ local test_keys = require "spec.inputs.test_keys"; describe("util.crypto", function () local crypto = require "util.crypto"; local random = require "util.random"; + local encodings = require "util.encodings"; describe("generate_ed25519_keypair", function () local keypair = crypto.generate_ed25519_keypair(); @@ -10,6 +11,26 @@ describe("util.crypto", function () assert.equal("ED25519", keypair:get_type()); end) + describe("generate_p256_keypair", function () + local keypair = crypto.generate_p256_keypair(); + assert.is_not_nil(keypair); + assert.equal("id-ecPublicKey", keypair:get_type()); + end) + + describe("export/import raw", function () + local keypair = crypto.generate_p256_keypair(); + assert.is_not_nil(keypair); + local raw = keypair:public_raw() + local imported = crypto.import_public_ec_raw(raw, "P-256") + assert.equal(keypair:public_pem(), imported:public_pem()); + end) + + describe("derive", function () + local key = crypto.import_private_pem(test_keys.ecdsa_private_pem); + local peer_key = crypto.import_public_pem(test_keys.ecdsa_public_pem); + assert.equal("n1v4KeKmOVwjC67fiKtjJnqcEaasbpZa2fLPNHW51co=", encodings.base64.encode(key:derive(peer_key))) + end) + describe("import_private_pem", function () it("can import ECDSA keys", function () local ecdsa_key = crypto.import_private_pem(test_keys.ecdsa_private_pem); diff --git a/spec/util_error_spec.lua b/spec/util_error_spec.lua index ebe8bff7..cd30ee94 100644 --- a/spec/util_error_spec.lua +++ b/spec/util_error_spec.lua @@ -29,10 +29,10 @@ describe("util.error", function () end); - describe("is_err()", function () + describe("is_error()", function () it("works", function () - assert.truthy(errors.is_err(errors.new())); - assert.falsy(errors.is_err("not an error")); + assert.truthy(errors.is_error(errors.new())); + assert.falsy(errors.is_error("not an error")); end); end); @@ -40,7 +40,7 @@ describe("util.error", function () it("works", function () local ok, err = errors.coerce(nil, "it dun goofed"); assert.is_nil(ok); - assert.truthy(errors.is_err(err)) + assert.truthy(errors.is_error(err)) end); end); @@ -50,7 +50,7 @@ describe("util.error", function () local m = st.message({ type = "chat" }); 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.truthy(errors.is_error(err)); assert.equal("modify", err.type); assert.equal("bad-request", err.condition); assert.equal(e, err.context.stanza); @@ -187,7 +187,7 @@ describe("util.error", function () end local ok, err = reg.coerce(test()); assert.is_nil(ok); - assert.is_truthy(errors.is_err(err)); + assert.is_truthy(errors.is_error(err)); assert.equal("forbidden", err.condition); end); @@ -208,7 +208,7 @@ describe("util.error", function () end local ok, err = reg.coerce(test()); assert.is_nil(ok); - assert.is_truthy(errors.is_err(err)); + assert.is_truthy(errors.is_error(err)); assert.equal("internal-server-error", err.condition); assert.equal("Oh no", err.text); end); diff --git a/spec/util_pubsub_spec.lua b/spec/util_pubsub_spec.lua index 45a612a0..a03ffa64 100644 --- a/spec/util_pubsub_spec.lua +++ b/spec/util_pubsub_spec.lua @@ -108,7 +108,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.pubsub_condition); + assert.equals("precondition-not-met", err); end); it("allows to publish to a node with differing config when only defaults are suggested", function () @@ -605,4 +605,14 @@ describe("util.pubsub", function () end); end) + + describe("metadata", function() + it("works", function() + local service = pubsub.new { metadata_subset = { "title" } }; + assert.truthy(service:create("node", true, { title = "Hello", secret = "hidden" })) + local ok, meta = service:get_node_metadata("node", "nobody"); + assert.truthy(ok, meta); + assert.same({ title = "Hello" }, meta); + end) + end); end); diff --git a/spec/util_queue_spec.lua b/spec/util_queue_spec.lua index d73f523d..d9e92e3d 100644 --- a/spec/util_queue_spec.lua +++ b/spec/util_queue_spec.lua @@ -137,4 +137,23 @@ describe("util.queue", function() assert.equal(c, 6); end); end); + describe("replace()", function () + it("should work", function () + local q = queue.new(10); + for i = 1, 5 do + q:push(i); + end + q:replace(6); + local c = 0; + for i in q:consume() do + c = c + 1; + if c > 1 then + assert.is_equal(c, i); + elseif c == 1 then + assert.is_equal(6, i); + end + end + assert.is_equal(5, c); + end); + end); end); diff --git a/spec/util_xtemplate_spec.lua b/spec/util_xtemplate_spec.lua index 4561378e..421be43f 100644 --- a/spec/util_xtemplate_spec.lua +++ b/spec/util_xtemplate_spec.lua @@ -38,6 +38,10 @@ describe("util.xtemplate", function () x:reset(); assert.same("12345", xtemplate.render("{foo/bar|each(i){{#}}}", x)); end) + it("handles missing inputs", function () + local x = st.stanza("root"); + assert.same("", xtemplate.render("{foo/bar|each(i){{#}}}", x)); + end) end) end) end) |