Annotate

spec/util_sasl_spec.lua @ 11245:43b43e7156b8

MUC: Add support for presence probes (fixes #1535) The following patch allows Prosody to respond to `probe` presences and send out the probed occupant's current presence. This is based on line 17.3 in XEP-0045: A MUC service MAY handle presence probes sent to the room JID <room@service> or an occupant JID <room@service/nick> (e.g, these might be sent by an occupant's home server to determine if the room is still online or to synchronize presence information if the user or the user's server has gone offline temporarily or has started sharing presence again, as for instance when Stanza Interception and Filtering Technology (XEP-0273) is used).
author JC Brand <jc@opkode.com>
date Sun, 19 Apr 2020 21:49:45 +0200
parent 10502:f1c0aa521dd5
child 13113:191fe4866e3e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10502
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local sasl = require "util.sasl";
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 -- profile * mechanism
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 -- callbacks could use spies instead
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 describe("util.sasl", function ()
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 describe("plain_test profile", function ()
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 local profile = {
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 plain_test = function (_, username, password, realm)
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 assert.equals("user", username)
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 assert.equals("pencil", password)
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 assert.equals("sasl.test", realm)
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 return true, true;
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 end;
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 };
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 it("works with PLAIN", function ()
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 local plain = sasl.new("sasl.test", profile);
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 assert.truthy(plain:select("PLAIN"));
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 assert.truthy(plain:process("\000user\000pencil"));
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 assert.equals("user", plain.username);
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 end);
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 end);
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 describe("plain profile", function ()
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 local profile = {
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 plain = function (_, username, realm)
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 assert.equals("user", username)
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 assert.equals("sasl.test", realm)
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 return "pencil", true;
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 end;
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 };
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 it("works with PLAIN", function ()
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 local plain = sasl.new("sasl.test", profile);
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 assert.truthy(plain:select("PLAIN"));
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 assert.truthy(plain:process("\000user\000pencil"));
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 assert.equals("user", plain.username);
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 end);
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 -- TODO SCRAM
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 end);
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 end);
f1c0aa521dd5 util.sasl: Add stub tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43