Annotate

spec/util_rsm_spec.lua @ 11039:ec6919401790

mod_external_services: Allow specifying a credential generation callback This is especially targeted at services added via the items API. More involved credential generation should use the event hook.
author Kim Alvefur <zash@zash.se>
date Sat, 25 Jul 2020 12:22:03 +0200
parent 10762:4fc224c97986
child 11427:83f5499d1f10
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10760
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local rsm = require "util.rsm";
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local xml = require "util.xml";
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 local function strip(s)
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 return (s:gsub(">%s+<", "><"));
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 end
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 describe("util.rsm", function ()
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 describe("parse", function ()
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 it("works", function ()
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 local test = xml.parse(strip([[
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 <set xmlns='http://jabber.org/protocol/rsm'>
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 <max>10</max>
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 </set>
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 ]]));
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 assert.same({ max = 10 }, rsm.parse(test));
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 end);
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 it("works", function ()
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 local test = xml.parse(strip([[
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 <set xmlns='http://jabber.org/protocol/rsm'>
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 <first index='0'>saint@example.org</first>
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 <last>peterpan@neverland.lit</last>
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 <count>800</count>
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 </set>
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 ]]));
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 assert.same({ first = { index = 0, "saint@example.org" }, last = "peterpan@neverland.lit", count = 800 }, rsm.parse(test));
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 end);
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 it("works", function ()
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 local test = xml.parse(strip([[
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 <set xmlns='http://jabber.org/protocol/rsm'>
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 <max>10</max>
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 <before>peter@pixyland.org</before>
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 </set>
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 ]]));
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 assert.same({ max = 10, before = "peter@pixyland.org" }, rsm.parse(test));
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 end);
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 end);
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 describe("generate", function ()
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43 it("works", function ()
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 local test = xml.parse(strip([[
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45 <set xmlns='http://jabber.org/protocol/rsm'>
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 <max>10</max>
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 </set>
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
48 ]]));
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
49 local res = rsm.generate({ max = 10 });
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
50 assert.same(test:get_child_text("max"), res:get_child_text("max"));
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
51 end);
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
52
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
53 it("works", function ()
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
54 local test = xml.parse(strip([[
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
55 <set xmlns='http://jabber.org/protocol/rsm'>
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
56 <first index='0'>saint@example.org</first>
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
57 <last>peterpan@neverland.lit</last>
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
58 <count>800</count>
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
59 </set>
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
60 ]]));
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
61 local res = rsm.generate({ first = { index = 0, "saint@example.org" }, last = "peterpan@neverland.lit", count = 800 });
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
62 assert.same(test:get_child("first").attr.index, res:get_child("first").attr.index);
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
63 assert.same(test:get_child_text("first"), res:get_child_text("first"));
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
64 assert.same(test:get_child_text("last"), res:get_child_text("last"));
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
65 assert.same(test:get_child_text("count"), res:get_child_text("count"));
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
66 end);
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
67
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
68 it("works", function ()
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
69 local test = xml.parse(strip([[
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
70 <set xmlns='http://jabber.org/protocol/rsm'>
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
71 <max>10</max>
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
72 <before>peter@pixyland.org</before>
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
73 </set>
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
74 ]]));
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
75 local res = rsm.generate({ max = 10, before = "peter@pixyland.org" });
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
76 assert.same(test:get_child_text("max"), res:get_child_text("max"));
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
77 assert.same(test:get_child_text("before"), res:get_child_text("before"));
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
78 end);
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
79
10762
4fc224c97986 util.rsm: Test that Lua 5.3 floats are not encoded with decimal point
Kim Alvefur <zash@zash.se>
parents: 10760
diff changeset
80 it("handles floats", function ()
4fc224c97986 util.rsm: Test that Lua 5.3 floats are not encoded with decimal point
Kim Alvefur <zash@zash.se>
parents: 10760
diff changeset
81 local r1 = rsm.generate({ max = 10.0, count = 100.0, first = { index = 1.0, "foo" } });
4fc224c97986 util.rsm: Test that Lua 5.3 floats are not encoded with decimal point
Kim Alvefur <zash@zash.se>
parents: 10760
diff changeset
82 assert.equal("10", r1:get_child_text("max"));
4fc224c97986 util.rsm: Test that Lua 5.3 floats are not encoded with decimal point
Kim Alvefur <zash@zash.se>
parents: 10760
diff changeset
83 assert.equal("100", r1:get_child_text("count"));
4fc224c97986 util.rsm: Test that Lua 5.3 floats are not encoded with decimal point
Kim Alvefur <zash@zash.se>
parents: 10760
diff changeset
84 assert.equal("1", r1:get_child("first").attr.index);
4fc224c97986 util.rsm: Test that Lua 5.3 floats are not encoded with decimal point
Kim Alvefur <zash@zash.se>
parents: 10760
diff changeset
85 end);
4fc224c97986 util.rsm: Test that Lua 5.3 floats are not encoded with decimal point
Kim Alvefur <zash@zash.se>
parents: 10760
diff changeset
86
10760
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
87 end);
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
88 end);
c9d1d9c80e1e util.rsm: Add tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
89