Annotate

spec/util_sasl_spec.lua @ 11749:83d6d6a70edf

net.http: fail open if surrounding code does not configure TLS Previously, if surrounding code was not configuring the TLS context used default in net.http, it would not validate certificates at all. This is not a security issue with prosody, because prosody updates the context with `verify = "peer"` as well as paths to CA certificates in util.startup.init_http_client. Nevertheless... Let's not leave this pitfall out there in the open.
author Jonas Schäfer <jonas@wielicki.name>
date Sun, 29 Aug 2021 15:04:47 +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