comparison mod_compliance_2021/mod_compliance_2021.lua @ 4411:c3d21182ebf3

mod_compliance_2021: XEP-0443: XMPP Compliance Suites 2021 self-test
author Kim Alvefur <zash@zash.se>
date Sat, 30 Jan 2021 01:10:06 +0100
parents
children 3a42789d7235
comparison
equal deleted inserted replaced
4410:d1230d32d709 4411:c3d21182ebf3
1 -- Copyright (c) 2021 Kim Alvefur
2 --
3 -- This module is MIT licensed.
4
5 local hostmanager = require "core.hostmanager";
6
7 local array = require "util.array";
8 local set = require "util.set";
9
10 local modules_enabled = module:get_option_inherited_set("modules_enabled");
11
12 for host in pairs(hostmanager.get_children(module.host)) do
13 local component = module:context(host):get_option_string("component_module");
14 if component then
15 modules_enabled:add(component);
16 modules_enabled:include(module:context(host):get_option_set("modules_enabled", {}));
17 end
18 end
19
20 local function check(suggested, alternate, ...)
21 if set.intersection(modules_enabled, set.new({suggested; alternate; ...})):empty() then return suggested; end
22 return false;
23 end
24
25 local compliance = {
26 array {"Core Server"; check("tls"); check("disco")};
27
28 array {"Advanced Server"; check("pep", "pep_simple")};
29
30 array {"Core Web"; check("bosh"); check("websocket")};
31
32 -- No Server requirements for Advanced Web
33
34 array {"Core IM"; check("vcard_legacy", "vcard"); check("carbons"); check("http_file_share", "http_upload")};
35
36 array {
37 "Advanced IM";
38 check("vcard_legacy", "vcard");
39 check("blocklist");
40 check("muc");
41 check("private");
42 check("smacks");
43 check("mam");
44 check("bookmarks");
45 };
46
47 array {"Core Mobile"; check("smacks"); check("csi_simple", "csi_battery_saver")};
48
49 array {"Advanced Mobile"; check("cloud_notify")};
50
51 array {"Core A/V Calling"; check("external_services", "turncredentials", "extdisco")};
52
53 };
54
55 function check_compliance()
56 local compliant = true;
57 for _, suite in ipairs(compliance) do
58 local section = suite:pop(1);
59 if module:get_option_boolean("compliance_" .. section:lower():gsub("%A", "_"), true) then
60 local missing = set.new(suite:filter(function(m) return type(m) == "string" end):map(function(m) return "mod_" .. m end));
61 if suite[1] then
62 if compliant then
63 compliant = false;
64 module:log("warn", "Missing some modules for XMPP Compliance 2021");
65 end
66 module:log("info", "%s Compliance: %s", section, missing);
67 end
68 end
69 end
70
71 if compliant then module:log("info", "XMPP Compliance 2021: Compliant ✔️"); end
72 end
73
74 if prosody.start_time then
75 check_compliance()
76 else
77 module:hook_global("server-started", check_compliance);
78 end
79