| 1 | local harness = require "harness"; |
| 2 | |
| 3 | return { |
| 4 | { "discovers server identity and features", function (t) |
| 5 | t.client("alice", function (c) |
| 6 | c:disco_info(harness.domain, nil, t.cb(function (info, err) |
| 7 | assert(info, "disco#info failed: "..tostring(err)); |
| 8 | assert(info.identities["server/im"], "no server/im identity"); |
| 9 | assert(info.features["urn:xmpp:ping"], "ping feature not advertised"); |
| 10 | assert(c:jid_supports(harness.domain, "urn:xmpp:ping"), "cache not populated"); |
| 11 | t.done(); |
| 12 | end)); |
| 13 | end, { plugins = { "disco" } }); |
| 14 | end }; |
| 15 | |
| 16 | { "lists the server's components", function (t) |
| 17 | t.client("alice", function (c) |
| 18 | c:disco_items(harness.domain, nil, t.cb(function (items, err) |
| 19 | assert(items, "disco#items failed: "..tostring(err)); |
| 20 | local found = {}; |
| 21 | for _, item in ipairs(items) do found[item.jid] = true; end |
| 22 | assert(found["conference."..harness.domain], "MUC component not listed"); |
| 23 | assert(found["pubsub."..harness.domain], "pubsub component not listed"); |
| 24 | t.done(); |
| 25 | end)); |
| 26 | end, { plugins = { "disco" } }); |
| 27 | end }; |
| 28 | |
| 29 | { "finds local services by identity after the initial disco", function (t) |
| 30 | t.client("alice", function (c) |
| 31 | -- The disco plugin re-fires "ready" once it has queried all local services |
| 32 | local services = assert(c:get_local_services("conference", "text")); |
| 33 | assert(services[1] == "conference."..harness.domain, "MUC service not found"); |
| 34 | t.done(); |
| 35 | end, { plugins = { "disco" } }); |
| 36 | end }; |
| 37 | |
| 38 | { "answers disco#info queries with its own features", function (t) |
| 39 | t.client("alice", function (alice) |
| 40 | alice:add_disco_feature("urn:example:verse-test"); |
| 41 | t.client("bob", function (bob) |
| 42 | bob:disco_info(alice.jid, nil, t.cb(function (info, err) |
| 43 | assert(info, "disco#info failed: "..tostring(err)); |
| 44 | assert(info.identities["client/pc"], "no client identity"); |
| 45 | assert(info.features["urn:example:verse-test"], "custom feature missing"); |
| 46 | t.done(); |
| 47 | end)); |
| 48 | end, { plugins = { "disco" } }); |
| 49 | end, { plugins = { "disco" } }); |
| 50 | end }; |
| 51 | }; |