1: -module(config_parser_SUITE).
    2: -compile([export_all, nowarn_export_all]).
    3: 
    4: -include_lib("eunit/include/eunit.hrl").
    5: 
    6: -define(HOST, <<"example.com">>).
    7: 
    8: -define(eq(Expected, Actual), ?assertEqual(Expected, Actual)).
    9: 
   10: %% Assertions
   11: 
   12: %% global config options
   13: -define(cfg(Key, Value, RawConfig), ?cfg([{Key, Value}], RawConfig)).
   14: -define(cfg(ExpectedOpts, RawConfig), assert_options(ExpectedOpts, parse(RawConfig))).
   15: 
   16: %% global config error
   17: -define(err(RawConfig), ?err(_, RawConfig)).
   18: -define(err(Pattern, RawConfig), ?assertError({config_error, _, Pattern}, parse(RawConfig))).
   19: 
   20: %% host-or-global config options
   21: -define(cfgh(KeyPrefix, Value, RawConfig), ?cfgh([{KeyPrefix, Value}], RawConfig)).
   22: -define(cfgh(ExpectedOpts, RawConfig),
   23:         begin
   24:             ?cfg(host_opts(ExpectedOpts), RawConfig),
   25:             ?cfg(host_opts(ExpectedOpts), host_config(RawConfig))
   26:         end).
   27: 
   28: %% host-or-global config error
   29: -define(errh(RawConfig), ?errh(_, RawConfig)).
   30: -define(errh(Pattern, RawConfig),
   31:         begin
   32:             ?err(Pattern, RawConfig),
   33:             ?err(Pattern, host_config(RawConfig))
   34:         end).
   35: 
   36: -import(mongoose_config_parser_toml, [extract_errors/1]).
   37: -import(config_parser_helper, [default_s2s/0,
   38:                                extra_service_listener_config/0,
   39:                                mod_event_pusher_http_handler/0,
   40:                                default_c2s_tls/1,
   41:                                mod_config/2, default_mod_config/1,
   42:                                config/2, default_config/1]).
   43: 
   44: -type key_prefix() :: top_level_key_prefix() | key_path_prefix().
   45: -type top_level_key_prefix() :: atom().
   46: -type key_path_prefix() :: [atom() | binary()].
   47: 
   48: all() ->
   49:     [{group, file},
   50:      {group, dynamic_domains},
   51:      {group, general},
   52:      {group, listen},
   53:      {group, auth},
   54:      {group, pool},
   55:      {group, shaper_acl_access},
   56:      {group, s2s},
   57:      {group, modules},
   58:      {group, services}].
   59: 
   60: groups() ->
   61:     [{file, [parallel], [sample_pgsql,
   62:                          miscellaneous,
   63:                          s2s,
   64:                          modules,
   65:                          outgoing_pools,
   66:                          host_types_file]},
   67:      {dynamic_domains, [parallel], [supported_features,
   68:                                     unsupported_features]},
   69:      {general, [parallel], [loglevel,
   70:                             hosts,
   71:                             host_types,
   72:                             default_server_domain,
   73:                             registration_timeout,
   74:                             language,
   75:                             all_metrics_are_global,
   76:                             sm_backend,
   77:                             max_fsm_queue,
   78:                             http_server_name,
   79:                             rdbms_server_type,
   80:                             route_subdomains,
   81:                             mongooseimctl_access_commands,
   82:                             routing_modules,
   83:                             replaced_wait_timeout,
   84:                             hide_service_name,
   85:                             domain_certfile]},
   86:      {listen, [parallel], [listen_duplicate,
   87:                            listen_c2s,
   88:                            listen_c2s_fast_tls,
   89:                            listen_c2s_just_tls,
   90:                            listen_s2s,
   91:                            listen_s2s_tls,
   92:                            listen_service,
   93:                            listen_http,
   94:                            listen_http_tls,
   95:                            listen_http_transport,
   96:                            listen_http_handlers_invalid,
   97:                            listen_http_handlers_bosh,
   98:                            listen_http_handlers_websockets,
   99:                            listen_http_handlers_client_api,
  100:                            listen_http_handlers_api,
  101:                            listen_http_handlers_api_admin,
  102:                            listen_http_handlers_api_client,
  103:                            listen_http_handlers_domain,
  104:                            listen_http_handlers_graphql]},
  105:      {auth, [parallel], [auth_methods,
  106:                          auth_password,
  107:                          auth_sasl_external,
  108:                          auth_allow_multiple_connections,
  109:                          auth_anonymous_protocol,
  110:                          auth_sasl_mechanisms,
  111:                          auth_ldap_pool,
  112:                          auth_ldap_bind_pool,
  113:                          auth_ldap_base,
  114:                          auth_ldap_uids,
  115:                          auth_ldap_filter,
  116:                          auth_ldap_dn_filter,
  117:                          auth_ldap_local_filter,
  118:                          auth_ldap_deref,
  119:                          auth_external,
  120:                          auth_http_basic_auth,
  121:                          auth_jwt,
  122:                          auth_riak_bucket_type,
  123:                          auth_rdbms_users_number_estimate,
  124:                          auth_dummy]},
  125:      {pool, [parallel], [pool_basics,
  126:                          pool_scope,
  127:                          pool_rdbms,
  128:                          pool_rdbms_connection_odbc,
  129:                          pool_rdbms_connection_pgsql,
  130:                          pool_rdbms_connection_mysql,
  131:                          pool_rdbms_connection_tls_pgsql,
  132:                          pool_rdbms_connection_tls_mysql,
  133:                          pool_http,
  134:                          pool_http_connection,
  135:                          pool_http_connection_tls,
  136:                          pool_redis,
  137:                          pool_redis_connection,
  138:                          pool_riak,
  139:                          pool_riak_connection,
  140:                          pool_riak_connection_credentials,
  141:                          pool_riak_connection_tls,
  142:                          pool_cassandra,
  143:                          pool_cassandra_connection,
  144:                          pool_cassandra_connection_auth_plain,
  145:                          pool_cassandra_connection_servers,
  146:                          pool_cassandra_connection_tls,
  147:                          pool_elastic,
  148:                          pool_elastic_connection,
  149:                          pool_rabbit,
  150:                          pool_rabbit_connection,
  151:                          pool_ldap,
  152:                          pool_ldap_connection]},
  153:      {shaper_acl_access, [parallel], [shaper,
  154:                                       acl,
  155:                                       acl_merge_host_and_global,
  156:                                       access,
  157:                                       access_merge_host_and_global]},
  158:      {s2s, [parallel], [s2s_host_config,
  159:                         s2s_dns_timeout,
  160:                         s2s_dns_retries,
  161:                         s2s_outgoing_port,
  162:                         s2s_outgoing_ip_versions,
  163:                         s2s_outgoing_timeout,
  164:                         s2s_use_starttls,
  165:                         s2s_certfile,
  166:                         s2s_default_policy,
  167:                         s2s_host_policy,
  168:                         s2s_address,
  169:                         s2s_ciphers,
  170:                         s2s_shared,
  171:                         s2s_max_retry_delay]},
  172:      {modules, [parallel], [mod_adhoc,
  173:                             mod_auth_token,
  174:                             mod_blocking,
  175:                             mod_bosh,
  176:                             mod_caps,
  177:                             mod_cache_users,
  178:                             mod_carboncopy,
  179:                             mod_csi,
  180:                             mod_disco,
  181:                             mod_inbox,
  182:                             mod_global_distrib,
  183:                             mod_global_distrib_connections,
  184:                             mod_global_distrib_connections_endpoints,
  185:                             mod_global_distrib_connections_advertised_endpoints,
  186:                             mod_global_distrib_connections_tls,
  187:                             mod_global_distrib_redis,
  188:                             mod_global_distrib_cache,
  189:                             mod_global_distrib_bounce,
  190:                             mod_event_pusher_sns,
  191:                             mod_event_pusher_push,
  192:                             mod_event_pusher_http,
  193:                             mod_event_pusher_rabbit,
  194:                             mod_extdisco,
  195:                             mod_http_upload,
  196:                             mod_http_upload_s3,
  197:                             mod_jingle_sip,
  198:                             mod_keystore,
  199:                             mod_keystore_keys,
  200:                             mod_last,
  201:                             mod_mam,
  202:                             mod_mam_riak,
  203:                             mod_mam_pm,
  204:                             mod_mam_muc,
  205:                             mod_muc,
  206:                             mod_muc_default_room,
  207:                             mod_muc_default_room_affiliations,
  208:                             mod_muc_log,
  209:                             mod_muc_log_top_link,
  210:                             mod_muc_light,
  211:                             mod_muc_light_config_schema,
  212:                             mod_offline,
  213:                             mod_offline_chatmarkers,
  214:                             mod_ping,
  215:                             mod_privacy,
  216:                             mod_private,
  217:                             mod_pubsub,
  218:                             mod_pubsub_pep_mapping,
  219:                             mod_pubsub_default_node_config,
  220:                             mod_push_service_mongoosepush,
  221:                             mod_register,
  222:                             mod_roster,
  223:                             mod_shared_roster_ldap,
  224:                             mod_sic,
  225:                             mod_smart_markers,
  226:                             mod_stream_management,
  227:                             mod_stream_management_stale_h,
  228:                             mod_time,
  229:                             mod_vcard,
  230:                             mod_vcard_ldap_uids,
  231:                             mod_vcard_ldap_vcard_map,
  232:                             mod_vcard_ldap_search_fields,
  233:                             mod_vcard_ldap_search_reported,
  234:                             mod_version,
  235:                             modules_without_config,
  236:                             incorrect_module]},
  237:      {services, [parallel], [service_admin_extra,
  238:                              service_domain_db,
  239:                              service_mongoose_system_metrics]}
  240:     ].
  241: 
  242: init_per_suite(Config) ->
  243:     {ok, _} = application:ensure_all_started(jid),
  244:     create_files(Config),
  245:     Config.
  246: 
  247: end_per_suite(_Config) ->
  248:     ok.
  249: 
  250: init_per_group(dynamic_domains, Config) ->
  251:     meck:new(ejabberd_auth_http, [passthrough, no_link]),
  252:     meck:new(mod_test, [non_strict, no_link]),
  253:     meck:expect(ejabberd_auth_http, supported_features, fun() -> [] end),
  254:     meck:expect(mod_test, supported_features, fun() -> [] end),
  255:     Config;
  256: init_per_group(_, Config) ->
  257:     Config.
  258: 
  259: end_per_group(dynamic_domains, _Config) ->
  260:     meck:unload();
  261: end_per_group(_, _Config) ->
  262:     ok.
  263: 
  264: init_per_testcase(_, Config) ->
  265:     Config.
  266: 
  267: end_per_testcase(_, _Config) ->
  268:     ok.
  269: 
  270: sample_pgsql(Config) ->
  271:     test_config_file(Config,  "mongooseim-pgsql").
  272: 
  273: miscellaneous(Config) ->
  274:     test_config_file(Config,  "miscellaneous").
  275: 
  276: s2s(Config) ->
  277:     test_config_file(Config,  "s2s_only").
  278: 
  279: modules(Config) ->
  280:     test_config_file(Config,  "modules").
  281: 
  282: outgoing_pools(Config) ->
  283:     test_config_file(Config,  "outgoing_pools").
  284: 
  285: host_types_file(Config) ->
  286:     test_config_file(Config, "host_types").
  287: 
  288: supported_features(_Config) ->
  289:     Gen = #{<<"general">> => #{<<"host_types">> => [<<"type1">>, <<"type2">>]}},
  290:     Auth = #{<<"auth">> => #{<<"internal">> => #{}}},
  291:     Mod = #{<<"modules">> => #{<<"mod_amp">> => #{}}},
  292:     ?cfg([{auth, <<"type1">>}, methods], [internal], maps:merge(Gen, Auth)),
  293:     ?cfg([{auth, <<"type1">>}, methods], [internal],
  294:          Gen#{<<"host_config">> => [Auth#{<<"host_type">> => <<"type1">>}]}),
  295:     ?cfg([{modules, <<"type1">>}, mod_amp], #{}, maps:merge(Gen, Mod)),
  296:     ?cfg([{modules, <<"type1">>}, mod_amp], #{},
  297:           Gen#{<<"host_config">> => [Mod#{<<"host_type">> => <<"type1">>}]}).
  298: 
  299: unsupported_features(_Config) ->
  300:     % ejabberd_auth_http and mod_test are mocked and they don't support dynamic domains
  301:     Gen = #{<<"general">> => #{<<"host_types">> => [<<"type1">>, <<"type2">>]}},
  302:     Auth = #{<<"auth">> => #{<<"http">> => #{}}},
  303:     Mod = #{<<"modules">> => #{<<"mod_test">> => #{}}},
  304:     ?err([#{reason := dynamic_domains_not_supported,
  305:             unsupported_auth_methods := [http],
  306:             unsupported_modules := []}],
  307:          maps:merge(Gen, Auth)),
  308:     ?err([#{reason := dynamic_domains_not_supported,
  309:             unsupported_auth_methods := [http],
  310:             unsupported_modules := []}],
  311:          Gen#{<<"host_config">> => [Auth#{<<"host_type">> => <<"type1">>}]}),
  312:     ?err([#{reason := dynamic_domains_not_supported,
  313:             unsupported_auth_methods := [],
  314:             unsupported_modules := [mod_test]}],
  315:          maps:merge(Gen, Mod)),
  316:     ?err([#{reason := dynamic_domains_not_supported,
  317:             unsupported_auth_methods := [],
  318:             unsupported_modules := [mod_test]}],
  319:          Gen#{<<"host_config">> => [Mod#{<<"host_type">> => <<"type1">>}]}).
  320: 
  321: %% tests: general
  322: loglevel(_Config) ->
  323:     ?cfg(loglevel, warning, #{}), % default
  324:     ?cfg(loglevel, debug, #{<<"general">> => #{<<"loglevel">> => <<"debug">>}}),
  325:     ?err(#{<<"general">> => #{<<"loglevel">> => <<"bebug">>}}),
  326:     %% make sure non-host options are not accepted in host_config
  327:     ?err(host_config(#{<<"general">> => #{<<"loglevel">> => <<"debug">>}})).
  328: 
  329: hosts(_Config) ->
  330:     ?cfg(hosts, [], % default
  331:          #{<<"general">> => #{<<"host_types">> => [<<"type1">>]}, without => [<<"hosts">>]}),
  332:     ?cfg(hosts, [<<"host1">>],
  333:          #{<<"general">> => #{<<"hosts">> => [<<"host1">>]}}),
  334:     ?cfg(hosts, [<<"host1">>, <<"host2">>],
  335:          #{<<"general">> => #{<<"hosts">> => [<<"host1">>, <<"host2">>]}}),
  336:     ?err(#{<<"general">> => #{<<"hosts">> => [<<"what is this?">>]}}),
  337:     ?err(#{<<"general">> => #{<<"hosts">> => [<<>>]}}),
  338:     ?err(#{<<"general">> => #{<<"hosts">> => [<<"host1">>, <<"host1">>]}}),
  339:     %% at least one host or host_type must be provided
  340:     ?err(#{<<"general">> => #{}, without => [<<"hosts">>]}),
  341:     ?err(#{<<"general">> => #{<<"hosts">> => []}}),
  342:     ?err(#{<<"general">> => #{<<"host_types">> => []}, without => [<<"hosts">>]}),
  343:     ?err(#{<<"general">> => #{<<"hosts">> => [], <<"host_types">> => []}}).
  344: 
  345: host_types(_Config) ->
  346:     ?cfg(host_types, [], #{}), % default
  347:     ?cfg([{host_types, [<<"type 1">>]},
  348:           {hosts, []}],
  349:          #{<<"general">> => #{<<"host_types">> => [<<"type 1">>]}, without => [<<"hosts">>]}),
  350:     ?cfg([{host_types, [<<"type 1">>, <<"type 2">>]},
  351:           {hosts, []}],
  352:          #{<<"general">> => #{<<"host_types">> => [<<"type 1">>, <<"type 2">>],
  353:                               <<"hosts">> => []}}),
  354:     ?err(#{<<"general">> => #{<<"host_types">> => [<<>>]}}),
  355:     ?err(#{<<"general">> => #{<<"host_types">> => [<<"type1">>, <<"type1">>]}}),
  356:     %% either hosts and host_types cannot have the same values
  357:     ?err(#{<<"general">> => #{<<"host_types">> => [<<"type1">>],
  358:                               <<"hosts">> => [<<"type1">>]}}).
  359: 
  360: default_server_domain(_Config) ->
  361:     ?cfg(default_server_domain, <<"host1">>,
  362:          #{<<"general">> => #{<<"default_server_domain">> => <<"host1">>}}),
  363:     ?err(#{<<"general">> => #{<<"default_server_domain">> => <<"what is this?">>}}),
  364:     ?err(#{<<"general">> => #{<<"default_server_domain">> => <<>>}}),
  365:     %% default_server_domain must be provided
  366:     ?err(#{without => [<<"default_server_domain">>]}).
  367: 
  368: registration_timeout(_Config) ->
  369:     ?cfg(registration_timeout, 600, #{}), % default
  370:     ?cfg(registration_timeout, infinity,
  371:          #{<<"general">> => #{<<"registration_timeout">> => <<"infinity">>}}),
  372:     ?cfg(registration_timeout, 300,
  373:          #{<<"general">> => #{<<"registration_timeout">> => 300}}),
  374:     ?err(#{<<"general">> => #{<<"registration_timeout">> => 0}}).
  375: 
  376: language(_Config) ->
  377:     ?cfg(language, <<"en">>, #{}), % default
  378:     ?cfg(language, <<"pl">>, #{<<"general">> => #{<<"language">> => <<"pl">>}}),
  379:     ?err(#{<<"general">> => #{<<"language">> => <<>>}}).
  380: 
  381: all_metrics_are_global(_Config) ->
  382:     ?cfg(all_metrics_are_global, false, #{}), % default
  383:     ?cfg(all_metrics_are_global, true, #{<<"general">> => #{<<"all_metrics_are_global">> => true}}),
  384:     ?err(#{<<"general">> => #{<<"all_metrics_are_global">> => <<"true">>}}).
  385: 
  386: sm_backend(_Config) ->
  387:     ?cfg(sm_backend, mnesia, #{}), % default
  388:     ?cfg(sm_backend, mnesia, #{<<"general">> => #{<<"sm_backend">> => <<"mnesia">>}}),
  389:     ?cfg(sm_backend, redis, #{<<"general">> => #{<<"sm_backend">> => <<"redis">>}}),
  390:     ?err(#{<<"general">> => #{<<"sm_backend">> => <<"amnesia">>}}).
  391: 
  392: max_fsm_queue(_Config) ->
  393:     ?cfg(max_fsm_queue, 100, #{<<"general">> => #{<<"max_fsm_queue">> => 100}}),
  394:     ?err(#{<<"general">> => #{<<"max_fsm_queue">> => -10}}).
  395: 
  396: http_server_name(_Config) ->
  397:     ?cfg(http_server_name, "my server",
  398:          #{<<"general">> => #{<<"http_server_name">> => <<"my server">>}}),
  399:     ?err(#{<<"general">> => #{<<"http_server_name">> => #{}}}).
  400: 
  401: rdbms_server_type(_Config) ->
  402:     ?cfg(rdbms_server_type, generic, #{}), % default
  403:     ?cfg(rdbms_server_type, mssql, #{<<"general">> => #{<<"rdbms_server_type">> => <<"mssql">>}}),
  404:     ?cfg(rdbms_server_type, pgsql, #{<<"general">> => #{<<"rdbms_server_type">> => <<"pgsql">>}}),
  405:     ?err(#{<<"general">> => #{<<"rdbms_server_type">> => <<"nosql">>}}).
  406: 
  407: route_subdomains(_Config) ->
  408:     ?cfgh(route_subdomains, s2s, #{<<"general">> => #{<<"route_subdomains">> => <<"s2s">>}}),
  409:     ?errh(#{<<"general">> => #{<<"route_subdomains">> => <<"c2s">>}}).
  410: 
  411: mongooseimctl_access_commands(_Config) ->
  412:     ?cfg(mongooseimctl_access_commands, #{}, #{}), % default
  413:     P = [mongooseimctl_access_commands, local],
  414:     T = fun(Opts) ->
  415:                 #{<<"general">> => #{<<"mongooseimctl_access_commands">> => #{<<"local">> => Opts}}}
  416:         end,
  417:     ?cfg(P, default_config([general, mongooseimctl_access_commands, local]), T(#{})),
  418:     ?cfg(P ++ [commands], [join_cluster], T(#{<<"commands">> => [<<"join_cluster">>]})),
  419:     ?cfg(P ++ [argument_restrictions], #{node => "mim1@host1"},
  420:          T(#{<<"argument_restrictions">> => #{<<"node">> => <<"mim1@host1">>}})),
  421:     ?err(T(#{<<"commands">> => [<<>>]})),
  422:     ?err(T(#{<<"argument_restrictions">> => #{<<"node">> => 1}})).
  423: 
  424: routing_modules(_Config) ->
  425:     ?cfg(routing_modules, mongoose_router:default_routing_modules(), #{}), % default
  426:     ?cfg(routing_modules, [mongoose_router_global, mongoose_router_localdomain],
  427:          #{<<"general">> => #{<<"routing_modules">> => [<<"mongoose_router_global">>,
  428:                                                         <<"mongoose_router_localdomain">>]}}),
  429:     ?err(#{<<"general">> => #{<<"routing_modules">> => [<<"moongoose_router_global">>]}}).
  430: 
  431: replaced_wait_timeout(_Config) ->
  432:     ?cfg({replaced_wait_timeout, ?HOST}, 2000, #{}), % global default
  433:     ?cfgh(replaced_wait_timeout, 1000, #{<<"general">> => #{<<"replaced_wait_timeout">> => 1000}}),
  434:     ?errh(#{<<"general">> => #{<<"replaced_wait_timeout">> => 0}}).
  435: 
  436: hide_service_name(_Config) ->
  437:     ?cfg(hide_service_name, false, #{}), % default
  438:     ?cfg(hide_service_name, true, #{<<"general">> => #{<<"hide_service_name">> => true}}),
  439:     ?err(#{<<"general">> => #{<<"hide_service_name">> => []}}).
  440: 
  441: domain_certfile(_Config) ->
  442:     DomCert = #{<<"domain">> => <<"myxmpp.com">>,
  443:                 <<"certfile">> => <<"priv/cert.pem">>},
  444:     ?cfg(domain_certfile, #{<<"myxmpp.com">> => "priv/cert.pem"},
  445:          #{<<"general">> => #{<<"domain_certfile">> => [DomCert]}}),
  446:     ?err([#{reason := invalid_filename}],
  447:          #{<<"general">> => #{<<"domain_certfile">> =>
  448:                                   [DomCert#{<<"certfile">> => <<"missing.pem">>}]}}),
  449:     [?err(#{<<"general">> => #{<<"domain_certfile">> => [maps:without([K], DomCert)]}})
  450:      || K <- maps:keys(DomCert)],
  451:     [?err(#{<<"general">> => #{<<"domain_certfile">> => [DomCert#{K := <<>>}]}})
  452:      || K <- maps:keys(DomCert)],
  453:     ?err(#{<<"general">> => #{<<"domain_certfile">> => [DomCert, DomCert]}}).
  454: 
  455: %% tests: listen
  456: 
  457: listen_duplicate(_Config) ->
  458:     ?cfg(listen, [listener(c2s, #{port => 5222}),
  459:                   listener(c2s, #{port => 5223})],
  460:          #{<<"listen">> => #{<<"c2s">> => [#{<<"port">> => 5222, <<"ip_address">> => <<"0">>},
  461:                                            #{<<"port">> => 5223}]}}),
  462:     ?err([#{reason := duplicate_listeners,
  463:             duplicates := [{5222, {0, 0, 0, 0}, tcp}]}],
  464:          #{<<"listen">> => #{<<"c2s">> => [#{<<"port">> => 5222, <<"ip_address">> => <<"0">>},
  465:                                            #{<<"port">> => 5222}]}}),
  466:     ?err([#{reason := duplicate_listeners,
  467:             duplicates := [{5222, {0, 0, 0, 0}, tcp}]}],
  468:          #{<<"listen">> => #{<<"c2s">> => [#{<<"port">> => 5222, <<"ip_address">> => <<"0">>}],
  469:                              <<"s2s">> => [#{<<"port">> => 5222}]}}).
  470: 
  471: listen_c2s(_Config) ->
  472:     T = fun(Opts) -> listen_raw(c2s, maps:merge(#{<<"port">> => 5222}, Opts)) end,
  473:     P = [listen, 1],
  474:     ?cfg(P, config([listen, c2s], #{port => 5222}), T(#{})),
  475:     test_listen(P, T),
  476:     test_listen_xmpp(P, T),
  477:     ?cfg(P ++ [access], rule1, T(#{<<"access">> => <<"rule1">>})),
  478:     ?cfg(P ++ [shaper], c2s_shaper, T(#{<<"shaper">> => <<"c2s_shaper">>})),
  479:     ?cfg(P ++ [zlib], 1024, T(#{<<"zlib">> => 1024})),
  480:     ?cfg(P ++ [max_fsm_queue], 1000, T(#{<<"max_fsm_queue">> => 1000})),
  481:     ?cfg(P ++ [allowed_auth_methods], [rdbms, http],
  482:          T(#{<<"allowed_auth_methods">> => [<<"rdbms">>, <<"http">>]})),
  483:     ?err(T(#{<<"access">> => <<>>})),
  484:     ?err(T(#{<<"shaper">> => <<>>})),
  485:     ?err(T(#{<<"zlib">> => 0})),
  486:     ?err(T(#{<<"max_fsm_queue">> => 0})),
  487:     ?err(T(#{<<"allowed_auth_methods">> => [<<"bad_method">>]})),
  488:     ?err(T(#{<<"allowed_auth_methods">> => [<<"rdbms">>, <<"rdbms">>]})).
  489: 
  490: listen_c2s_fast_tls(_Config) ->
  491:     T = fun(Opts) -> listen_raw(c2s, #{<<"port">> => 5222,
  492:                                        <<"tls">> => Opts}) end,
  493:     P = [listen, 1, tls],
  494:     ?cfg(P, default_c2s_tls(fast_tls), T(#{})),
  495:     test_fast_tls_server(P, T),
  496:     ?cfg(P ++ [mode], tls, T(#{<<"mode">> => <<"tls">>})),
  497:     ?err(T(#{<<"mode">> => <<"stopttls">>})),
  498:     ?err(T(#{<<"module">> => <<"slow_tls">>})).
  499: 
  500: listen_c2s_just_tls(_Config) ->
  501:     T = fun(Opts) -> listen_raw(c2s, #{<<"port">> => 5222,
  502:                                        <<"tls">> => Opts#{<<"module">> => <<"just_tls">>}}) end,
  503:     P = [listen, 1, tls],
  504:     ?cfg(P, default_c2s_tls(just_tls), T(#{})),
  505:     test_just_tls_server(P, T),
  506:     ?cfg(P ++ [mode], tls, T(#{<<"mode">> => <<"tls">>})),
  507:     ?cfg(P ++ [disconnect_on_failure], false, T(#{<<"disconnect_on_failure">> => false})),
  508:     ?cfg(P ++ [crl_files], ["priv/cert.pem"], % note: this is not a real CRL file
  509:          T(#{<<"crl_files">> => [<<"priv/cert.pem">>]})),
  510:     ?err(T(#{<<"mode">> => <<"stopttls">>})),
  511:     ?err(T(#{<<"disconnect_on_failure">> => <<"sometimes">>})),
  512:     ?err(T(#{<<"dhfile">> => <<"no_such_file.pem">>})),
  513:     ?err(T(#{<<"crl_files">> => [<<"no_such_file.crl">>]})).
  514: 
  515: listen_s2s(_Config) ->
  516:     T = fun(Opts) -> listen_raw(s2s, maps:merge(#{<<"port">> => 5269}, Opts)) end,
  517:     P = [listen, 1],
  518:     ?cfg(P, config([listen, s2s], #{port => 5269}), T(#{})),
  519:     test_listen(P, T),
  520:     test_listen_xmpp(P, T),
  521:     ?cfg(P ++ [shaper], s2s_shaper, T(#{<<"shaper">> => <<"s2s_shaper">>})),
  522:     ?err(T(#{<<"shaper">> => <<>>})).
  523: 
  524: listen_s2s_tls(_Config) ->
  525:     T = fun(Opts) -> listen_raw(s2s, #{<<"port">> => 5269, <<"tls">> => Opts}) end,
  526:     P = [listen, 1, tls],
  527:     ?cfg(P, default_config([listen, s2s, tls]), T(#{})),
  528:     test_fast_tls_server(P, T).
  529: 
  530: listen_service(_Config) ->
  531:     T = fun(Opts) -> listen_raw(service, maps:merge(#{<<"port">> => 8888,
  532:                                                       <<"password">> => <<"secret">>}, Opts))
  533:         end,
  534:     P = [listen, 1],
  535:     ?cfg(P, config([listen, service], #{port => 8888, password => "secret"}), T(#{})),
  536:     test_listen(P, T),
  537:     test_listen_xmpp(P, T),
  538:     ?cfg(P ++ [access], rule1, T(#{<<"access">> => <<"rule1">>})),
  539:     ?cfg(P ++ [shaper_rule], fast, T(#{<<"shaper_rule">> => <<"fast">>})),
  540:     ?cfg(P ++ [check_from], false, T(#{<<"check_from">> => false})),
  541:     ?cfg(P ++ [hidden_components], true, T(#{<<"hidden_components">> => true})),
  542:     ?cfg(P ++ [conflict_behaviour], kick_old, T(#{<<"conflict_behaviour">> => <<"kick_old">>})),
  543:     ?cfg(P ++ [max_fsm_queue], 1000, T(#{<<"max_fsm_queue">> => 1000})),
  544:     ?err(T(#{<<"access">> => <<>>})),
  545:     ?err(T(#{<<"shaper_rule">> => <<>>})),
  546:     ?err(T(#{<<"check_from">> => 1})),
  547:     ?err(T(#{<<"hidden_components">> => <<"yes">>})),
  548:     ?err(T(#{<<"conflict_behaviour">> => <<"kill_server">>})),
  549:     ?err(T(#{<<"password">> => <<>>})),
  550:     ?err(T(#{<<"password">> => undefined})),
  551:     ?err(T(#{<<"max_fsm_queue">> => 0})).
  552: 
  553: listen_http(_Config) ->
  554:     T = fun(Opts) -> listen_raw(http, maps:merge(#{<<"port">> => 5280}, Opts)) end,
  555:     P = [listen, 1],
  556:     ?cfg(P, config([listen, http], #{port => 5280}), T(#{})),
  557:     test_listen(P, T).
  558: 
  559: listen_http_tls(_Config) ->
  560:     T = fun(Opts) -> listen_raw(http, #{<<"port">> => 5280, <<"tls">> => Opts}) end,
  561:     P = [listen, 1, tls],
  562:     test_just_tls_server(P, T),
  563:     ?cfg(P, default_config([listen, http, tls]), T(#{})).
  564: 
  565: listen_http_transport(_Config) ->
  566:     T = fun(Opts) -> listen_raw(http, #{<<"port">> => 5280, <<"transport">> => Opts}) end,
  567:     P = [listen, 1, transport],
  568:     ?cfg(P ++ [num_acceptors], 10, T(#{<<"num_acceptors">> => 10})),
  569:     ?cfg(P ++ [max_connections], 1024, T(#{<<"max_connections">> => 1024})),
  570:     ?err(T(#{<<"num_acceptors">> => 0})),
  571:     ?err(T(#{<<"max_connections">> => -1})).
  572: 
  573: listen_http_protocol(_Config) ->
  574:     T = fun(Opts) -> listen_raw(http, #{<<"port">> => 5280, <<"protocol">> => Opts}) end,
  575:     P = [listen, 1, protocol],
  576:     ?cfg(P ++ [compress], true, T(#{<<"compress">> => true})),
  577:     ?err(T(#{<<"compress">> => 1})).
  578: 
  579: listen_http_handlers_invalid(_Config) ->
  580:     T = fun(Opts) -> listen_raw(http, #{<<"port">> => 5280, <<"handlers">> => Opts}) end,
  581:     ?err(T(#{<<"mod_bosch">> => [#{<<"host">> => <<"dishwasher">>,
  582:                                    <<"path">> => <<"/cutlery">>}]})).
  583: 
  584: listen_http_handlers_bosh(_Config) ->
  585:     test_listen_http_handler(mod_bosh).
  586: 
  587: listen_http_handlers_websockets(_Config) ->
  588:     {P, T} = test_listen_http_handler(mod_websockets),
  589:     ?cfg(P ++ [timeout], 30000, T(#{<<"timeout">> => 30000})),
  590:     ?cfg(P ++ [ping_rate], 20, T(#{<<"ping_rate">> => 20})),
  591:     ?cfg(P ++ [max_stanza_size], 10000, T(#{<<"max_stanza_size">> => 10000})),
  592:     ?cfg(P ++ [service], maps:merge(extra_service_listener_config(), #{password => "secret"}),
  593:          T(#{<<"service">> => #{<<"password">> => <<"secret">>}})),
  594:     ?err(T(#{<<"timeout">> => -1})),
  595:     ?err(T(#{<<"ping_rate">> => 0})),
  596:     ?err(T(#{<<"max_stanza_size">> => 0})),
  597:     ?err(T(#{<<"service">> => #{}})).
  598: 
  599: listen_http_handlers_client_api(_Config) ->
  600:     {P, T} = test_listen_http_handler(mongoose_client_api),
  601:     ?cfg(P ++ [handlers], [mongoose_client_api_messages],
  602:          T(#{<<"handlers">> => [<<"mongoose_client_api_messages">>]})),
  603:     ?cfg(P ++ [docs], false, T(#{<<"docs">> => false})),
  604:     ?err(T(#{<<"handlers">> => [not_a_module]})),
  605:     ?err(T(#{<<"docs">> => <<"maybe">>})).
  606: 
  607: listen_http_handlers_api(_Config) ->
  608:     {P, T} = test_listen_http_handler(mongoose_api),
  609:     ?cfg(P ++ [handlers], [mongoose_api_metrics],
  610:          T(#{<<"handlers">> => [<<"mongoose_api_metrics">>]})),
  611:     ?err(T(#{<<"handlers">> => [not_a_module]})).
  612: 
  613: listen_http_handlers_api_admin(_Config) ->
  614:     {P, T} = test_listen_http_handler(mongoose_api_admin),
  615:     test_listen_http_handler_creds(P, T).
  616: 
  617: listen_http_handlers_api_client(_Config) ->
  618:     test_listen_http_handler(mongoose_api_client).
  619: 
  620: listen_http_handlers_domain(_Config) ->
  621:     {P, T} = test_listen_http_handler(mongoose_domain_handler),
  622:     test_listen_http_handler_creds(P, T).
  623: 
  624: listen_http_handlers_graphql(_Config) ->
  625:     T = fun graphql_handler_raw/1,
  626:     {P, _} = test_listen_http_handler(mongoose_graphql_cowboy_handler, T),
  627:     test_listen_http_handler_creds(P, T),
  628:     ?err(T(#{<<"schema_endpoint">> => <<"wrong_endpoint">>})),
  629:     ?err(http_handler_raw(mongoose_graphql_cowboy_handler, #{})).
  630: 
  631: test_listen_http_handler_creds(P, T) ->
  632:     CredsRaw = #{<<"username">> => <<"user">>, <<"password">> => <<"pass">>},
  633:     ?cfg(P ++ [username], <<"user">>, T(CredsRaw)),
  634:     ?cfg(P ++ [password], <<"pass">>, T(CredsRaw)),
  635:     %% Both username and password required. Or none.
  636:     [?err(T(maps:remove(Key, CredsRaw))) || Key <- maps:keys(CredsRaw)],
  637:     ?err(CredsRaw#{<<"username">> => 1}),
  638:     ?err(CredsRaw#{<<"password">> => 1}).
  639: 
  640: test_listen_http_handler(Module) ->
  641:     T = fun(Opts) -> http_handler_raw(Module, Opts) end,
  642:     test_listen_http_handler(Module, T).
  643: 
  644: test_listen_http_handler(Module, T) ->
  645:     P = [listen, 1, handlers, 1],
  646:     ?cfg(P, config([listen, http, handlers, Module], #{host => "localhost", path => "/api"}),
  647:          T(#{})),
  648:     ?cfg(P ++ [host], '_', T(#{<<"host">> => <<"_">>})),
  649:     ?cfg(P ++ [path], "/my-path", T(#{<<"path">> => <<"/my-path">>})),
  650:     ?err(T(#{<<"host">> => <<>>})),
  651:     ?err(T(#{<<"host">> => undefined})),
  652:     ?err(T(#{<<"path">> => 12})),
  653:     ?err(T(#{<<"path">> => undefined})),
  654:     {P, T}.
  655: 
  656: test_listen(P, T) ->
  657:     ?cfg(P ++ [ip_address], "192.168.1.16", T(#{<<"ip_address">> => <<"192.168.1.16">>})),
  658:     ?cfg(P ++ [ip_tuple], {192, 168, 1, 16}, T(#{<<"ip_address">> => <<"192.168.1.16">>})),
  659:     ?cfg(P ++ [ip_version], 4, T(#{<<"ip_address">> => <<"192.168.1.16">>})),
  660:     ?cfg(P ++ [ip_address], "2001:db8:3:4:5:6:7:8",
  661:          T(#{<<"ip_address">> => <<"2001:db8:3:4:5:6:7:8">>})),
  662:     ?cfg(P ++ [ip_tuple], {8193, 3512, 3, 4, 5, 6, 7, 8},
  663:          T(#{<<"ip_address">> => <<"2001:db8:3:4:5:6:7:8">>})),
  664:     ?cfg(P ++ [ip_version], 6,
  665:          T(#{<<"ip_address">> => <<"2001:db8:3:4:5:6:7:8">>})),
  666:     ?cfg(P ++ [ip_version], 4, T(#{<<"ip_version">> => 4})),
  667:     ?cfg(P ++ [ip_version], 6, T(#{<<"ip_version">> => 6})),
  668:     ?cfg(P ++ [ip_address], "::", T(#{<<"ip_version">> => 6})),
  669:     ?cfg(P ++ [ip_tuple], {0, 0, 0, 0, 0, 0, 0, 0}, T(#{<<"ip_version">> => 6})),
  670:     ?cfg(P ++ [proto], tcp, T(#{<<"proto">> => <<"tcp">>})),
  671:     ?err(T(#{<<"ip_address">> => <<"192.168.1.999">>})),
  672:     ?err(T(#{<<"port">> => <<"5222">>})),
  673:     ?err(T(#{<<"port">> => 522222})),
  674:     ?err(T(#{<<"port">> => undefined})),
  675:     ?err(T(#{<<"ip_version">> => 7})),
  676:     ?err(T(#{<<"proto">> => <<"udp">>})). % only TCP is accepted
  677: 
  678: test_listen_xmpp(P, T) ->
  679:     ?cfg(P ++ [backlog], 10, T(#{<<"backlog">> => 10})),
  680:     ?cfg(P ++ [proxy_protocol], true, T(#{<<"proxy_protocol">> => true})),
  681:     ?cfg(P ++ [hibernate_after], 10, T(#{<<"hibernate_after">> => 10})),
  682:     ?cfg(P ++ [max_stanza_size], 10000, T(#{<<"max_stanza_size">> => 10000})),
  683:     ?cfg(P ++ [num_acceptors], 100, T(#{<<"num_acceptors">> => 100})),
  684:     ?err(T(#{<<"backlog">> => -10})),
  685:     ?err(T(#{<<"proxy_protocol">> => <<"awesome">>})),
  686:     ?err(T(#{<<"hibernate_after">> => -10})),
  687:     ?err(T(#{<<"max_stanza_size">> => <<"unlimited">>})),
  688:     ?err(T(#{<<"num_acceptors">> => 0})).
  689: 
  690: %% tests: auth
  691: 
  692: auth_methods(_Config) ->
  693:     ?cfg([{auth, ?HOST}, methods], [], #{}), % global default
  694:     ?cfgh([auth, methods], [], #{<<"auth">> => #{}}), % default
  695:     ?cfgh([auth, methods], [internal, rdbms], % default alphabetical order
  696:           #{<<"auth">> => #{<<"internal">> => #{},
  697:                             <<"rdbms">> => #{}}}),
  698:     ?cfgh([auth, methods], [rdbms, internal], % specified order
  699:           #{<<"auth">> => #{<<"internal">> => #{},
  700:                             <<"rdbms">> => #{},
  701:                             <<"methods">> => [<<"rdbms">>, <<"internal">>]}}),
  702:     ?cfgh([auth, methods], [internal], % only one of the defined methods is enabled
  703:           #{<<"auth">> => #{<<"internal">> => #{},
  704:                             <<"rdbms">> => #{},
  705:                             <<"methods">> => [<<"internal">>]}}),
  706:     ?errh(#{<<"auth">> => #{<<"rdbms">> => <<"enabled">>}}),
  707:     ?errh(#{<<"auth">> => #{<<"supernatural">> => #{}}}),
  708:     ?errh(#{<<"auth">> => #{<<"methods">> => [<<"rdbms">>]}}).
  709: 
  710: auth_password(_Config) ->
  711:     Defaults = #{format => scram, scram_iterations => 10000},
  712:     ?cfg([{auth, ?HOST}, password], Defaults, #{}), % global default
  713:     ?cfgh([auth, password], Defaults, #{<<"auth">> => #{}}), % default
  714:     ?cfgh([auth, password], Defaults, #{<<"auth">> => #{<<"password">> => #{}}}), % default
  715:     ?cfgh([auth, password, format], plain,
  716:           #{<<"auth">> => #{<<"password">> => #{<<"format">> => <<"plain">>}}}),
  717:     ?errh(#{<<"auth">> => #{<<"password">> => #{<<"format">> => <<"plane">>}}}),
  718:     ?cfgh([auth, password, hash], [sha, sha256],
  719:           #{<<"auth">> => #{<<"password">> => #{<<"hash">> => [<<"sha">>, <<"sha256">>]}}}),
  720:     ?errh(#{<<"auth">> => #{<<"password">> => #{<<"hash">> => [<<"sha1234">>]}}}),
  721:     ?errh(#{<<"auth">> => #{<<"password">> => #{<<"harsh">> => [<<"sha">>]}}}),
  722:     ?cfgh([auth, password, scram_iterations], 1000,
  723:           #{<<"auth">> => #{<<"password">> => #{<<"scram_iterations">> => 1000}}}),
  724:     ?errh(#{<<"auth">> => #{<<"password">> => #{<<"scram_iterations">> => false}}}).
  725: 
  726: auth_sasl_external(_Config) ->
  727:     ?cfg([{auth, ?HOST}, sasl_external], [standard], #{}), % global default
  728:     ?cfgh([auth, sasl_external], [standard], #{<<"auth">> => #{}}), % default
  729:     ?cfgh([auth, sasl_external], [standard,
  730:                                   common_name,
  731:                                   {mod, cyrsasl_external_verification}],
  732:           #{<<"auth">> => #{<<"sasl_external">> =>
  733:                                 [<<"standard">>,
  734:                                  <<"common_name">>,
  735:                                  <<"cyrsasl_external_verification">>]}}),
  736:     ?errh(#{<<"auth">> => #{<<"sasl_external">> => [<<"unknown">>]}}).
  737: 
  738: auth_sasl_mechanisms(_Config) ->
  739:     Default = cyrsasl:default_modules(),
  740:     ?cfg([{auth, ?HOST}, sasl_mechanisms], Default, #{}), % global default
  741:     ?cfg([{auth, ?HOST}, sasl_mechanisms], Default, #{<<"auth">> => #{}}), % default
  742:     ?cfgh([auth, sasl_mechanisms], [cyrsasl_external, cyrsasl_scram],
  743:           #{<<"auth">> => #{<<"sasl_mechanisms">> => [<<"external">>, <<"scram">>]}}),
  744:     ?errh(#{<<"auth">> => #{<<"sasl_mechanisms">> => [<<"none">>]}}).
  745: 
  746: auth_allow_multiple_connections(_Config) ->
  747:     ?cfgh([auth, anonymous, allow_multiple_connections], true,
  748:           auth_raw(<<"anonymous">>, #{<<"allow_multiple_connections">> => true})),
  749:     ?errh(auth_raw(<<"anonymous">>, #{<<"allow_multiple_connections">> => <<"yes">>})).
  750: 
  751: auth_anonymous_protocol(_Config) ->
  752:     ?cfgh([auth, anonymous, protocol], login_anon,
  753:           auth_raw(<<"anonymous">>, #{<<"protocol">> => <<"login_anon">>})),
  754:     ?errh(auth_raw(<<"anonymous">>, #{<<"protocol">> => <<"none">>})).
  755: 
  756: auth_ldap_pool(_Config) ->
  757:     ?cfgh([auth, ldap, pool_tag], default, auth_ldap_raw(#{})), % default
  758:     ?cfgh([auth, ldap, pool_tag], ldap_pool,
  759:           auth_ldap_raw(#{<<"pool_tag">> => <<"ldap_pool">>})),
  760:     ?errh(auth_ldap_raw(#{<<"pool_tag">> => <<>>})).
  761: 
  762: auth_ldap_bind_pool(_Config) ->
  763:     ?cfgh([auth, ldap, bind_pool_tag], bind, auth_ldap_raw(#{})), % default
  764:     ?cfgh([auth, ldap, bind_pool_tag], ldap_bind_pool,
  765:           auth_ldap_raw(#{<<"bind_pool_tag">> => <<"ldap_bind_pool">>})),
  766:     ?errh(auth_ldap_raw(#{<<"bind_pool_tag">> => true})).
  767: 
  768: auth_ldap_base(_Config) ->
  769:     ?cfgh([auth, ldap, base], <<>>, auth_ldap_raw(#{})), % default
  770:     ?cfgh([auth, ldap, base], <<"ou=Users,dc=example,dc=com">>,
  771:           auth_ldap_raw(#{<<"base">> => <<"ou=Users,dc=example,dc=com">>})),
  772:     ?errh(auth_ldap_raw(#{<<"base">> => 10})).
  773: 
  774: auth_ldap_uids(_Config) ->
  775:     ?cfgh([auth, ldap, uids], [{<<"uid">>, <<"%u">>}], auth_ldap_raw(#{})), % default
  776:     ?cfgh([auth, ldap, uids], [{<<"uid1">>, <<"user=%u">>}],
  777:           auth_ldap_raw(#{<<"uids">> => [#{<<"attr">> => <<"uid1">>,
  778:                                            <<"format">> => <<"user=%u">>}]})),
  779:     ?cfgh([auth, ldap, uids], [<<"uid1">>],
  780:           auth_ldap_raw(#{<<"uids">> => [#{<<"attr">> => <<"uid1">>}]})),
  781:     ?errh(auth_ldap_raw(#{<<"uids">> => [#{<<"format">> => <<"user=%u">>}]})).
  782: 
  783: auth_ldap_filter(_Config) ->
  784:     ?cfgh([auth, ldap, filter], <<>>, auth_ldap_raw(#{})), % default
  785:     ?cfgh([auth, ldap, filter], <<"(objectClass=inetOrgPerson)">>,
  786:           auth_ldap_raw(#{<<"filter">> => <<"(objectClass=inetOrgPerson)">>})),
  787:     ?errh(auth_ldap_raw(#{<<"filter">> => 10})).
  788: 
  789: auth_ldap_dn_filter(_Config) ->
  790:     ?cfgh([auth, ldap, dn_filter], {undefined, []}, auth_ldap_raw(#{})), % default
  791:     ?cfgh([auth, ldap, dn_filter], {<<"(user=%u@%d)">>, []},
  792:           auth_ldap_raw(#{<<"dn_filter">> => #{<<"filter">> => <<"(user=%u@%d)">>}})),
  793:     Pattern = <<"(&(name=%s)(owner=%D)(user=%u@%d))">>,
  794:     ?cfgh([auth, ldap, dn_filter], {Pattern, [<<"sn">>]},
  795:           auth_ldap_raw(#{<<"dn_filter">> => #{<<"filter">> => Pattern,
  796:                                                <<"attributes">> => [<<"sn">>]}})),
  797:     ?errh(auth_ldap_raw(#{<<"dn_filter">> => #{<<"attributes">> => [<<"sn">>]}})),
  798:     ?errh(auth_ldap_raw(#{<<"dn_filter">> => #{<<"filter">> => 12}})),
  799:     ?errh(auth_ldap_raw(#{<<"dn_filter">> => #{<<"filter">> => Pattern,
  800:                                                <<"attributes">> => <<"sn">>}})).
  801: 
  802: auth_ldap_local_filter(_Config) ->
  803:     ?cfgh([auth, ldap, local_filter], undefined, auth_ldap_raw(#{})), % default
  804:     Filter = #{<<"operation">> => <<"equal">>,
  805:                <<"attribute">> => <<"accountStatus">>,
  806:                <<"values">> => [<<"enabled">>]},
  807:     ?cfgh([auth, ldap, local_filter], {equal, {"accountStatus", ["enabled"]}},
  808:           auth_ldap_raw(#{<<"local_filter">> => Filter})),
  809:     [?errh(auth_ldap_raw(#{<<"local_filter">> => maps:remove(K, Filter)})) ||
  810:         K <- maps:keys(Filter)],
  811:     ?errh(auth_ldap_raw(#{<<"local_filter">> => Filter#{<<"operation">> := <<"lt">>}})),
  812:     ?errh(auth_ldap_raw(#{<<"local_filter">> => Filter#{<<"attribute">> := <<>>}})),
  813:     ?errh(auth_ldap_raw(#{<<"local_filter">> => Filter#{<<"values">> := []}})).
  814: 
  815: auth_ldap_deref(_Config) ->
  816:     ?cfgh([auth, ldap, deref], never, auth_ldap_raw(#{})), % default
  817:     ?cfgh([auth, ldap, deref], always, auth_ldap_raw(#{<<"deref">> => <<"always">>})),
  818:     ?errh(auth_ldap_raw(#{<<"deref">> => <<"sometimes">>})).
  819: 
  820: auth_external(_Config) ->
  821:     RequiredOpts = #{<<"program">> => <<"/usr/bin/auth">>},
  822:     Config = #{program => "/usr/bin/auth",
  823:                instances => 1}, % default
  824:     ?cfgh([auth, external], Config,
  825:           auth_raw(<<"external">>, RequiredOpts)),
  826:     ?cfgh([auth, external, instances], 2,
  827:           auth_raw(<<"external">>, RequiredOpts#{<<"instances">> => 2})),
  828:     ?errh(auth_raw(<<"external">>, #{<<"program">> => <<>>})),
  829:     ?errh(auth_raw(<<"external">>, #{<<"instances">> => 2})),
  830:     ?errh(auth_raw(<<"external">>, RequiredOpts#{<<"instances">> => 0})).
  831: 
  832: auth_http_basic_auth(_Config) ->
  833:     ?cfgh([auth, http, basic_auth], "admin:admin123",
  834:           auth_raw(<<"http">>, #{<<"basic_auth">> => <<"admin:admin123">>})),
  835:     ?errh(auth_raw(<<"http">>, #{<<"basic_auth">> => true})).
  836: 
  837: auth_jwt(_Config) ->
  838:     Opts = #{<<"secret">> => #{<<"value">> => <<"secret123">>},
  839:              <<"algorithm">> => <<"HS512">>,
  840:              <<"username_key">> => <<"user">>}, % tested together as all options are required
  841:     Config = #{algorithm => <<"HS512">>,
  842:                secret => {value, "secret123"},
  843:                username_key => user},
  844:     ?cfgh([auth, jwt], Config,
  845:           auth_raw(<<"jwt">>, Opts)),
  846:     ?cfgh([auth, jwt, secret], {file, "/home/user/jwt_secret"},
  847:           auth_raw(<<"jwt">>, Opts#{<<"secret">> := #{<<"file">> => <<"/home/user/jwt_secret">>}})),
  848:     ?cfgh([auth, jwt, secret], {env, "SECRET"},
  849:           auth_raw(<<"jwt">>, Opts#{<<"secret">> := #{<<"env">> => <<"SECRET">>}})),
  850:     ?errh(auth_raw(<<"jwt">>, Opts#{<<"secret">> := #{<<"value">> => 123}})),
  851:     ?errh(auth_raw(<<"jwt">>, Opts#{<<"secret">> := #{<<"file">> => <<>>}})),
  852:     ?errh(auth_raw(<<"jwt">>, Opts#{<<"secret">> := #{<<"env">> => <<>>}})),
  853:     ?errh(auth_raw(<<"jwt">>, Opts#{<<"secret">> := #{<<"file">> => <<"/jwt_secret">>,
  854:                                                       <<"env">> => <<"SECRET">>}})),
  855:     ?errh(auth_raw(<<"jwt">>, Opts#{<<"algorithm">> := <<"bruteforce">>})),
  856:     ?errh(auth_raw(<<"jwt">>, Opts#{<<"username_key">> := <<>>})),
  857:     [?errh(auth_raw(<<"jwt">>, maps:without([K], Opts))) || K <- maps:keys(Opts)].
  858: 
  859: auth_riak_bucket_type(_Config) ->
  860:     ?cfgh([auth, riak, bucket_type], <<"users">>, auth_raw(<<"riak">>, #{})), % default
  861:     ?cfgh([auth, riak, bucket_type], <<"buckethead">>,
  862:           auth_raw(<<"riak">>, #{<<"bucket_type">> => <<"buckethead">>})),
  863:     ?errh(auth_raw(<<"riak">>, #{<<"bucket_type">> => <<>>})).
  864: 
  865: auth_rdbms_users_number_estimate(_Config) ->
  866:     ?cfgh([auth, rdbms, users_number_estimate], false, auth_raw(<<"rdbms">>, #{})), % default
  867:     ?cfgh([auth, rdbms, users_number_estimate], true,
  868:           auth_raw(<<"rdbms">>, #{<<"users_number_estimate">> => true})),
  869:     ?errh(auth_raw(<<"rdbms">>, #{<<"users_number_estimate">> => 1200})).
  870: 
  871: auth_dummy(_Config) ->
  872:     ?cfgh([auth, dummy], #{base_time => 50, variance => 450}, auth_raw(<<"dummy">>, #{})), % default
  873:     ?cfgh([auth, dummy, base_time], 0, auth_raw(<<"dummy">>, #{<<"base_time">> => 0})),
  874:     ?cfgh([auth, dummy, variance], 10, auth_raw(<<"dummy">>, #{<<"variance">> => 10})),
  875:     ?errh(auth_raw(<<"dummy">>, #{<<"base_time">> => -5})),
  876:     ?errh(auth_raw(<<"dummy">>, #{<<"variance">> => 0})).
  877: 
  878: %% tests: outgoing_pools
  879: 
  880: pool_basics(_Config) ->
  881:     P = [outgoing_pools, 1],
  882:     Required = #{<<"connection">> => #{<<"host">> => <<"http://localhost">>}},
  883:     ?cfg(P ++ [type], http, pool_raw(<<"http">>, <<"default">>, Required)),
  884:     ?cfg(P ++ [tag], default, pool_raw(<<"http">>, <<"default">>, Required)),
  885:     ?err(pool_raw(<<"swimming_pool">>, <<"default">>, Required)),
  886:     ?err(pool_raw(<<"http">>, 1000, Required)).
  887: 
  888: pool_scope(_Config) ->
  889:     P = [outgoing_pools, 1, scope],
  890:     Required = #{<<"connection">> => #{<<"host">> => <<"http://localhost">>}},
  891:     T = fun(Opts) -> pool_raw(<<"http">>, <<"default">>, maps:merge(Required, Opts)) end,
  892:     ?cfg(P, host, T(#{<<"scope">> => <<"host">>})),
  893:     ?cfg(P, <<"localhost">>, T(#{<<"scope">> => <<"single_host">>, <<"host">> => <<"localhost">>})),
  894:     ?err(T(#{<<"host">> => <<"localhost">>})), % missing scope
  895:     ?err(T(#{<<"scope">> => <<"single_host">>})), % missing host
  896:     ?err(T(#{<<"scope">> => <<"whatever">>})).
  897: 
  898: pool_rdbms(_Config) ->
  899:     test_pool_opts(rdbms, #{<<"connection">> => raw_sql_opts(pgsql)}).
  900: 
  901: pool_rdbms_connection_odbc(_Config) ->
  902:     P = [outgoing_pools, 1, conn_opts],
  903:     Required = #{<<"driver">> => <<"odbc">>, <<"settings">> => <<"DSN=mydb">>},
  904:     T = fun(Opts) -> pool_conn_raw(<<"rdbms">>, Opts) end,
  905:     test_pool_rdbms_connection_common_opts(P, T, Required),
  906:     ?cfg(P, config([outgoing_pools, rdbms, default, conn_opts],
  907:                    #{driver => odbc, settings => "DSN=mydb"}), T(Required)),
  908:     ?err(T(Required#{<<"settings">> => true})),
  909:     [?err(T(maps:remove(K, Required))) || K <- maps:keys(Required)].
  910: 
  911: pool_rdbms_connection_pgsql(_Config) ->
  912:     P = [outgoing_pools, 1, conn_opts],
  913:     T = fun(Opts) -> pool_conn_raw(<<"rdbms">>, Opts) end,
  914:     Required = raw_sql_opts(pgsql),
  915:     test_pool_rdbms_connection_common_opts(P, T, Required),
  916:     test_pool_rdbms_connection_sql_opts(P, T, Required, sql_opts(pgsql, 5432)).
  917: 
  918: pool_rdbms_connection_tls_pgsql(_Config) ->
  919:     P = [outgoing_pools, 1, conn_opts, tls],
  920:     Required = raw_sql_opts(pgsql),
  921:     T = fun(Opts) -> pool_conn_raw(<<"rdbms">>, Required#{<<"tls">> => Opts}) end,
  922:     ?cfg(P, config([outgoing_pools, rdbms, default, conn_opts, tls], #{required => false}), T(#{})),
  923:     ?cfg(P ++ [required], true, T(#{<<"required">> => true})),
  924:     ?err(T(#{<<"required">> => <<"maybe">>})),
  925:     test_just_tls_client(P, T).
  926: 
  927: pool_rdbms_connection_mysql(_Config) ->
  928:     P = [outgoing_pools, 1, conn_opts],
  929:     T = fun(Opts) -> pool_conn_raw(<<"rdbms">>, Opts) end,
  930:     Required = raw_sql_opts(mysql),
  931:     test_pool_rdbms_connection_common_opts(P, T, Required),
  932:     test_pool_rdbms_connection_sql_opts(P, T, Required, sql_opts(mysql, 3306)).
  933: 
  934: pool_rdbms_connection_tls_mysql(_Config) ->
  935:     P = [outgoing_pools, 1, conn_opts, tls],
  936:     Required = raw_sql_opts(mysql),
  937:     T = fun(Opts) -> pool_conn_raw(<<"rdbms">>, Required#{<<"tls">> => Opts}) end,
  938:     ?err(T(#{<<"required">> => true})), % only for pgsql
  939:     test_just_tls_client(P, T).
  940: 
  941: test_pool_rdbms_connection_sql_opts(P, T, Required, Expected) ->
  942:     ?cfg(P, config([outgoing_pools, rdbms, default, conn_opts], Expected), T(Required)),
  943:     ?cfg(P ++ [port], 1234, T(Required#{<<"port">> => 1234})),
  944:     ?err(T(Required#{<<"host">> => <<>>})),
  945:     ?err(T(Required#{<<"port">> => -1})),
  946:     ?err(T(Required#{<<"database">> => <<>>})),
  947:     ?err(T(Required#{<<"username">> => <<>>})),
  948:     ?err(T(Required#{<<"password">> => <<>>})).
  949: 
  950: test_pool_rdbms_connection_common_opts(P, T, Required) ->
  951:     ?cfg(P ++ [keepalive_interval], 100, T(Required#{<<"keepalive_interval">> => 100})),
  952:     ?cfg(P ++ [max_start_interval], 200, T(Required#{<<"max_start_interval">> => 200})),
  953:     ?err(T(Required#{<<"keepalive_interval">> => 0})),
  954:     ?err(T(Required#{<<"max_start_interval">> => 0})),
  955:     [?err(T(maps:remove(K, Required))) || K <- maps:keys(Required)].
  956: 
  957: raw_sql_opts(Driver) ->
  958:     #{<<"driver">> => atom_to_binary(Driver),
  959:       <<"host">> => <<"localhost">>,
  960:       <<"database">> => <<"db">>,
  961:       <<"username">> => <<"dbuser">>,
  962:       <<"password">> => <<"secret">>}.
  963: 
  964: sql_opts(Driver, Port) ->
  965:     #{driver => Driver,
  966:       host => "localhost",
  967:       port => Port,
  968:       database => "db",
  969:       username => "dbuser",
  970:       password => "secret"}.
  971: 
  972: pool_http(_Config) ->
  973:     test_pool_opts(http, #{<<"connection">> => #{<<"host">> => <<"https://localhost:8443">>}}).
  974: 
  975: pool_http_connection(_Config) ->
  976:     P = [outgoing_pools, 1, conn_opts],
  977:     T = fun(Opts) -> pool_conn_raw(<<"http">>, Opts) end,
  978:     Required = #{<<"host">> => <<"https://localhost:8443">>},
  979:     ?cfg(P, config([outgoing_pools, http, default, conn_opts], #{host => "https://localhost:8443"}),
  980:          T(Required)),
  981:     ?cfg(P ++ [path_prefix], <<"/my_path/">>, T(Required#{<<"path_prefix">> => <<"/my_path/">>})),
  982:     ?cfg(P ++ [request_timeout], 999, T(Required#{<<"request_timeout">> => 999})),
  983:     ?err(T(#{})),
  984:     ?err(T(#{<<"host">> => <<>>})),
  985:     ?err(T(Required#{<<"path_prefix">> => <<>>})),
  986:     ?err(T(Required#{<<"request_timeout">> => -1000})).
  987: 
  988: pool_http_connection_tls(_Config) ->
  989:     P = [outgoing_pools, 1, conn_opts, tls],
  990:     T = fun(Opts) -> pool_conn_raw(<<"http">>, #{<<"host">> => <<"http://localhost">>,
  991:                                                  <<"tls">> => Opts}) end,
  992:     ?cfg(P, default_config([outgoing_pools, http, default, conn_opts, tls]), T(#{})),
  993:     test_just_tls_client(P, T).
  994: 
  995: pool_redis(_Config) ->
  996:     test_pool_opts(redis, #{}).
  997: 
  998: pool_redis_connection(_Config) ->
  999:     P = [outgoing_pools, 1, conn_opts],
 1000:     T = fun(Opts) -> pool_conn_raw(<<"redis">>, Opts) end,
 1001:     ?cfg(P, default_config([outgoing_pools, redis, default, conn_opts]), T(#{})),
 1002:     ?cfg(P ++ [host], "my_host", T(#{<<"host">> => <<"my_host">>})),
 1003:     ?cfg(P ++ [port], 9999, T(#{<<"port">> => 9999})),
 1004:     ?cfg(P ++ [database], 1, T(#{<<"database">> => 1})),
 1005:     ?cfg(P ++ [password], "password1", T(#{<<"password">> => <<"password1">>})),
 1006:     ?err(T(#{<<"host">> => 8443})),
 1007:     ?err(T(#{<<"port">> => 666666})),
 1008:     ?err(T(#{<<"database">> => -1})),
 1009:     ?err(T(#{<<"password">> => 0})).
 1010: 
 1011: pool_riak(_Config) ->
 1012:     test_pool_opts(riak, #{<<"connection">> => required_riak_connection_opts()}).
 1013: 
 1014: pool_riak_connection(_Config) ->
 1015:     P = [outgoing_pools, 1, conn_opts],
 1016:     T = fun(Opts) -> pool_conn_raw(<<"riak">>, Opts) end,
 1017:     Required = required_riak_connection_opts(),
 1018:     ?cfg(P ++ [address], "127.0.0.1", T(Required)),
 1019:     ?cfg(P ++ [port], 8087, T(Required)),
 1020:     [?err(T(maps:remove(K, Required))) || K <- maps:keys(Required)],
 1021:     ?err(T(Required#{<<"address">> => 8443})),
 1022:     ?err(T(Required#{<<"port">> => 666666})).
 1023: 
 1024: pool_riak_connection_credentials(_Config) ->
 1025:     P = [outgoing_pools, 1, conn_opts, credentials],
 1026:     T = fun(Opts) -> pool_conn_raw(<<"riak">>,
 1027:                                    (required_riak_connection_opts())#{<<"credentials">> => Opts})
 1028:         end,
 1029:     Required = #{<<"user">> => <<"user">>, <<"password">> => <<"pass">>},
 1030:     ?cfg(P, #{user => "user", password => "pass"}, T(Required)),
 1031:     [?err(T(maps:remove(K, Required))) || K <- maps:keys(Required)],
 1032:     [?err(T(Required#{K => <<>>})) || K <- maps:keys(Required)].
 1033: 
 1034: pool_riak_connection_tls(_Config) ->
 1035:     P = [outgoing_pools, 1, conn_opts, tls],
 1036:     T0 = fun(Opts) -> pool_conn_raw(<<"riak">>,
 1037:                                     (required_riak_connection_opts())#{<<"tls">> => Opts}) end,
 1038:     T = fun(Opts) -> T0(maps:merge(#{<<"cacertfile">> => <<"priv/ca.pem">>}, Opts)) end,
 1039:     ?cfg(P, config([outgoing_pools, riak, default, conn_opts, tls], #{cacertfile => "priv/ca.pem"}),
 1040:          T(#{})),
 1041:     test_just_tls_client(P, T),
 1042:     ?err(T0(#{})), % missing required 'cacertfile'
 1043:     ?err(T(#{<<"verify_mode">> => <<"none">>})). % verification is mandatory for Riak
 1044: 
 1045: required_riak_connection_opts() ->
 1046:     #{<<"address">> => <<"127.0.0.1">>, <<"port">> => 8087}.
 1047: 
 1048: pool_cassandra(_Config) ->
 1049:     test_pool_opts(cassandra, #{<<"connection">> => #{}}).
 1050: 
 1051: pool_cassandra_connection(_Config) ->
 1052:     P = [outgoing_pools, 1, conn_opts],
 1053:     T = fun(Opts) -> pool_conn_raw(<<"cassandra">>, Opts) end,
 1054:     ?cfg(P, default_config([outgoing_pools, cassandra, default, conn_opts]), T(#{})),
 1055:     ?cfg(P ++ [keyspace], big_mongooseim, T(#{<<"keyspace">> => <<"big_mongooseim">>})),
 1056:     ?err(T(#{<<"keyspace">> => <<>>})).
 1057: 
 1058: pool_cassandra_connection_auth_plain(_Config) ->
 1059:     P = [outgoing_pools, 1, conn_opts, auth, plain],
 1060:     T = fun(Opts) -> pool_conn_raw(<<"cassandra">>, #{<<"auth">> => #{<<"plain">> => Opts}}) end,
 1061:     Required = #{<<"username">> => <<"user">>, <<"password">> => <<"pass">>},
 1062:     ?cfg(P, #{username => <<"user">>, password => <<"pass">>}, T(Required)),
 1063:     [?err(T(maps:remove(K, Required))) || K <- maps:keys(Required)],
 1064:     [?err(T(Required#{K => false})) || K <- maps:keys(Required)].
 1065: 
 1066: pool_cassandra_connection_servers(_Config) ->
 1067:     P = [outgoing_pools, 1, conn_opts, servers],
 1068:     T = fun(Servers) -> pool_conn_raw(<<"cassandra">>, #{<<"servers">> => Servers}) end,
 1069:     Required = #{<<"host">> => <<"example.com">>},
 1070:     ?cfg(P, [#{host => "example.com", port => 9042}, % default port
 1071:              #{host => "example.com", port => 9043}],
 1072:          T([Required, Required#{<<"port">> => 9043}])),
 1073:     ?err(T([Required, Required#{<<"port">> => 9042}])), % same port for both servers
 1074:     ?err(T([#{}])), % missing host
 1075:     ?err(T([])). % no servers
 1076: 
 1077: pool_cassandra_connection_tls(_Config) ->
 1078:     P = [outgoing_pools, 1, conn_opts, tls],
 1079:     T = fun(Opts) -> pool_conn_raw(<<"cassandra">>, #{<<"tls">> => Opts}) end,
 1080:     ?cfg(P, default_config([outgoing_pools, cassandra, default, conn_opts, tls]), T(#{})),
 1081:     test_just_tls_client(P, T).
 1082: 
 1083: pool_elastic(_Config) ->
 1084:     test_pool_opts(elastic, #{<<"connection">> => #{}}).
 1085: 
 1086: pool_elastic_connection(_Config) ->
 1087:     P = [outgoing_pools, 1, conn_opts],
 1088:     T = fun(Opts) -> pool_conn_raw(<<"elastic">>, Opts) end,
 1089:     ?cfg(P, default_config([outgoing_pools, elastic, default, conn_opts]), T(#{})),
 1090:     ?cfg(P ++ [host], <<"my_host">>, T(#{<<"host">> => <<"my_host">>})),
 1091:     ?cfg(P ++ [port], 9999, T(#{<<"port">> => 9999})),
 1092:     ?err(T(#{<<"host">> => <<>>})),
 1093:     ?err(T(#{<<"port">> => 123456})).
 1094: 
 1095: pool_rabbit(_Config) ->
 1096:     test_pool_opts(rabbit, #{<<"connection">> => #{}}).
 1097: 
 1098: pool_rabbit_connection(_Config) ->
 1099:     P = [outgoing_pools, 1, conn_opts],
 1100:     T = fun(Opts) -> pool_conn_raw(<<"rabbit">>, Opts) end,
 1101:     ?cfg(P, default_config([outgoing_pools, rabbit, default, conn_opts]), T(#{})),
 1102:     ?cfg(P ++ [host], "my_host", T(#{<<"host">> => <<"my_host">>})),
 1103:     ?cfg(P ++ [port], 9999, T(#{<<"port">> => 9999})),
 1104:     ?cfg(P ++ [username], <<"user">>, T(#{<<"username">> => <<"user">>})),
 1105:     ?cfg(P ++ [password], <<"pass">>, T(#{<<"password">> => <<"pass">>})),
 1106:     ?cfg(P ++ [confirms_enabled], true, T(#{<<"confirms_enabled">> => true})),
 1107:     ?cfg(P ++ [max_worker_queue_len], 100, T(#{<<"max_worker_queue_len">> => 100})),
 1108:     ?err(T(#{<<"host">> => <<>>})),
 1109:     ?err(T(#{<<"port">> => 123456})),
 1110:     ?err(T(#{<<"username">> => <<>>})),
 1111:     ?err(T(#{<<"password">> => <<>>})),
 1112:     ?err(T(#{<<"confirms_enabled">> => <<"yes">>})),
 1113:     ?err(T(#{<<"max_worker_queue_len">> => -1})).
 1114: 
 1115: pool_ldap(_Config) ->
 1116:     test_pool_opts(ldap, #{<<"connection">> => #{}}).
 1117: 
 1118: pool_ldap_connection(_Config) ->
 1119:     P = [outgoing_pools, 1, conn_opts],
 1120:     T = fun(Opts) -> pool_conn_raw(<<"ldap">>, Opts) end,
 1121:     ?cfg(P, default_config([outgoing_pools, ldap, default, conn_opts]), T(#{})),
 1122:     ?cfg(P ++ [servers], ["server1.example.com", "server2.example.com"],
 1123:          T(#{<<"servers">> => [<<"server1.example.com">>, <<"server2.example.com">>]})),
 1124:     ?cfg(P ++ [port], 999, T(#{<<"port">> => 999})),
 1125:     ?cfg(P ++ [root_dn], <<"my_rootdn">>, T(#{<<"root_dn">> => <<"my_rootdn">>})),
 1126:     ?cfg(P ++ [password], <<"pass">>, T(#{<<"password">> => <<"pass">>})),
 1127:     ?cfg(P ++ [connect_interval], 5000, T(#{<<"connect_interval">> => 5000})),
 1128:     ?cfg(P ++ [port], 636, T(#{<<"tls">> => #{}})), % default TLS port is different
 1129:     ?err(T(#{<<"servers">> => [<<"server1.example.com">>, <<"server1.example.com">>]})),
 1130:     ?err(T(#{<<"servers">> => []})),
 1131:     ?err(T(#{<<"port">> => 123456})),
 1132:     ?err(T(#{<<"root_dn">> => 1})),
 1133:     ?err(T(#{<<"password">> => true})),
 1134:     ?err(T(#{<<"connect_interval">> => <<"infinity">>})).
 1135: 
 1136: pool_ldap_connection_tls(_Config) ->
 1137:     P = [outgoing_pools, 1, conn_opts, tls],
 1138:     T = fun(Opts) -> pool_conn_raw(<<"ldap">>, #{<<"tls">> => Opts}) end,
 1139:     ?cfg(P, default_config([outgoing_pools, ldap, default, conn_opts, tls]), T(#{})),
 1140:     test_just_tls_client(P, T).
 1141: 
 1142: test_pool_opts(Type, Required) ->
 1143:     P = [outgoing_pools, 1, opts],
 1144:     T = fun(Opts) -> pool_raw(atom_to_binary(Type), <<"default">>, Opts) end,
 1145:     ?cfg(P, default_config([outgoing_pools, Type, default, opts]), T(Required)),
 1146:     ?cfg(P ++ [workers], 11, T(Required#{<<"workers">> => 11})),
 1147:     ?cfg(P ++ [strategy], random_worker, T(Required#{<<"strategy">> => <<"random_worker">>})),
 1148:     ?cfg(P ++ [call_timeout], 999, T(Required#{<<"call_timeout">> => 999})),
 1149:     ?err(T(Required#{<<"workers">> => 0})),
 1150:     ?err(T(Required#{<<"strategy">> => <<"worst_worker">>})),
 1151:     ?err(T(Required#{<<"call_timeout">> => 0})).
 1152: 
 1153: test_just_tls_client(P, T) ->
 1154:     test_just_tls_common(P, T),
 1155:     test_just_tls_client_sni(P, T),
 1156:     ?err(T(#{<<"dhfile">> => <<"priv/dh.pem">>})). % server-only
 1157: 
 1158: test_just_tls_server(P, T) ->
 1159:     test_just_tls_common(P, T),
 1160:     ?cfg(P ++ [dhfile], "priv/dh.pem", T(#{<<"dhfile">> => <<"priv/dh.pem">>})),
 1161:     ?err(T(#{<<"dhfile">> => <<"no_such_file.pem">>})).
 1162: 
 1163: test_just_tls_common(P, T) ->
 1164:     ?cfg(P ++ [verify_mode], selfsigned_peer, T(#{<<"verify_mode">> => <<"selfsigned_peer">>})),
 1165:     ?cfg(P ++ [certfile], "priv/cert.pem", T(#{<<"certfile">> => <<"priv/cert.pem">>})),
 1166:     ?cfg(P ++ [cacertfile], "priv/ca.pem", T(#{<<"cacertfile">> => <<"priv/ca.pem">>})),
 1167:     ?cfg(P ++ [ciphers], "TLS_AES_256_GCM_SHA384",
 1168:          T(#{<<"ciphers">> => <<"TLS_AES_256_GCM_SHA384">>})),
 1169:     ?cfg(P ++ [keyfile], "priv/dc1.pem", T(#{<<"keyfile">> => <<"priv/dc1.pem">>})),
 1170:     ?cfg(P ++ [password], "secret", T(#{<<"password">> => <<"secret">>})),
 1171:     ?cfg(P ++ [versions], ['tlsv1.2', 'tlsv1.3'],
 1172:          T(#{<<"versions">> => [<<"tlsv1.2">>, <<"tlsv1.3">>]})),
 1173:     ?err(T(#{<<"verify_mode">> => <<"whatever">>})),
 1174:     ?err(T(#{<<"certfile">> => <<"no_such_file.pem">>})),
 1175:     ?err(T(#{<<"cacertfile">> => <<"no_such_file.pem">>})),
 1176:     ?err(T(#{<<"ciphers">> => [<<"TLS_AES_256_GCM_SHA384">>]})),
 1177:     ?err(T(#{<<"keyfile">> => <<"no_such_file.pem">>})),
 1178:     ?err(T(#{<<"password">> => false})),
 1179:     ?err(T(#{<<"versions">> => <<"tlsv1.2">>})),
 1180:     ?err(T(#{<<"protocol_options">> => [<<"nosslv2">>]})). % only for fast_tls
 1181: 
 1182: test_just_tls_client_sni(ParentP, ParentT) ->
 1183:     P = ParentP ++ [server_name_indication],
 1184:     T = fun(Opts) -> ParentT(#{<<"server_name_indication">> => Opts}) end,
 1185:     ?cfg(P ++ [enabled], false, T(#{<<"enabled">> => false})),
 1186:     ?cfg(P ++ [host], "host.example.com", T(#{<<"host">> => <<"host.example.com">>})),
 1187:     ?cfg(P ++ [protocol], https, T(#{<<"protocol">> => <<"https">>})),
 1188:     ?err(T(#{<<"enabled">> => <<"maybe">>})),
 1189:     ?err(T(#{<<"host">> => <<>>})),
 1190:     ?err(T(#{<<"protocol">> => <<"http">>})).
 1191: 
 1192: test_fast_tls_server(P, T) ->
 1193:     ?cfg(P ++ [verify_mode], none, T(#{<<"verify_mode">> => <<"none">>})),
 1194:     ?cfg(P ++ [certfile], "priv/cert.pem", T(#{<<"certfile">> => <<"priv/cert.pem">>})),
 1195:     ?cfg(P ++ [cacertfile], "priv/ca.pem", T(#{<<"cacertfile">> => <<"priv/ca.pem">>})),
 1196:     ?cfg(P ++ [ciphers], "TLS_AES_256_GCM_SHA384",
 1197:          T(#{<<"ciphers">> => <<"TLS_AES_256_GCM_SHA384">>})),
 1198:     ?cfg(P ++ [dhfile], "priv/dh.pem", T(#{<<"dhfile">> => <<"priv/dh.pem">>})),
 1199:     ?cfg(P ++ [protocol_options], ["nosslv2"], T(#{<<"protocol_options">> => [<<"nosslv2">>]})),
 1200:     ?err(T(#{<<"verify_mode">> => <<"selfsigned_peer">>})), % value only for just_tls
 1201:     ?err(T(#{<<"crl_files">> => [<<"priv/cert.pem">>]})), % option only for just_tls
 1202:     ?err(T(#{<<"certfile">> => <<"no_such_file.pem">>})),
 1203:     ?err(T(#{<<"cacertfile">> => <<"no_such_file.pem">>})),
 1204:     ?err(T(#{<<"ciphers">> => [<<"TLS_AES_256_GCM_SHA384">>]})),
 1205:     ?err(T(#{<<"dhfile">> => <<"no_such_file.pem">>})),
 1206:     ?err(T(#{<<"keyfile">> => <<"priv/dc1.pem">>})), % option only for just_tls
 1207:     ?err(T(#{<<"password">> => <<"secret">>})), % option only for just_tls
 1208:     ?err(T(#{<<"versions">> => [<<"tlsv1.2">>]})), % option only for just_tls
 1209:     ?err(T(#{<<"protocol_options">> => [<<>>]})).
 1210: 
 1211: %% tests: shaper, acl, access
 1212: shaper(_Config) ->
 1213:     ?cfg([shaper, normal], #{max_rate => 1000},
 1214:          #{<<"shaper">> => #{<<"normal">> => #{<<"max_rate">> => 1000}}}),
 1215:     ?err(#{<<"shaper">> => #{<<"unlimited">> => #{<<"max_rate">> => <<"infinity">>}}}),
 1216:     ?err(#{<<"shaper">> => #{<<"fast">> => #{}}}).
 1217: 
 1218: acl(_Config) ->
 1219:     ?cfgh([acl, local], [#{match => all}],
 1220:           #{<<"acl">> => #{<<"local">> => [#{<<"match">> => <<"all">>}]}}),
 1221:     ?cfgh([acl, local], [#{match => any_hosted_domain}],
 1222:           #{<<"acl">> => #{<<"local">> => [#{<<"match">> => <<"any_hosted_domain">>}]}}),
 1223:     ?cfgh([acl, local], [#{match => current_domain,
 1224:                            user_regexp => <<>>}],
 1225:           #{<<"acl">> => #{<<"local">> => [#{<<"user_regexp">> => <<>>}]}}),
 1226:     ?cfgh([acl, alice], [#{match => current_domain,
 1227:                            user_regexp => <<"ali.*">>,
 1228:                            server_regexp => <<".*host">>}],
 1229:           #{<<"acl">> => #{<<"alice">> => [#{<<"user_regexp">> => <<"aLi.*">>,
 1230:                                              <<"server_regexp">> => <<".*HosT">>}]}}),
 1231:     ?cfgh([acl, alice], [#{match => current_domain,
 1232:                            user => <<"alice">>,
 1233:                            server => <<"localhost">>}],
 1234:           #{<<"acl">> => #{<<"alice">> => [#{<<"user">> => <<"alice">>,
 1235:                                              <<"server">> => <<"localhost">>}]}}),
 1236:     ?errh(#{<<"acl">> => #{<<"local">> => <<"everybody">>}}),
 1237:     ?errh(#{<<"acl">> => #{<<"local">> => [#{<<"match">> => <<"lit">>}]}}),
 1238:     ?errh(#{<<"acl">> => #{<<"alice">> => [#{<<"user_glob">> => <<"a*">>,
 1239:                                              <<"server_blog">> => <<"bloghost">>}]}}),
 1240:     ?errh([#{reason := incorrect_acl_condition_value}],
 1241:           #{<<"acl">> => #{<<"local">> => [#{<<"user">> => <<"@@@">>}]}}).
 1242: 
 1243: acl_merge_host_and_global(_Config) ->
 1244:     G = #{<<"acl">> => #{<<"admin">> => [#{<<"user">> => <<"george">>}]}},
 1245:     H1 = #{<<"acl">> => #{<<"admin">> => [#{<<"user">> => <<"henry">>}]}},
 1246:     H2 = #{<<"acl">> => #{<<"hostile">> => [#{<<"user">> => <<"hacker">>}]}},
 1247:     ?cfg([{{acl, global}, #{admin => [#{user => <<"george">>, match => current_domain}]}},
 1248:           {{acl, ?HOST}, #{admin => [#{user => <<"george">>, match => current_domain}]}}],
 1249:          maps:merge(G, host_config(G))),
 1250:     ?cfg([{{acl, global}, #{admin => [#{user => <<"george">>, match => current_domain}]}},
 1251:           {{acl, ?HOST}, #{admin => [#{user => <<"george">>, match => current_domain},
 1252:                                      #{user => <<"henry">>, match => current_domain}]}}],
 1253:          maps:merge(G, host_config(H1))),
 1254:     ?cfg([{{acl, global}, #{admin => [#{user => <<"george">>, match => current_domain}]}},
 1255:           {{acl, ?HOST}, #{admin => [#{user => <<"george">>, match => current_domain}],
 1256:                            hostile => [#{user => <<"hacker">>, match => current_domain}]}}],
 1257:          maps:merge(G, host_config(H2))).
 1258: 
 1259: access(_Config) ->
 1260:     ?cfgh([access, c2s], [#{acl => blocked, value => deny},
 1261:                           #{acl => all, value => allow}],
 1262:           access_raw(<<"c2s">>, [#{<<"acl">> => <<"blocked">>, <<"value">> => <<"deny">>},
 1263:                                  #{<<"acl">> => <<"all">>, <<"value">> => <<"allow">>}])),
 1264:     ?cfgh([access, max_user_sessions], [#{acl => all, value => 10}],
 1265:           access_raw(<<"max_user_sessions">>, [#{<<"acl">> => <<"all">>, <<"value">> => 10}])),
 1266:     ?errh(access_raw(<<"max_user_sessions">>, [#{<<"acl">> => <<"all">>}])),
 1267:     ?errh(access_raw(<<"max_user_sessions">>, [#{<<"value">> => 10}])),
 1268:     ?errh(access_raw(<<"max_user_sessions">>, [#{<<"acl">> => 10, <<"value">> => 10}])).
 1269: 
 1270: access_merge_host_and_global(_Config) ->
 1271:     G1 = access_raw(<<"c2s">>, [#{<<"acl">> => <<"good">>, <<"value">> => <<"allow">>}]),
 1272:     G2 = access_raw(<<"c2s">>, [#{<<"acl">> => <<"gangsters">>, <<"value">> => <<"deny">>},
 1273:                                 #{<<"acl">> => <<"all">>, <<"value">> => <<"allow">>}]),
 1274:     H1 = access_raw(<<"c2s">>, [#{<<"acl">> => <<"harmless">>, <<"value">> => <<"allow">>}]),
 1275:     H2 = access_raw(<<"s2s">>, [#{<<"acl">> => <<"harmless">>, <<"value">> => <<"allow">>}]),
 1276:     H3 = access_raw(<<"c2s">>, [#{<<"acl">> => <<"hackers">>, <<"value">> => <<"deny">>}]),
 1277:     ?cfg([{{access, global}, #{c2s => [#{acl => good, value => allow}]}},
 1278:           {{access, ?HOST}, #{c2s => [#{acl => good, value => allow}]}}],
 1279:          maps:merge(G1, host_config(G1))),
 1280:     ?cfg([{{access, global}, #{c2s => [#{acl => good, value => allow}]}},
 1281:           {{access, ?HOST}, #{c2s => [#{acl => good, value => allow},
 1282:                                       #{acl => harmless, value => allow}]}}],
 1283:          maps:merge(G1, host_config(H1))),
 1284:     ?cfg([{{access, global}, #{c2s => [#{acl => good, value => allow}]}},
 1285:           {{access, ?HOST}, #{c2s => [#{acl => good, value => allow}],
 1286:                               s2s => [#{acl => harmless, value => allow}]}}],
 1287:          maps:merge(G1, host_config(H2))),
 1288:     ?cfg([{{access, global}, #{c2s => [#{acl => gangsters, value => deny},
 1289:                                        #{acl => all, value => allow}]}},
 1290:           {{access, ?HOST}, #{c2s => [#{acl => gangsters, value => deny},
 1291:                                       #{acl => hackers, value => deny},
 1292:                                       #{acl => all, value => allow}]}}],
 1293:          maps:merge(G2, host_config(H3))).
 1294: 
 1295: %% tests: s2s
 1296: 
 1297: s2s_host_config(_Config) ->
 1298:     DefaultS2S = default_s2s(),
 1299:     EmptyHostConfig = host_config(#{<<"s2s">> => #{}}),
 1300:     ?cfg(host_key(s2s), DefaultS2S,
 1301:          EmptyHostConfig#{<<"s2s">> => #{<<"dns">> => #{<<"timeout">> => 5}}}),
 1302:     StartTLSHostConfig = host_config(#{<<"s2s">> => #{<<"use_starttls">> => <<"required">>}}),
 1303:     ?cfg(host_key(s2s), DefaultS2S#{use_starttls => required},
 1304:          StartTLSHostConfig#{<<"s2s">> => #{<<"dns">> => #{<<"timeout">> => 5}}}).
 1305: 
 1306: s2s_dns_timeout(_Config) ->
 1307:     ?cfgh([s2s, dns, timeout], 10, #{}), % default
 1308:     ?cfgh([s2s, dns, timeout], 5, #{<<"s2s">> => #{<<"dns">> => #{<<"timeout">> => 5}}}),
 1309:     ?errh(#{<<"s2s">> => #{<<"dns">> => #{<<"timeout">> => 0}}}).
 1310: 
 1311: s2s_dns_retries(_Config) ->
 1312:     ?cfgh([s2s, dns, retries], 2, #{}), % default
 1313:     ?cfgh([s2s, dns, retries], 1, #{<<"s2s">> => #{<<"dns">> => #{<<"retries">> => 1}}}),
 1314:     ?errh(#{<<"s2s">> => #{<<"dns">> => #{<<"retries">> => 0}}}).
 1315: 
 1316: s2s_outgoing_port(_Config) ->
 1317:     ?cfgh([s2s, outgoing, port], 5269, #{}), % default
 1318:     ?cfgh([s2s, outgoing, port], 5270, #{<<"s2s">> => #{<<"outgoing">> => #{<<"port">> => 5270}}}),
 1319:     ?errh(#{<<"s2s">> => #{<<"outgoing">> => #{<<"port">> => <<"http">>}}}).
 1320: 
 1321: s2s_outgoing_ip_versions(_Config) ->
 1322:     ?cfgh([s2s, outgoing, ip_versions], [4, 6], #{}), % default
 1323:     ?cfgh([s2s, outgoing, ip_versions], [6, 4],
 1324:          #{<<"s2s">> => #{<<"outgoing">> => #{<<"ip_versions">> => [6, 4]}}}),
 1325:     ?errh(#{<<"s2s">> => #{<<"outgoing">> => #{<<"ip_versions">> => []}}}),
 1326:     ?errh(#{<<"s2s">> => #{<<"outgoing">> => #{<<"ip_versions">> => [<<"http">>]}}}).
 1327: 
 1328: s2s_outgoing_timeout(_Config) ->
 1329:     ?cfgh([s2s, outgoing, connection_timeout], 10000, #{}), % default
 1330:     ?cfgh([s2s, outgoing, connection_timeout], 5000,
 1331:           #{<<"s2s">> => #{<<"outgoing">> => #{<<"connection_timeout">> => 5000}}}),
 1332:     ?cfgh([s2s, outgoing, connection_timeout], infinity,
 1333:           #{<<"s2s">> => #{<<"outgoing">> => #{<<"connection_timeout">> => <<"infinity">>}}}),
 1334:     ?errh(#{<<"s2s">> => #{<<"outgoing">> => #{<<"connection_timeout">> => 0}}}).
 1335: 
 1336: s2s_use_starttls(_Config) ->
 1337:     ?cfgh([s2s, use_starttls], false, #{}), % default
 1338:     ?cfgh([s2s, use_starttls], required, #{<<"s2s">> => #{<<"use_starttls">> => <<"required">>}}),
 1339:     ?errh(#{<<"s2s">> => #{<<"use_starttls">> => <<"unnecessary">>}}).
 1340: 
 1341: s2s_certfile(_Config) ->
 1342:     ?cfgh([s2s, certfile], "priv/server.pem",  #{<<"s2s">> => #{<<"certfile">> => <<"priv/server.pem">>}}),
 1343:     ?errh([#{reason := invalid_filename}], #{<<"s2s">> => #{<<"certfile">> => <<"nofile.pem">>}}),
 1344:     ?errh(#{<<"s2s">> => #{<<"certfile">> => []}}).
 1345: 
 1346: s2s_default_policy(_Config) ->
 1347:     ?cfgh([s2s, default_policy], allow, #{}), % default
 1348:     ?cfgh([s2s, default_policy], deny, #{<<"s2s">> => #{<<"default_policy">> => <<"deny">>}}),
 1349:     ?errh(#{<<"s2s">> => #{<<"default_policy">> => <<"ask">>}}).
 1350: 
 1351: s2s_host_policy(_Config) ->
 1352:     Policy = #{<<"host">> => <<"host1">>,
 1353:                <<"policy">> => <<"allow">>},
 1354:     ?cfgh([s2s, host_policy], #{<<"host1">> => allow},
 1355:           #{<<"s2s">> => #{<<"host_policy">> => [Policy]}}),
 1356:     ?cfgh([s2s, host_policy], #{<<"host1">> => allow,
 1357:                                 <<"host2">> => deny},
 1358:           #{<<"s2s">> => #{<<"host_policy">> => [Policy, #{<<"host">> => <<"host2">>,
 1359:                                                            <<"policy">> => <<"deny">>}]}}),
 1360:     ?errh(#{<<"s2s">> => #{<<"host_policy">> => [maps:without([<<"host">>], Policy)]}}),
 1361:     ?errh(#{<<"s2s">> => #{<<"host_policy">> => [maps:without([<<"policy">>], Policy)]}}),
 1362:     ?errh(#{<<"s2s">> => #{<<"host_policy">> => [Policy#{<<"host">> => <<>>}]}}),
 1363:     ?errh(#{<<"s2s">> => #{<<"host_policy">> => [Policy#{<<"policy">> => <<"huh">>}]}}),
 1364:     ?errh(#{<<"s2s">> => #{<<"host_policy">> => [Policy,
 1365:                                                  Policy#{<<"policy">> => <<"deny">>}]}}).
 1366: 
 1367: s2s_address(_Config) ->
 1368:     Addr = #{<<"host">> => <<"host1">>,
 1369:              <<"ip_address">> => <<"192.168.1.2">>,
 1370:              <<"port">> => 5321},
 1371:     ?cfgh([s2s, address], #{<<"host1">> => #{ip_address => "192.168.1.2", port => 5321}},
 1372:           #{<<"s2s">> => #{<<"address">> => [Addr]}}),
 1373:     ?cfgh([s2s, address], #{<<"host1">> => #{ip_address => "192.168.1.2"}},
 1374:           #{<<"s2s">> => #{<<"address">> => [maps:without([<<"port">>], Addr)]}}),
 1375:     ?errh(#{<<"s2s">> => #{<<"address">> => [maps:without([<<"host">>], Addr)]}}),
 1376:     ?errh(#{<<"s2s">> => #{<<"address">> => [maps:without([<<"ip_address">>], Addr)]}}),
 1377:     ?errh(#{<<"s2s">> => #{<<"address">> => [Addr#{<<"host">> => <<>>}]}}),
 1378:     ?errh(#{<<"s2s">> => #{<<"address">> => [Addr#{<<"ip_address">> => <<"host2">>}]}}),
 1379:     ?errh(#{<<"s2s">> => #{<<"address">> => [Addr#{<<"port">> => <<"seaport">>}]}}),
 1380:     ?errh(#{<<"s2s">> => #{<<"address">> => [Addr, maps:remove(<<"port">>, Addr)]}}).
 1381: 
 1382: s2s_ciphers(_Config) ->
 1383:     ?cfgh([s2s, ciphers], mongoose_tls:default_ciphers(), #{}), % default
 1384:     ?cfgh([s2s, ciphers], "TLSv1.2",
 1385:           #{<<"s2s">> => #{<<"ciphers">> => <<"TLSv1.2">>}}),
 1386:     ?errh(#{<<"s2s">> => #{<<"ciphers">> => [<<"cipher1">>, <<"cipher2">>]}}).
 1387: 
 1388: s2s_shared(_Config) ->
 1389:     ?cfgh([s2s, shared], <<"secret">>, #{<<"s2s">> => #{<<"shared">> => <<"secret">>}}),
 1390:     ?errh(#{<<"s2s">> => #{<<"shared">> => 536837}}).
 1391: 
 1392: s2s_max_retry_delay(_Config) ->
 1393:     ?cfgh([s2s, max_retry_delay], 120, #{<<"s2s">> => #{<<"max_retry_delay">> => 120}}),
 1394:     ?errh(#{<<"s2s">> => #{<<"max_retry_delay">> => 0}}).
 1395: 
 1396: %% modules
 1397: 
 1398: mod_adhoc(_Config) ->
 1399:     check_module_defaults(mod_adhoc),
 1400:     check_iqdisc(mod_adhoc),
 1401:     P = [modules, mod_adhoc],
 1402:     T = fun(K, V) -> #{<<"modules">> => #{<<"mod_adhoc">> => #{K => V}}} end,
 1403:     %% report_commands_node is boolean
 1404:     ?cfgh(P ++ [report_commands_node], true, T(<<"report_commands_node">>, true)),
 1405:     ?cfgh(P ++ [report_commands_node], false, T(<<"report_commands_node">>, false)),
 1406:     %% not boolean
 1407:     ?errh(T(<<"report_commands_node">>, <<"hello">>)).
 1408: 
 1409: mod_auth_token(_Config) ->
 1410:     check_module_defaults(mod_auth_token),
 1411:     check_iqdisc(mod_auth_token),
 1412:     P = [modules, mod_auth_token],
 1413:     T = fun(K, V) -> #{<<"modules">> => #{<<"mod_auth_token">> => #{K => V}}} end,
 1414:     ?cfgh(P ++ [backend], rdbms, T(<<"backend">>, <<"rdbms">>)),
 1415:     ?cfgh(P ++ [validity_period, access], #{unit => minutes, value => 13},
 1416:           T(<<"validity_period">>,
 1417:             #{<<"access">> => #{<<"value">> => 13, <<"unit">> => <<"minutes">>}})),
 1418:     ?cfgh(P ++ [validity_period, refresh], #{unit => days, value => 31},
 1419:           T(<<"validity_period">>,
 1420:             #{<<"refresh">> => #{<<"value">> => 31, <<"unit">> => <<"days">>}})),
 1421:     ?errh(T(<<"backend">>, <<"nosql">>)),
 1422:     ?errh(T(<<"validity_period">>,
 1423:             #{<<"access">> => #{<<"value">> => -1, <<"unit">> => <<"minutes">>}})),
 1424:     ?errh(T(<<"validity_period">>,
 1425:             #{<<"access">> => #{<<"value">> => 10, <<"unit">> => <<"centuries">>}})),
 1426:     ?errh(T(<<"validity_period">>, #{<<"access">> => #{<<"value">> => 10}})),
 1427:     ?errh(T(<<"validity_period">>, #{<<"access">> => #{<<"unit">> => <<"days">>}})).
 1428: 
 1429: mod_blocking(_Config) ->
 1430:     test_privacy_opts(mod_blocking).
 1431: 
 1432: mod_bosh(_Config) ->
 1433:     check_module_defaults(mod_bosh),
 1434:     P = [modules, mod_bosh],
 1435:     T = fun(K, V) -> #{<<"modules">> => #{<<"mod_bosh">> => #{K => V}}} end,
 1436:     ?cfgh(P ++ [backend], mnesia, T(<<"backend">>, <<"mnesia">>)),
 1437:     ?cfgh(P ++ [inactivity], 10, T(<<"inactivity">>, 10)),
 1438:     ?cfgh(P ++ [inactivity], infinity, T(<<"inactivity">>, <<"infinity">>)),
 1439:     ?cfgh(P ++ [max_wait], 10, T(<<"max_wait">>, 10)),
 1440:     ?cfgh(P ++ [max_wait], infinity, T(<<"max_wait">>, <<"infinity">>)),
 1441:     ?cfgh(P ++ [server_acks], true, T(<<"server_acks">>, true)),
 1442:     ?cfgh(P ++ [server_acks], false, T(<<"server_acks">>, false)),
 1443:     ?cfgh(P ++ [max_pause], 10, T(<<"max_pause">>, 10)),
 1444:     ?errh(T(<<"backend">>, <<"nodejs">>)),
 1445:     ?errh(T(<<"inactivity">>, 0)),
 1446:     ?errh(T(<<"inactivity">>, <<"10">>)),
 1447:     ?errh(T(<<"inactivity">>, <<"inactivity">>)),
 1448:     ?errh(T(<<"max_wait">>, <<"10">>)),
 1449:     ?errh(T(<<"max_wait">>, 0)),
 1450:     ?errh(T(<<"server_acks">>, -1)),
 1451:     ?errh(T(<<"maxpause">>, 0)).
 1452: 
 1453: mod_caps(_Config) ->
 1454:     check_module_defaults(mod_caps),
 1455:     T = fun(K, V) -> #{<<"modules">> => #{<<"mod_caps">> => #{K => V}}} end,
 1456:     P = [modules, mod_caps],
 1457:     ?cfgh(P ++ [cache_size], 10, T(<<"cache_size">>, 10)),
 1458:     ?cfgh(P ++ [cache_life_time], 10, T(<<"cache_life_time">>, 10)),
 1459:     ?errh(T(<<"cache_size">>, 0)),
 1460:     ?errh(T(<<"cache_size">>, <<"infinity">>)),
 1461:     ?errh(T(<<"cache_life_time">>, 0)),
 1462:     ?errh(T(<<"cache_life_time">>, <<"infinity">>)).
 1463: 
 1464: mod_cache_users(_Config) ->
 1465:     check_module_defaults(mod_cache_users),
 1466:     P = [modules, mod_cache_users],
 1467:     T = fun(K, V) -> #{<<"modules">> => #{<<"mod_cache_users">> => #{K => V}}} end,
 1468:     ?cfgh(P ++ [time_to_live], 8600, T(<<"time_to_live">>, 8600)),
 1469:     ?cfgh(P ++ [time_to_live], infinity, T(<<"time_to_live">>, <<"infinity">>)),
 1470:     ?cfgh(P ++ [number_of_segments], 10, T(<<"number_of_segments">>, 10)),
 1471:     ?cfgh(P ++ [strategy], fifo, T(<<"strategy">>, <<"fifo">>)),
 1472:     ?errh(T(<<"time_to_live">>, 0)),
 1473:     ?errh(T(<<"strategy">>, <<"lifo">>)),
 1474:     ?errh(T(<<"number_of_segments">>, 0)),
 1475:     ?errh(T(<<"number_of_segments">>, <<"infinity">>)).
 1476: 
 1477: mod_carboncopy(_Config) ->
 1478:     check_iqdisc(mod_carboncopy).
 1479: 
 1480: mod_csi(_Config) ->
 1481:     check_module_defaults(mod_csi),
 1482:     T = fun(K, V) -> #{<<"modules">> => #{<<"mod_csi">> => #{K => V}}} end,
 1483:     P = [modules, mod_csi],
 1484:     ?cfgh(P ++ [buffer_max], 10, T(<<"buffer_max">>, 10)),
 1485:     ?cfgh(P ++ [buffer_max], infinity, T(<<"buffer_max">>, <<"infinity">>)),
 1486:     ?errh(T(<<"buffer_max">>, -1)).
 1487: 
 1488: mod_disco(_Config) ->
 1489:     check_module_defaults(mod_disco),
 1490:     check_iqdisc(mod_disco),
 1491:     P = [modules, mod_disco],
 1492:     T = fun(K, V) -> #{<<"modules">> => #{<<"mod_disco">> => #{K => V}}} end,
 1493:     ?cfgh(P ++ [users_can_see_hidden_services], true,
 1494:           T(<<"users_can_see_hidden_services">>, true)),
 1495:     ?cfgh(P ++ [users_can_see_hidden_services], false,
 1496:           T(<<"users_can_see_hidden_services">>, false)),
 1497:     %% extra_domains are binaries
 1498:     ?cfgh(P ++ [extra_domains], [<<"localhost">>, <<"erlang-solutions.com">>],
 1499:           T(<<"extra_domains">>, [<<"localhost">>, <<"erlang-solutions.com">>])),
 1500:     ?cfgh(P ++ [extra_domains], [],
 1501:           T(<<"extra_domains">>, [])),
 1502:     Info = #{<<"name">> => <<"abuse-address">>,
 1503:              <<"urls">> => [<<"admin@example.com">>]},
 1504:     SpiritUrls = [<<"spirit1@localhost">>, <<"spirit2@localhost">>],
 1505:     ?cfgh(P ++ [server_info],
 1506:           [#{name => <<"abuse-address">>, urls => [<<"admin@example.com">>]},
 1507:            #{name => <<"friendly-spirits">>, urls => SpiritUrls, modules => [mod_muc, mod_disco]}],
 1508:           T(<<"server_info">>, [Info, #{<<"name">> => <<"friendly-spirits">>,
 1509:                                         <<"urls">> => SpiritUrls,
 1510:                                         <<"modules">> => [<<"mod_muc">>, <<"mod_disco">>]}])),
 1511:     ?errh(T(<<"users_can_see_hidden_services">>, 1)),
 1512:     ?errh(T(<<"users_can_see_hidden_services">>, <<"true">>)),
 1513:     ?errh(T(<<"extra_domains">>, [<<"user@localhost">>])),
 1514:     ?errh(T(<<"extra_domains">>, [1])),
 1515:     ?errh(T(<<"extra_domains">>, <<"domains domains domains">>)),
 1516:     ?errh(T(<<"server_info">>, [Info#{<<"name">> => 1}])),
 1517:     ?errh(T(<<"server_info">>, [Info#{<<"name">> => <<"">>}])),
 1518:     ?errh(T(<<"server_info">>, [Info#{<<"modules">> => <<"roll">>}])),
 1519:     ?errh(T(<<"server_info">>, [Info#{<<"modules">> => [<<"meow_meow_meow">>]}])),
 1520:     ?errh(T(<<"server_info">>, [Info#{<<"urls">> => [1]}])),
 1521:     ?errh(T(<<"server_info">>, [Info#{<<"urls">> => [<<"">>]}])),
 1522:     ?errh(T(<<"server_info">>, [maps:remove(<<"name">>, Info)])),
 1523:     ?errh(T(<<"server_info">>, [maps:remove(<<"urls">>, Info)])).
 1524: 
 1525: mod_extdisco(_Config) ->
 1526:     check_module_defaults(mod_extdisco),
 1527:     check_iqdisc(mod_extdisco),
 1528:     P = [modules, mod_extdisco, service],
 1529:     T = fun(Opts) -> #{<<"modules">> =>
 1530:                            #{<<"mod_extdisco">> =>
 1531:                                  #{<<"service">> => [Opts]}}}
 1532:         end,
 1533:     RequiredOpts = #{<<"type">> => <<"stun">>, <<"host">> => <<"stun1">>},
 1534:     Service = #{type => stun, host => <<"stun1">>},
 1535:     ?cfgh(P, [Service], T(RequiredOpts)),
 1536:     ?cfgh(P, [Service#{port => 3478}], T(RequiredOpts#{<<"port">> => 3478})),
 1537:     ?cfgh(P, [Service#{transport => <<"udp">>}], T(RequiredOpts#{<<"transport">> => <<"udp">>})),
 1538:     ?cfgh(P, [Service#{username => <<"user">>}], T(RequiredOpts#{<<"username">> => <<"user">>})),
 1539:     ?cfgh(P, [Service#{password => <<"pass">>}], T(RequiredOpts#{<<"password">> => <<"pass">>})),
 1540:     [?errh(T(maps:remove(Key, RequiredOpts))) || Key <- maps:keys(RequiredOpts)],
 1541:     [?errh(T(RequiredOpts#{Key => 1})) || Key <- maps:keys(RequiredOpts)],
 1542:     ?errh(T(RequiredOpts#{<<"type">> => <<>>})),
 1543:     ?errh(T(RequiredOpts#{<<"host">> => <<>>})),
 1544:     ?errh(T(RequiredOpts#{<<"port">> => -1})),
 1545:     ?errh(T(RequiredOpts#{<<"transport">> => <<>>})),
 1546:     ?errh(T(RequiredOpts#{<<"username">> => <<>>})),
 1547:     ?errh(T(RequiredOpts#{<<"password">> => <<>>})).
 1548: 
 1549: mod_inbox(_Config) ->
 1550:     check_module_defaults(mod_inbox),
 1551:     check_iqdisc(mod_inbox),
 1552:     P = [modules, mod_inbox],
 1553:     T = fun(Opts) -> #{<<"modules">> => #{<<"mod_inbox">> => Opts}} end,
 1554:     ChatMarkers = [<<"displayed">>, <<"received">>, <<"acknowledged">>],
 1555:     ?cfgh(P ++ [backend], rdbms, T(#{<<"backend">> => <<"rdbms">>})),
 1556:     ?cfgh(P ++ [async_writer], #{pool_size => 8}, T(#{<<"async_writer">> => #{<<"pool_size">> => 8}})),
 1557:     ?cfgh(P ++ [reset_markers], ChatMarkers, T(#{<<"reset_markers">> => ChatMarkers})),
 1558:     ?cfgh(P ++ [groupchat], [muc, muclight], T(#{<<"groupchat">> => [<<"muc">>, <<"muclight">>]})),
 1559:     ?cfgh(P ++ [boxes],
 1560:           [<<"inbox">>, <<"archive">>, <<"bin">>, <<"favourites">>, <<"spam">>],
 1561:           T(#{<<"boxes">> => [<<"favourites">>, <<"spam">>]})),
 1562:     ?cfgh(P ++ [bin_ttl], 30, T(#{<<"bin_ttl">> => 30})),
 1563:     ?cfgh(P ++ [bin_clean_after], 43200000, T(#{<<"bin_clean_after">> => 12})),
 1564:     ?cfgh(P ++ [aff_changes], true, T(#{<<"aff_changes">> => true})),
 1565:     ?cfgh(P ++ [remove_on_kicked], false, T(#{<<"remove_on_kicked">> => false})),
 1566:     ?errh(T(#{<<"backend">> => <<"nodejs">>})),
 1567:     ?errh(T(#{<<"pool_size">> => -1})),
 1568:     ?errh(T(#{<<"reset_markers">> => 1})),
 1569:     ?errh(T(#{<<"reset_markers">> => [<<"destroyed">>]})),
 1570:     ?errh(T(#{<<"groupchat">> => [<<"test">>]})),
 1571:     ?errh(T(#{<<"boxes">> => [<<"archive">>]})),
 1572:     ?errh(T(#{<<"boxes">> => [<<"duplicate">>, <<"duplicate">>]})),
 1573:     ?errh(T(#{<<"boxes">> => <<"test">>})),
 1574:     ?errh(T(#{<<"bin_ttl">> => true})),
 1575:     ?errh(T(#{<<"bin_clean_after">> => -1})),
 1576:     ?errh(T(#{<<"aff_changes">> => 1})),
 1577:     ?errh(T(#{<<"remove_on_kicked">> => 1})).
 1578: 
 1579: mod_global_distrib(_Config) ->
 1580:     P = [modules, mod_global_distrib],
 1581:     T = fun(Opts) -> #{<<"modules">> => #{<<"mod_global_distrib">> => Opts}} end,
 1582:     RequiredOpts = global_distrib_required_opts(),
 1583:     ExpectedCfg = mod_config(mod_global_distrib, global_distrib_expected_config()),
 1584:     ?cfgh(P, ExpectedCfg, T(RequiredOpts)),
 1585:     ?cfgh(P ++ [message_ttl], 42,
 1586:           T(RequiredOpts#{<<"message_ttl">> => 42})),
 1587:     ?cfgh(P ++ [hosts_refresh_interval], 100,
 1588:           T(RequiredOpts#{<<"hosts_refresh_interval">> => 100})),
 1589:     [?errh(T(maps:remove(Key, RequiredOpts))) || Key <- maps:keys(RequiredOpts)],
 1590:     ?errh(T(RequiredOpts#{<<"global_host">> => <<>>})),
 1591:     ?errh(T(RequiredOpts#{<<"local_host">> => <<>>})),
 1592:     ?errh(T(RequiredOpts#{<<"local_host">> => <<"nohost">>})), % passed to 'endpoints', not resolved
 1593:     ?errh(T(RequiredOpts#{<<"message_ttl">> => -1})),
 1594:     ?errh(T(RequiredOpts#{<<"hosts_refresh_interval">> => -1})).
 1595: 
 1596: mod_global_distrib_connections(_Config) ->
 1597:     RequiredOpts = global_distrib_required_opts(),
 1598:     P = [modules, mod_global_distrib, connections],
 1599:     T = fun(Opts) -> #{<<"modules">> =>
 1600:                            #{<<"mod_global_distrib">> =>
 1601:                                  RequiredOpts#{<<"connections">> => Opts}}}
 1602:         end,
 1603:     ?cfgh(P, global_distrib_expected_connections(), T(#{})),
 1604:     ?cfgh(P ++ [connections_per_endpoint], 22,
 1605:           T(#{<<"connections_per_endpoint">> => 22})),
 1606:     ?cfgh(P ++ [endpoint_refresh_interval], 120,
 1607:           T(#{<<"endpoint_refresh_interval">> => 120})),
 1608:     ?cfgh(P ++ [endpoint_refresh_interval_when_empty], 5,
 1609:           T(#{<<"endpoint_refresh_interval_when_empty">> => 5})),
 1610:     ?cfgh(P ++ [disabled_gc_interval], 60,
 1611:           T(#{<<"disabled_gc_interval">> => 60})),
 1612:     ?errh(T(#{<<"connections_per_endpoint">> => -1})),
 1613:     ?errh(T(#{<<"endpoint_refresh_interval">> => 0})),
 1614:     ?errh(T(#{<<"endpoint_refresh_interval_when_empty">> => 0})),
 1615:     ?errh(T(#{<<"disabled_gc_interval">> => 0})).
 1616: 
 1617: mod_global_distrib_connections_endpoints(_Config) ->
 1618:     check_mod_global_distrib_endpoint_opts(<<"endpoints">>),
 1619:     RequiredModOpts = global_distrib_required_opts(),
 1620:     P = [modules, mod_global_distrib, connections],
 1621:     T = fun(Opts) -> #{<<"modules">> =>
 1622:                            #{<<"mod_global_distrib">> =>
 1623:                                  RequiredModOpts#{<<"connections">> => #{<<"endpoints">> => Opts}}}}
 1624:         end,
 1625: 
 1626:     %% 'enpoints' propagate to 'advertised_endpoints' and 'resolved_endpoints'
 1627:     ?cfgh([{P ++ [endpoints], [{"172.16.0.2", 5555}]},
 1628:            {P ++ [advertised_endpoints], [{"172.16.0.2", 5555}]},
 1629:            {P ++ [resolved_endpoints], [{{172, 16, 0, 2}, 5555}]}],
 1630:           T([#{<<"host">> => <<"172.16.0.2">>, <<"port">> => 5555}])),
 1631: 
 1632:     ?cfgh([{P ++ [endpoints], [{"localhost", 15555}]},
 1633:            {P ++ [advertised_endpoints], [{"localhost", 15555}]},
 1634:            {P ++ [resolved_endpoints], [{{0, 0, 0, 0, 0, 0, 0, 1}, 15555},
 1635:                                         {{127, 0, 0, 1}, 15555}]
 1636:            }],
 1637:           T([#{<<"host">> => <<"localhost">>, <<"port">> => 15555}])),
 1638:     ?errh(T([#{<<"host">> => <<"172.16.0.299">>, <<"port">> => 5555}])),
 1639:     ?errh(T([#{<<"host">> => <<"nohost">>, <<"port">> => 15555}])).
 1640: 
 1641: mod_global_distrib_connections_advertised_endpoints(_Config) ->
 1642:     check_mod_global_distrib_endpoint_opts(<<"advertised_endpoints">>).
 1643: 
 1644: check_mod_global_distrib_endpoint_opts(OptKey) ->
 1645:     RequiredModOpts = global_distrib_required_opts(),
 1646:     P = [modules, mod_global_distrib, connections, binary_to_atom(OptKey)],
 1647:     T = fun(Opts) -> #{<<"modules">> =>
 1648:                            #{<<"mod_global_distrib">> =>
 1649:                                  RequiredModOpts#{<<"connections">> => #{OptKey => Opts}}}}
 1650:         end,
 1651:     RequiredOpts = #{<<"host">> => <<"172.16.0.2">>, <<"port">> => 5678},
 1652:     ?cfgh(P, [{"172.16.0.2", 5678}], T([RequiredOpts])),
 1653:     [?errh(T(maps:remove(Key, RequiredOpts))) || Key <- maps:keys(RequiredOpts)],
 1654:     ?errh(T([RequiredOpts#{<<"host">> => <<>>}])),
 1655:     ?errh(T([RequiredOpts#{<<"port">> => -1}])).
 1656: 
 1657: mod_global_distrib_connections_tls(_Config) ->
 1658:     RequiredModOpts = global_distrib_required_opts(),
 1659:     P = host_key([modules, mod_global_distrib, connections, tls]),
 1660:     T = fun(Opts) -> #{<<"modules">> =>
 1661:                            #{<<"mod_global_distrib">> =>
 1662:                                  RequiredModOpts#{<<"connections">> => #{<<"tls">> => Opts}}}}
 1663:         end,
 1664:     % Does not test host_config, but other tests do that,
 1665:     % and this module should be enabled globally anyway
 1666:     test_fast_tls_server(P, T).
 1667: 
 1668: mod_global_distrib_redis(_Config) ->
 1669:     RequiredModOpts = global_distrib_required_opts(),
 1670:     P = [modules, mod_global_distrib, redis],
 1671:     T = fun(Opts) -> #{<<"modules">> =>
 1672:                            #{<<"mod_global_distrib">> =>
 1673:                                  RequiredModOpts#{<<"redis">> => Opts}}}
 1674:         end,
 1675:     ?cfgh(P, default_config(P), T(#{})),
 1676:     ?cfgh(P ++ [pool], global_distrib, T(#{<<"pool">> => <<"global_distrib">>})),
 1677:     ?cfgh(P ++ [expire_after], 120, T(#{<<"expire_after">> => 120})),
 1678:     ?cfgh(P ++ [refresh_after], 60, T(#{<<"refresh_after">> => 60})),
 1679:     ?errh(T(#{<<"pool">> => <<"">>})),
 1680:     ?errh(T(#{<<"expire_after">> => 0})),
 1681:     ?errh(T(#{<<"refresh_after">> => -1})).
 1682: 
 1683: mod_global_distrib_cache(_Config) ->
 1684:     RequiredModOpts = global_distrib_required_opts(),
 1685:     P = [modules, mod_global_distrib, cache],
 1686:     T = fun(Opts) -> #{<<"modules">> =>
 1687:                            #{<<"mod_global_distrib">> =>
 1688:                                  RequiredModOpts#{<<"cache">> => Opts}}}
 1689:         end,
 1690:     ?cfgh(P, default_config(P), T(#{})),
 1691:     ?cfgh(P ++ [cache_missed], false, T(#{<<"cache_missed">> => false})),
 1692:     ?cfgh(P ++ [domain_lifetime_seconds], 60, T(#{<<"domain_lifetime_seconds">> => 60})),
 1693:     ?cfgh(P ++ [jid_lifetime_seconds], 30, T(#{<<"jid_lifetime_seconds">> => 30})),
 1694:     ?cfgh(P ++ [max_jids], 9999, T(#{<<"max_jids">> => 9999})),
 1695:     ?errh(T(#{<<"cache_missed">> => <<"yes">>})),
 1696:     ?errh(T(#{<<"domain_lifetime_seconds">> => -1})),
 1697:     ?errh(T(#{<<"jid_lifetime_seconds">> => -1})),
 1698:     ?errh(T(#{<<"max_jids">> => -1})).
 1699: 
 1700: mod_global_distrib_bounce(_Config) ->
 1701:     RequiredModOpts = global_distrib_required_opts(),
 1702:     P = [modules, mod_global_distrib, bounce],
 1703:     T = fun(Opts) -> #{<<"modules">> =>
 1704:                            #{<<"mod_global_distrib">> =>
 1705:                                  RequiredModOpts#{<<"bounce">> => Opts}}}
 1706:         end,
 1707:     ?cfgh(P, default_config(P), T(#{})),
 1708:     ?cfgh(P ++ [enabled], false, T(#{<<"enabled">> => false})),
 1709:     ?cfgh(P ++ [resend_after_ms], 300, T(#{<<"resend_after_ms">> => 300})),
 1710:     ?cfgh(P ++ [max_retries], 3, T(#{<<"max_retries">> => 3})),
 1711:     ?errh(T(#{<<"enabled">> => <<"">>})),
 1712:     ?errh(T(#{<<"resend_after_ms">> => -1})),
 1713:     ?errh(T(#{<<"max_retries">> => -1})).
 1714: 
 1715: global_distrib_required_opts() ->
 1716:     #{<<"global_host">> => <<"global.example.com">>,
 1717:       <<"local_host">> => <<"localhost">>}.
 1718: 
 1719: global_distrib_expected_config() ->
 1720:     #{global_host => <<"global.example.com">>,
 1721:       local_host => <<"localhost">>,
 1722:       connections => global_distrib_expected_connections()}.
 1723: 
 1724: global_distrib_expected_connections() ->
 1725:     config([modules, mod_global_distrib, connections],
 1726:            #{endpoints => [{"localhost", 5555}],
 1727:              advertised_endpoints => [{"localhost", 5555}],
 1728:              resolved_endpoints => [{{0, 0, 0, 0, 0, 0, 0, 1}, 5555},
 1729:                                     {{127, 0, 0, 1}, 5555}]}).
 1730: 
 1731: mod_event_pusher_sns(_Config) ->
 1732:     RequiredOpts = #{<<"sns_host">> => <<"sns.eu-west-1.amazonaws.com">>,
 1733:                      <<"region">> => <<"eu-west-1">>,
 1734:                      <<"access_key_id">> => <<"AKIAIOSFODNN7EXAMPLE">>,
 1735:                      <<"secret_access_key">> => <<"KEY">>,
 1736:                      <<"account_id">> => <<"123456789012">>},
 1737:     ExpectedCfg = #{sns_host => "sns.eu-west-1.amazonaws.com",
 1738:                     region => "eu-west-1",
 1739:                     access_key_id => "AKIAIOSFODNN7EXAMPLE",
 1740:                     secret_access_key => "KEY",
 1741:                     account_id => "123456789012"},
 1742:     P = [modules, mod_event_pusher, sns],
 1743:     T = fun(Opts) -> #{<<"modules">> =>
 1744:                            #{<<"mod_event_pusher">> => #{<<"sns">> => Opts}}}
 1745:         end,
 1746:     ?cfgh(P, config(P, ExpectedCfg), T(RequiredOpts)),
 1747:     ?cfgh(P ++ [presence_updates_topic], "pres",
 1748:           T(RequiredOpts#{<<"presence_updates_topic">> => <<"pres">>})),
 1749:     ?cfgh(P ++ [pm_messages_topic], "pm",
 1750:           T(RequiredOpts#{<<"pm_messages_topic">> => <<"pm">>})),
 1751:     ?cfgh(P ++ [muc_messages_topic], "muc",
 1752:           T(RequiredOpts#{<<"muc_messages_topic">> => <<"muc">>})),
 1753:     ?cfgh(P ++ [plugin_module], mod_event_pusher_sns_defaults,
 1754:           T(RequiredOpts#{<<"plugin_module">> => <<"mod_event_pusher_sns_defaults">>})),
 1755:     ?cfgh(P ++ [pool_size], 10,
 1756:           T(RequiredOpts#{<<"pool_size">> => 10})),
 1757:     ?cfgh(P ++ [publish_retry_count], 1,
 1758:           T(RequiredOpts#{<<"publish_retry_count">> => 1})),
 1759:     ?cfgh(P ++ [publish_retry_time_ms], 100,
 1760:           T(RequiredOpts#{<<"publish_retry_time_ms">> => 100})),
 1761:     [?errh(T(maps:remove(Key, RequiredOpts))) || Key <- maps:keys(RequiredOpts)],
 1762:     [?errh(T(RequiredOpts#{Key => 1})) || Key <- maps:keys(RequiredOpts)],
 1763:     ?errh(T(RequiredOpts#{<<"presence_updates_topic">> => #{}})),
 1764:     ?errh(T(RequiredOpts#{<<"pm_messages_topic">> => true})),
 1765:     ?errh(T(RequiredOpts#{<<"muc_messages_topic">> => [1, 2]})),
 1766:     ?errh(T(RequiredOpts#{<<"plugin_module">> => <<"plug_and_play">>})),
 1767:     ?errh(T(RequiredOpts#{<<"pool_size">> => 0})),
 1768:     ?errh(T(RequiredOpts#{<<"publish_retry_count">> => -1})),
 1769:     ?errh(T(RequiredOpts#{<<"publish_retry_time_ms">> => -1})).
 1770: 
 1771: mod_event_pusher_push(_Config) ->
 1772:     P = [modules, mod_event_pusher, push],
 1773:     T = fun(Opts) -> #{<<"modules">> =>
 1774:                            #{<<"mod_event_pusher">> => #{<<"push">> => Opts}}}
 1775:         end,
 1776:     ?cfgh(P, default_config(P), T(#{})),
 1777:     check_iqdisc(P, T),
 1778:     test_wpool(P ++ [wpool], fun(Opts) -> T(#{<<"wpool">> => Opts}) end),
 1779:     ?cfgh(P ++ [backend], rdbms, T(#{<<"backend">> => <<"rdbms">>})),
 1780:     ?cfgh(P ++ [plugin_module], mod_event_pusher_push_plugin_enhanced,
 1781:           T(#{<<"plugin_module">> => <<"mod_event_pusher_push_plugin_enhanced">>})),
 1782:     ?cfgh(P ++ [virtual_pubsub_hosts], [{fqdn, <<"host1">>}, {fqdn, <<"host2">>}],
 1783:           T(#{<<"virtual_pubsub_hosts">> => [<<"host1">>, <<"host2">>]})),
 1784:     ?cfgh(P ++ [virtual_pubsub_hosts], [{prefix, <<"pubsub.">>}, {prefix, <<"pub-sub.">>}],
 1785:           T(#{<<"virtual_pubsub_hosts">> => [<<"pubsub.@HOST@">>, <<"pub-sub.@HOST@">>]})),
 1786:     ?errh(T(#{<<"backend">> => <<"redis">>})),
 1787:     ?errh(T(#{<<"wpool">> => true})),
 1788:     ?errh(T(#{<<"plugin_module">> => <<"wow_cool_but_missing">>})),
 1789:     ?errh(T(#{<<"plugin_module">> => 1})),
 1790:     ?errh(T(#{<<"virtual_pubsub_hosts">> => [<<"host with whitespace">>]})),
 1791:     ?errh(T(#{<<"virtual_pubsub_hosts">> => [<<"invalid.sub@HOST@">>]})),
 1792:     ?errh(T(#{<<"virtual_pubsub_hosts">> => [<<"invalid.sub.@HOST@.as.well">>]})).
 1793: 
 1794: test_wpool(P, T) ->
 1795:     ?cfgh(P, default_config(P), T(#{})),
 1796:     ?cfgh(P ++ [workers], 200, T(#{<<"workers">> => 200})),
 1797:     ?cfgh(P ++ [strategy], random_worker, T(#{<<"strategy">> => <<"random_worker">>})),
 1798:     ?cfgh(P ++ [call_timeout], 1000, T(#{<<"call_timeout">> => 1000})),
 1799:     ?errh(T(#{<<"workers">> => 0})),
 1800:     ?errh(T(#{<<"strategy">> => <<"worst_worker">>})),
 1801:     ?errh(T(#{<<"workers">> => 0})).
 1802: 
 1803: mod_event_pusher_http(_Config) ->
 1804:     P = [modules, mod_event_pusher, http, handlers],
 1805:     T = fun(Handlers) -> #{<<"modules">> =>
 1806:                            #{<<"mod_event_pusher">> =>
 1807:                                  #{<<"http">> => #{<<"handlers">> => Handlers}}}}
 1808:         end,
 1809:     DefaultHandler = mod_event_pusher_http_handler(),
 1810:     ?cfgh(P, [DefaultHandler], T([#{}])),
 1811:     ?cfgh(P, [DefaultHandler#{pool_name => my_pool}],
 1812:           T([#{<<"pool_name">> => <<"my_pool">>}])),
 1813:     ?cfgh(P, [DefaultHandler#{path => <<"notifications">>}],
 1814:           T([#{<<"path">> => <<"/notifications">>}])),
 1815:     ?cfgh(P, [DefaultHandler#{callback_module => mod_event_pusher_http}], % existing module
 1816:           T([#{<<"callback_module">> => <<"mod_event_pusher_http">>}])),
 1817:     ?cfgh(P, [DefaultHandler, DefaultHandler#{pool_name => my_pool}], % two handlers
 1818:           T([#{}, #{<<"pool_name">> => <<"my_pool">>}])),
 1819:     ?errh(T([#{<<"pool_name">> => <<>>}])),
 1820:     ?errh(T([#{<<"path">> => true}])),
 1821:     ?errh(T([#{<<"callback_module">> => <<"wow_cool_but_missing">>}])),
 1822:     ?errh(T([#{<<"callback_module">> => 1}])),
 1823:     ?errh(T([#{}, #{}])). % handlers have to be unique
 1824: 
 1825: mod_event_pusher_rabbit(_Config) ->
 1826:     P = [modules, mod_event_pusher, rabbit],
 1827:     T = fun(Key, Opts) -> #{<<"modules">> =>
 1828:                                 #{<<"mod_event_pusher">> =>
 1829:                                       #{<<"rabbit">> => #{Key => Opts}}}}
 1830:         end,
 1831:     test_event_pusher_rabbit_exchange(P ++ [presence_exchange],
 1832:                                       fun(Opts) -> T(<<"presence_exchange">>, Opts) end),
 1833:     test_event_pusher_rabbit_msg_exchange(P ++ [chat_msg_exchange],
 1834:                                           fun(Opts) -> T(<<"chat_msg_exchange">>, Opts) end),
 1835:     test_event_pusher_rabbit_msg_exchange(P ++ [groupchat_msg_exchange],
 1836:                                           fun(Opts) -> T(<<"groupchat_msg_exchange">>, Opts) end).
 1837: 
 1838: test_event_pusher_rabbit_msg_exchange(P, T) ->
 1839:     test_event_pusher_rabbit_exchange(P, T),
 1840:     ?cfgh(P, default_config(P), T(#{})),
 1841:     ?cfgh(P ++ [sent_topic], <<"outgoing">>, T(#{<<"sent_topic">> => <<"outgoing">>})),
 1842:     ?cfgh(P ++ [recv_topic], <<"incoming">>, T(#{<<"recv_topic">> => <<"incoming">>})),
 1843:     ?errh(T(#{<<"sent_topic">> => <<>>})),
 1844:     ?errh(T(#{<<"recv_topic">> => <<>>})).
 1845: 
 1846: test_event_pusher_rabbit_exchange(P, T) ->
 1847:     ?cfgh(P, default_config(P), T(#{})),
 1848:     ?cfgh(P ++ [name], <<"notifications">>, T(#{<<"name">> => <<"notifications">>})),
 1849:     ?cfgh(P ++ [type], <<"direct">>, T(#{<<"type">> => <<"direct">>})),
 1850:     ?errh(T(#{<<"name">> => <<>>})),
 1851:     ?errh(T(#{<<"type">> => <<>>})).
 1852: 
 1853: mod_http_upload(_Config) ->
 1854:     T = fun(Opts) -> #{<<"modules">> => #{<<"mod_http_upload">> => Opts}} end,
 1855:     P = [modules, mod_http_upload],
 1856:     RequiredOpts = #{<<"s3">> => http_upload_s3_required_opts()},
 1857:     S3Cfg = http_upload_s3_expected_cfg(),
 1858:     ?cfgh(P, mod_config(mod_http_upload,
 1859:         #{host => <<"upload.@HOST@">>,
 1860:           s3 => config_parser_helper:config([modules, mod_http_upload, s3], S3Cfg)
 1861:          }),
 1862:         T(RequiredOpts)),
 1863:     ?cfgh(P ++ [s3], S3Cfg#{add_acl => false}, T(RequiredOpts)),
 1864:     ?cfgh(P ++ [host], {prefix, <<"upload.">>},
 1865:           T(RequiredOpts#{<<"host">> => <<"upload.@HOST@">>})),
 1866:     ?cfgh(P ++ [host], {fqdn, <<"upload.test">>},
 1867:           T(RequiredOpts#{<<"host">> => <<"upload.test">>})),
 1868:     ?cfgh(P ++ [backend], s3,
 1869:           T(RequiredOpts#{<<"backend">> => <<"s3">>})),
 1870:     ?cfgh(P ++ [expiration_time], 666,
 1871:           T(RequiredOpts#{<<"expiration_time">> => 666})),
 1872:     ?cfgh(P ++ [token_bytes], 32,
 1873:           T(RequiredOpts#{<<"token_bytes">> => 32})),
 1874:     ?cfgh(P ++ [max_file_size], 42,
 1875:           T(RequiredOpts#{<<"max_file_size">> => 42})),
 1876:     ?errh(T(#{})), %% missing 's3'
 1877:     ?errh(T(RequiredOpts#{<<"backend">> => <<"">>})),
 1878:     ?errh(T(RequiredOpts#{<<"expiration_time">> => 0})),
 1879:     ?errh(T(RequiredOpts#{<<"token_bytes">> => 0})),
 1880:     ?errh(T(RequiredOpts#{<<"max_file_size">> => 0})),
 1881:     ?errh(T(RequiredOpts#{<<"host">> => <<"is this a host? no.">>})),
 1882:     ?errh(T(RequiredOpts#{<<"host">> => [<<"invalid.sub@HOST@">>]})),
 1883:     ?errh(T(RequiredOpts#{<<"host">> => [<<"invalid.sub.@HOST@.as.well">>]})),
 1884:     ?errh(T(RequiredOpts#{<<"host">> => [<<"not.supported.any.more.@HOSTS@">>]})),
 1885:     check_iqdisc(mod_http_upload, RequiredOpts).
 1886: 
 1887: mod_http_upload_s3(_Config) ->
 1888:     T = fun(Opts) -> #{<<"modules">> => #{<<"mod_http_upload">> =>
 1889:                                               #{<<"s3">> => Opts}}} end,
 1890:     RequiredOpts = http_upload_s3_required_opts(),
 1891:     ExpectedCfg = http_upload_s3_expected_cfg(),
 1892:     P = [modules, mod_http_upload, s3],
 1893:     ?cfgh(P, ExpectedCfg#{add_acl => false}, T(RequiredOpts)),
 1894:     ?cfgh(P ++ [add_acl], true, T(RequiredOpts#{<<"add_acl">> => true})),
 1895:     [?errh(T(maps:remove(Key, RequiredOpts))) || Key <- maps:keys(RequiredOpts)],
 1896:     ?errh(T(RequiredOpts#{<<"bucket_url">> => <<>>})),
 1897:     ?errh(T(RequiredOpts#{<<"region">> => true})),
 1898:     ?errh(T(RequiredOpts#{<<"access_key_id">> => []})),
 1899:     ?errh(T(RequiredOpts#{<<"secret_access_key">> => 3})),
 1900:     ?errh(T(RequiredOpts#{<<"add_acl">> => <<"true">>})).
 1901: 
 1902: http_upload_s3_required_opts() ->
 1903:     #{<<"bucket_url">> => <<"https://s3-eu-west-1.amazonaws.com/mybucket">>,
 1904:       <<"region">> => <<"antarctica-1">>,
 1905:       <<"access_key_id">> => <<"PLEASE">>,
 1906:       <<"secret_access_key">> => <<"ILOVEU">>}.
 1907: 
 1908: http_upload_s3_expected_cfg() ->
 1909:     #{access_key_id => <<"PLEASE">>,
 1910:       bucket_url => <<"https://s3-eu-west-1.amazonaws.com/mybucket">>,
 1911:       region => <<"antarctica-1">>,
 1912:       secret_access_key => <<"ILOVEU">>}.
 1913: 
 1914: mod_jingle_sip(_Config) ->
 1915:     check_module_defaults(mod_jingle_sip),
 1916:     T = fun(Opts) -> #{<<"modules">> => #{<<"mod_jingle_sip">> => Opts}} end,
 1917:     P = [modules, mod_jingle_sip],
 1918:     ?cfgh(P ++ [proxy_host], "proxxxy.com",
 1919:           T(#{<<"proxy_host">> => <<"proxxxy.com">>})),
 1920:     ?cfgh(P ++ [proxy_port], 5601,
 1921:           T(#{<<"proxy_port">> => 5601})),
 1922:     ?cfgh(P ++ [listen_port], 5602,
 1923:           T(#{<<"listen_port">> => 5602})),
 1924:     ?cfgh(P ++ [local_host], "localhost",
 1925:           T(#{<<"local_host">> => <<"localhost">>})),
 1926:     ?cfgh(P ++ [sdp_origin], "127.0.0.1",
 1927:           T(#{<<"sdp_origin">> => <<"127.0.0.1">>})),
 1928:     ?cfgh(P ++ [transport], "tcp",
 1929:           T(#{<<"transport">> => <<"tcp">>})),
 1930:     ?cfgh(P ++ [username_to_phone], [{<<"2000006168">>, <<"+919177074440">>}],
 1931:           T(#{<<"username_to_phone">> => [#{<<"username">> => <<"2000006168">>,
 1932:                                             <<"phone">> => <<"+919177074440">>}]})),
 1933:     ?errh(T(#{<<"proxy_host">> => 1})),
 1934:     ?errh(T(#{<<"proxy_port">> => 1000000})),
 1935:     ?errh(T(#{<<"listen_port">> => -1})),
 1936:     ?errh(T(#{<<"local_host">> => <<>>})),
 1937:     ?errh(T(#{<<"sdp_origin">> => <<"abc">>})).
 1938: 
 1939: mod_keystore(_Config) ->
 1940:     check_module_defaults(mod_keystore),
 1941:     T = fun(Opts) -> #{<<"modules">> => #{<<"mod_keystore">> => Opts}} end,
 1942:     P = [modules, mod_keystore],
 1943:     ?cfgh(P ++ [ram_key_size], 1024,
 1944:           T(#{<<"ram_key_size">> => 1024})),
 1945:     ?errh(T(#{<<"ram_key_size">> => -1})).
 1946: 
 1947: mod_keystore_keys(_Config) ->
 1948:     T = fun(Opts) -> #{<<"modules">> => #{<<"mod_keystore">> =>
 1949:                                               #{<<"keys">> => Opts}}}
 1950:         end,
 1951:     P = [modules, mod_keystore, keys],
 1952:     RequiredOpts = #{<<"name">> => <<"access_secret">>,
 1953:                      <<"type">> => <<"ram">>},
 1954:     ?cfgh(P ++ [access_secret], ram,
 1955:           T([RequiredOpts])),
 1956:     ?cfgh(P ++ [access_secret], {file, "priv/access_psk"},
 1957:           T([RequiredOpts#{<<"type">> => <<"file">>,
 1958:                            <<"path">> => <<"priv/access_psk">>}])),
 1959:     [?errh(T([maps:remove(Key, RequiredOpts)])) || Key <- maps:keys(RequiredOpts)],
 1960:     ?errh(T([RequiredOpts#{<<"name">> => <<>>}])),
 1961:     ?errh(T([RequiredOpts#{<<"type">> => <<"rampampam">>}])),
 1962:     ?errh(T([RequiredOpts#{<<"type">> => <<"file">>}])),
 1963:     ?errh(T([RequiredOpts#{<<"type">> => <<"file">>,
 1964:                            <<"path">> => <<"does/not/exists">>}])),
 1965:     ?errh(T([#{<<"name">> => <<"same_name_twice">>,
 1966:                <<"type">> => <<"ram">>},
 1967:              #{<<"name">> => <<"same_name_twice">>,
 1968:                <<"type">> => <<"file">>,
 1969:                <<"path">> => <<"priv/access_psk">>}])).
 1970: 
 1971: mod_last(_Config) ->
 1972:     check_iqdisc(mod_last),
 1973:     check_module_defaults(mod_last),
 1974:     T = fun(Opts) -> #{<<"modules">> => #{<<"mod_last">> => Opts}} end,
 1975:     P = [modules, mod_last],
 1976:     ?cfgh(P ++ [backend], mnesia, T(#{<<"backend">> => <<"mnesia">>})),
 1977:     ?cfgh(P ++ [backend], rdbms, T(#{<<"backend">> => <<"rdbms">>})),
 1978:     ?cfgh(P ++ [riak, bucket_type], <<"last">>, T(#{<<"backend">> => <<"riak">>})),
 1979:     ?cfgh(P ++ [riak, bucket_type], <<"test">>,
 1980:           T(#{<<"backend">> => <<"riak">>, <<"riak">> => #{<<"bucket_type">> => <<"test">>}})),
 1981:     ?errh(T(#{<<"backend">> => <<"frontend">>})),
 1982:     ?errh(T(#{<<"riak">> => #{<<"bucket_type">> => 1}})).
 1983: 
 1984: mod_mam(_Config) ->
 1985:     check_module_defaults(mod_mam),
 1986:     T = fun(Opts) -> #{<<"modules">> => #{<<"mod_mam">> => Opts}} end,
 1987:     P = [modules, mod_mam],
 1988:     test_cache_config(P ++ [cache], fun(Opts) -> T(#{<<"cache">> => Opts}) end),
 1989:     test_mod_mam(P, T).
 1990: 
 1991: mod_mam_riak(_Config) ->
 1992:     T = fun(Opts) ->
 1993:                 #{<<"modules">> => #{<<"mod_mam">> => Opts#{<<"backend">> => <<"riak">>}}}
 1994:         end,
 1995:     P = [modules, mod_mam, riak],
 1996:     ?cfgh(P, default_config([modules, mod_mam, riak]), T(#{})),
 1997:     ?cfgh(P ++ [bucket_type], <<"mam_bucket">>,
 1998:           T(#{<<"riak">> => #{<<"bucket_type">> => <<"mam_bucket">>}})),
 1999:     ?cfgh(P ++ [search_index], <<"mam_index">>,
 2000:           T(#{<<"riak">> => #{<<"search_index">> => <<"mam_index">>}})),
 2001:     ?errh(T(#{<<"riak">> => #{<<"bucket_type">> => <<>>}})),
 2002:     ?errh(T(#{<<"riak">> => #{<<"search_index">> => <<>>}})).
 2003: 
 2004: mod_mam_pm(_Config) ->
 2005:     T = fun(Opts) -> #{<<"modules">> => #{<<"mod_mam">> => #{<<"pm">> => Opts}}} end,
 2006:     P = [modules, mod_mam, pm],
 2007:     test_mod_mam(P, T),
 2008:     ?cfgh(P, default_config(P), T(#{})),
 2009:     ?cfgh(P ++ [archive_groupchats], true, T(#{<<"archive_groupchats">> => true})),
 2010:     ?cfgh(P ++ [same_mam_id_for_peers], true, T(#{<<"same_mam_id_for_peers">> => true})),
 2011:     ?errh(T(#{<<"host">> => <<"muc.@HOST@">>})), % muc-only
 2012:     ?errh(T(#{<<"archive_groupchats">> => <<"not really">>})),
 2013:     ?errh(T(#{<<"same_mam_id_for_peers">> => <<"not really">>})).
 2014: 
 2015: mod_mam_muc(_Config) ->
 2016:     T = fun(Opts) -> #{<<"modules">> => #{<<"mod_mam">> => #{<<"muc">> => Opts}}} end,
 2017:     P = [modules, mod_mam, muc],
 2018:     test_mod_mam(P, T),
 2019:     ?cfgh(P, default_config(P), T(#{})),
 2020:     ?cfgh(P ++ [host], {prefix, <<"muc.">>}, T(#{<<"host">> => <<"muc.@HOST@">>})),
 2021:     ?cfgh(P ++ [host], {fqdn, <<"muc.test">>}, T(#{<<"host">> => <<"muc.test">>})),
 2022:     ?errh(T(#{<<"host">> => <<"is this a host? no.">>})),
 2023:     ?errh(T(#{<<"host">> => [<<"invalid.sub@HOST@">>]})),
 2024:     ?errh(T(#{<<"host">> => [<<"invalid.sub.@HOST@.as.well">>]})),
 2025:     ?errh(T(#{<<"archive_groupchats">> => true})), % pm-only
 2026:     ?errh(T(#{<<"same_mam_id_for_peers">> => true})). % pm-only
 2027: 
 2028: test_mod_mam(P, T) ->
 2029:     test_async_writer(P, T),
 2030:     ?cfgh(P ++ [backend], rdbms,
 2031:           T(#{<<"backend">> => <<"rdbms">>})),
 2032:     ?cfgh(P ++ [no_stanzaid_element], true,
 2033:           T(#{<<"no_stanzaid_element">> => true})),
 2034:     ?cfgh(P ++ [is_archivable_message], mod_mam_utils,
 2035:           T(#{<<"is_archivable_message">> => <<"mod_mam_utils">>})),
 2036:     ?cfgh(P ++ [archive_chat_markers], true,
 2037:           T(#{<<"archive_chat_markers">> => true})),
 2038:     ?cfgh(P ++ [message_retraction], false,
 2039:           T(#{<<"message_retraction">> => false})),
 2040:     ?cfgh(P ++ [user_prefs_store], rdbms,
 2041:           T(#{<<"user_prefs_store">> => <<"rdbms">>})),
 2042:     ?cfgh(P ++ [full_text_search], false,
 2043:           T(#{<<"full_text_search">> => false})),
 2044:     ?cfgh(P ++ [cache_users], false,
 2045:           T(#{<<"cache_users">> => false})),
 2046:     ?cfgh(P ++ [default_result_limit], 100,
 2047:           T(#{<<"default_result_limit">> => 100})),
 2048:     ?cfgh(P ++ [max_result_limit], 1000,
 2049:           T(#{<<"max_result_limit">> => 1000})),
 2050:     ?cfgh(P ++ [db_jid_format], mam_jid_rfc,
 2051:           T(#{<<"db_jid_format">> => <<"mam_jid_rfc">>})),
 2052:     ?cfgh(P ++ [db_message_format], mam_message_xml,
 2053:           T(#{<<"db_message_format">> => <<"mam_message_xml">>})),
 2054:     ?cfgh(P ++ [extra_fin_element], mod_mam_utils,
 2055:           T(#{<<"extra_fin_element">> => <<"mod_mam_utils">>})),
 2056:     ?cfgh(P ++ [extra_lookup_params], mod_mam_utils,
 2057:           T(#{<<"extra_lookup_params">> => <<"mod_mam_utils">>})),
 2058:     ?errh(T(#{<<"backend">> => <<"notepad">>})),
 2059:     ?errh(T(#{<<"no_stanzaid_element">> => <<"true">>})),
 2060:     ?errh(T(#{<<"is_archivable_message">> => <<"mod_mam_fake">>})),
 2061:     ?errh(T(#{<<"archive_chat_markers">> => <<"maybe">>})),
 2062:     ?errh(T(#{<<"message_retraction">> => 1})),
 2063:     ?errh(T(#{<<"user_prefs_store">> => <<"textfile">>})),
 2064:     ?errh(T(#{<<"full_text_search">> => <<"disabled">>})),
 2065:     ?errh(T(#{<<"cache_users">> => []})),
 2066:     ?errh(T(#{<<"default_result_limit">> => -1})),
 2067:     ?errh(T(#{<<"max_result_limit">> => -2})),
 2068:     ?errh(T(#{<<"db_jid_format">> => <<"not_a_module">>})),
 2069:     ?errh(T(#{<<"db_message_format">> => <<"not_a_module">>})),
 2070:     ?errh(T(#{<<"extra_fin_element">> => <<"bad_module">>})),
 2071:     ?errh(T(#{<<"extra_lookup_params">> => <<"bad_module">>})).
 2072: 
 2073: test_cache_config(P, T) ->
 2074:     ?cfgh(P ++ [module], internal, T(#{<<"module">> => <<"internal">>})),
 2075:     ?cfgh(P ++ [time_to_live], 8600, T(#{<<"time_to_live">> => 8600})),
 2076:     ?cfgh(P ++ [time_to_live], infinity, T(#{<<"time_to_live">> => <<"infinity">>})),
 2077:     ?cfgh(P ++ [number_of_segments], 10, T(#{<<"number_of_segments">> => 10})),
 2078:     ?cfgh(P ++ [strategy], fifo, T(#{<<"strategy">> => <<"fifo">>})),
 2079:     ?errh(T(#{<<"module">> => <<"mod_wrong_cache">>})),
 2080:     ?errh(T(#{<<"time_to_live">> => 0})),
 2081:     ?errh(T(#{<<"strategy">> => <<"lifo">>})),
 2082:     ?errh(T(#{<<"number_of_segments">> => 0})),
 2083:     ?errh(T(#{<<"number_of_segments">> => <<"infinity">>})),
 2084:     ?errh(T(#{<<"cache">> => []})).
 2085: 
 2086: test_async_writer(ParentP, ParentT) ->
 2087:     P = ParentP ++ [async_writer],
 2088:     T = fun(Opts) -> ParentT(#{<<"async_writer">> => Opts}) end,
 2089:     ?cfgh(P ++ [flush_interval], 1500, T(#{<<"flush_interval">> => 1500})),
 2090:     ?cfgh(P ++ [batch_size], 1500, T(#{<<"batch_size">> => 1500})),
 2091:     ?cfgh(P ++ [pool_size], 1500, T(#{<<"pool_size">> => 1500})),
 2092:     ?cfgh(P ++ [enabled], false, T(#{<<"enabled">> => false})),
 2093:     ?errh(T(#{<<"flush_interval">> => -1})),
 2094:     ?errh(T(#{<<"batch_size">> => -1})),
 2095:     ?errh(T(#{<<"pool_size">> => -1})),
 2096:     ?errh(T(#{<<"enabled">> => <<"wrong">>})).
 2097: 
 2098: mod_muc(_Config) ->
 2099:     check_module_defaults(mod_muc),
 2100:     P = [modules, mod_muc],
 2101:     T = fun(K, V) -> #{<<"modules">> => #{<<"mod_muc">> => #{K => V}}} end,
 2102:     ?cfgh(P ++ [host], {prefix, <<"conference.">>},
 2103:           T(<<"host">>, <<"conference.@HOST@">>)),
 2104:     ?cfgh(P ++ [host], {fqdn, <<"conference.test">>},
 2105:           T(<<"host">>, <<"conference.test">>)),
 2106:     ?cfgh(P ++ [backend], mnesia, T(<<"backend">>, <<"mnesia">>)),
 2107:     ?cfgh(P ++ [access], all, T(<<"access">>, <<"all">>)),
 2108:     ?cfgh(P ++ [access_create], admin, T(<<"access_create">>, <<"admin">>)),
 2109:     ?cfgh(P ++ [access_admin], none, T(<<"access_admin">>, <<"none">>)),
 2110:     ?cfgh(P ++ [access_persistent], all, T(<<"access_persistent">>, <<"all">>)),
 2111:     ?cfgh(P ++ [history_size], 20, T(<<"history_size">>, 20)),
 2112:     ?cfgh(P ++ [room_shaper], muc_room_shaper,
 2113:           T(<<"room_shaper">>, <<"muc_room_shaper">>)),
 2114:     ?cfgh(P ++ [max_room_id], infinity, T(<<"max_room_id">>, <<"infinity">>)),
 2115:     ?cfgh(P ++ [max_room_name], 30, T(<<"max_room_name">>, 30)),
 2116:     ?cfgh(P ++ [max_room_desc], 0, T(<<"max_room_desc">>, 0)),
 2117:     ?cfgh(P ++ [min_message_interval], 10, T(<<"min_message_interval">>, 10)),
 2118:     ?cfgh(P ++ [min_presence_interval], 0, T(<<"min_presence_interval">>, 0)),
 2119:     ?cfgh(P ++ [max_users], 30, T(<<"max_users">>, 30)),
 2120:     ?cfgh(P ++ [max_users_admin_threshold], 2,
 2121:           T(<<"max_users_admin_threshold">>, 2)),
 2122:     ?cfgh(P ++ [user_message_shaper], muc_msg_shaper,
 2123:           T(<<"user_message_shaper">>, <<"muc_msg_shaper">>)),
 2124:     ?cfgh(P ++ [user_presence_shaper], muc_pres_shaper,
 2125:           T(<<"user_presence_shaper">>, <<"muc_pres_shaper">>)),
 2126:     ?cfgh(P ++ [max_user_conferences], 10, T(<<"max_user_conferences">>, 10)),
 2127:     ?cfgh(P ++ [http_auth_pool], external_auth,
 2128:           T(<<"http_auth_pool">>, <<"external_auth">>)),
 2129:     ?cfgh(P ++ [load_permanent_rooms_at_startup], true,
 2130:           T(<<"load_permanent_rooms_at_startup">>, true)),
 2131:     ?cfgh(P ++ [hibernate_timeout], infinity,
 2132:           T(<<"hibernate_timeout">>, <<"infinity">>)),
 2133:     ?cfgh(P ++ [hibernated_room_check_interval], 5000,
 2134:           T(<<"hibernated_room_check_interval">>, 5000)),
 2135:     ?cfgh(P ++ [hibernated_room_timeout], 0,
 2136:           T(<<"hibernated_room_timeout">>, 0)),
 2137:     ?errh(T(<<"host">>, <<>>)),
 2138:     ?errh(T(<<"host">>, <<"is this a host? no.">>)),
 2139:     ?errh(T(<<"host">>, [<<"invalid.sub@HOST@">>])),
 2140:     ?errh(T(<<"host">>, [<<"invalid.sub.@HOST@.as.well">>])),
 2141:     ?errh(T(<<"backend">>, <<"amnesia">>)),
 2142:     ?errh(T(<<"access">>, <<>>)),
 2143:     ?errh(T(<<"access_create">>, 1)),
 2144:     ?errh(T(<<"access_admin">>, [])),
 2145:     ?errh(T(<<"access_persistent">>, true)),
 2146:     ?errh(T(<<"history_size">>, <<"20">>)),
 2147:     ?errh(T(<<"room_shaper">>, <<>>)),
 2148:     ?errh(T(<<"max_room_id">>, #{})),
 2149:     ?errh(T(<<"max_room_name">>, <<"infinite!">>)),
 2150:     ?errh(T(<<"max_room_desc">>, -1)),
 2151:     ?errh(T(<<"min_message_interval">>, -10)),
 2152:     ?errh(T(<<"min_presence_interval">>, <<"infinity">>)),
 2153:     ?errh(T(<<"max_users">>, 0)),
 2154:     ?errh(T(<<"max_users_admin_threshold">>, 0)),
 2155:     ?errh(T(<<"user_message_shaper">>, [])),
 2156:     ?errh(T(<<"user_presence_shaper">>, <<>>)),
 2157:     ?errh(T(<<"max_user_conferences">>, -1)),
 2158:     ?errh(T(<<"http_auth_pool">>, <<>>)),
 2159:     ?errh(T(<<"load_permanent_rooms_at_startup">>, <<"true">>)),
 2160:     ?errh(T(<<"hibernate_timeout">>, <<"really big">>)),
 2161:     ?errh(T(<<"hibernated_room_check_interval">>, -1)),
 2162:     ?errh(T(<<"hibernated_room_timeout">>, false)).
 2163: 
 2164: mod_muc_default_room(_Config) ->
 2165:     P = [modules, mod_muc, default_room],
 2166:     T = fun(K, V) ->
 2167:                 M = #{<<"mod_muc">> => #{<<"default_room">> => #{K => V}}},
 2168:                 #{<<"modules">> => M}
 2169:         end,
 2170:     ?cfgh(P ++ [title], <<"living room">>, T(<<"title">>, <<"living room">>)),
 2171:     ?cfgh(P ++ [description], <<"a room that is alive">>,
 2172:           T(<<"description">>, <<"a room that is alive">>)),
 2173:     ?cfgh(P ++ [allow_change_subj], true, T(<<"allow_change_subj">>, true)),
 2174:     ?cfgh(P ++ [allow_query_users], false, T(<<"allow_query_users">>, false)),
 2175:     ?cfgh(P ++ [allow_private_messages], true,
 2176:           T(<<"allow_private_messages">>, true)),
 2177:     ?cfgh(P ++ [allow_visitor_status], false,
 2178:           T(<<"allow_visitor_status">>, false)),
 2179:     ?cfgh(P ++ [allow_visitor_nickchange], true,
 2180:           T(<<"allow_visitor_nickchange">>, true)),
 2181:     ?cfgh(P ++ [public], false, T(<<"public">>, false)),
 2182:     ?cfgh(P ++ [public_list], true, T(<<"public_list">>, true)),
 2183:     ?cfgh(P ++ [persistent], true, T(<<"persistent">>, true)),
 2184:     ?cfgh(P ++ [moderated], false, T(<<"moderated">>, false)),
 2185:     ?cfgh(P ++ [members_by_default], true, T(<<"members_by_default">>, true)),
 2186:     ?cfgh(P ++ [members_only], false, T(<<"members_only">>, false)),
 2187:     ?cfgh(P ++ [allow_user_invites], true, T(<<"allow_user_invites">>, true)),
 2188:     ?cfgh(P ++ [allow_multiple_sessions], false,
 2189:           T(<<"allow_multiple_sessions">>, false)),
 2190:     ?cfgh(P ++ [password_protected], true, T(<<"password_protected">>, true)),
 2191:     ?cfgh(P ++ [password], <<"secret">>, T(<<"password">>, <<"secret">>)),
 2192:     ?cfgh(P ++ [anonymous], true, T(<<"anonymous">>, true)),
 2193:     ?cfgh(P ++ [max_users],  100, T(<<"max_users">>, 100)),
 2194:     ?cfgh(P ++ [logging], false, T(<<"logging">>, false)),
 2195:     ?cfgh(P ++ [maygetmemberlist], [moderator],
 2196:           T(<<"maygetmemberlist">>, [<<"moderator">>])),
 2197:     ?cfgh(P ++ [subject], <<"Lambda days">>, T(<<"subject">>, <<"Lambda days">>)),
 2198:     ?cfgh(P ++ [subject_author], <<"Alice">>, T(<<"subject_author">>, <<"Alice">>)),
 2199:     ?errh(T(<<"title">>, true)),
 2200:     ?errh(T(<<"description">>, 1)),
 2201:     ?errh(T(<<"allow_change_subj">>, <<"true">>)),
 2202:     ?errh(T(<<"allow_query_users">>, <<>>)),
 2203:     ?errh(T(<<"allow_private_messages">>, 1)),
 2204:     ?errh(T(<<"allow_visitor_status">>, [])),
 2205:     ?errh(T(<<"allow_visitor_nickchange">>, #{})),
 2206:     ?errh(T(<<"public">>, 0)),
 2207:     ?errh(T(<<"public_list">>, [false])),
 2208:     ?errh(T(<<"persistent">>, 1)),
 2209:     ?errh(T(<<"moderated">>, <<"yes">>)),
 2210:     ?errh(T(<<"members_by_default">>, 0)),
 2211:     ?errh(T(<<"members_only">>, [true])),
 2212:     ?errh(T(<<"allow_user_invites">>, <<>>)),
 2213:     ?errh(T(<<"allow_multiple_sessions">>, [])),
 2214:     ?errh(T(<<"password_protected">>, #{})),
 2215:     ?errh(T(<<"password">>, false)),
 2216:     ?errh(T(<<"anonymous">>, <<"maybe">>)),
 2217:     ?errh(T(<<"max_users">>, 0)),
 2218:     ?errh(T(<<"logging">>, [true, false])),
 2219:     ?errh(T(<<"maygetmemberlist">>, <<"moderator">>)),
 2220:     ?errh(T(<<"maygetmemberlist">>, [<<>>])),
 2221:     ?errh(T(<<"subject">>, [<<"subjective">>])),
 2222:     ?errh(T(<<"subject_author">>, 1)).
 2223: 
 2224: mod_muc_default_room_affiliations(_Config) ->
 2225:     P = [modules, mod_muc, default_room, affiliations],
 2226:     T = fun(V) ->
 2227:                 M = #{<<"mod_muc">> => #{<<"default_room">> => #{<<"affiliations">> => V}}},
 2228:                 #{<<"modules">> => M}
 2229:         end,
 2230:     RequiredOpts = #{<<"user">> => <<"alice">>,
 2231:                      <<"server">> => <<"localhost">>,
 2232:                      <<"resource">> => <<"phone">>,
 2233:                      <<"affiliation">> => <<"moderator">>},
 2234:     ExpectedCfg = {{<<"alice">>, <<"localhost">>, <<"phone">>}, moderator},
 2235:     ?cfgh(P, [], T([])),
 2236:     ?cfgh(P, [ExpectedCfg], T([RequiredOpts])),
 2237:     [?errh(T([maps:remove(Key, RequiredOpts)])) || Key <- maps:keys(RequiredOpts)],
 2238:     ?errh(T([RequiredOpts#{<<"user">> := <<>>}])),
 2239:     ?errh(T([RequiredOpts#{<<"server">> := <<"domain? not really!">>}])),
 2240:     ?errh(T([RequiredOpts#{<<"resource">> := false}])),
 2241:     ?errh(T([RequiredOpts#{<<"affiliation">> := <<>>}])).
 2242: 
 2243: mod_muc_log(_Config) ->
 2244:     check_module_defaults(mod_muc_log),
 2245:     P = [modules, mod_muc_log],
 2246:     T = fun(K, V) -> #{<<"modules">> => #{<<"mod_muc_log">> => #{K => V}}} end,
 2247:     ?cfgh(P ++ [outdir], "www/muc", T(<<"outdir">>, <<"www/muc">>)),
 2248:     ?cfgh(P ++ [access_log], muc_admin, T(<<"access_log">>, <<"muc_admin">>)),
 2249:     ?cfgh(P ++ [dirtype], subdirs, T(<<"dirtype">>, <<"subdirs">>)),
 2250:     ?cfgh(P ++ [dirname], room_name, T(<<"dirname">>, <<"room_name">>)),
 2251:     ?cfgh(P ++ [file_format], html, T(<<"file_format">>, <<"html">>)),
 2252:     ?cfgh(P ++ [css_file], <<"path/to/css_file">>,
 2253:           T(<<"css_file">>, <<"path/to/css_file">>)),
 2254:     ?cfgh(P ++ [timezone], local, T(<<"timezone">>, <<"local">>)),
 2255:     ?cfgh(P ++ [spam_prevention], false, T(<<"spam_prevention">>, false)),
 2256:     ?errh(T(<<"outdir">>, <<"does/not/exist">>)),
 2257:     ?errh(T(<<"access_log">>, 1)),
 2258:     ?errh(T(<<"dirtype">>, <<"imaginary">>)),
 2259:     ?errh(T(<<"dirname">>, <<"dyrektory">>)),
 2260:     ?errh(T(<<"file_format">>, <<"none">>)),
 2261:     ?errh(T(<<"css_file">>, <<>>)),
 2262:     ?errh(T(<<"timezone">>, <<"yes">>)),
 2263:     ?errh(T(<<"spam_prevention">>, <<"spam and eggs and spam">>)).
 2264: 
 2265: mod_muc_log_top_link(_Config) ->
 2266:     P = [modules, mod_muc_log, top_link],
 2267:     T = fun(V) ->
 2268:                 M = #{<<"mod_muc_log">> => #{<<"top_link">> => V}},
 2269:                 #{<<"modules">> => M}
 2270:         end,
 2271:     RequiredOpts = #{<<"target">> => <<"https://esl.github.io/MongooseDocs/">>,
 2272:                      <<"text">> => <<"Docs">>},
 2273:     ExpectedCfg = {"https://esl.github.io/MongooseDocs/", "Docs"},
 2274:     ?cfgh(P, ExpectedCfg, T(RequiredOpts)),
 2275:     [?errh(T(maps:remove(K, RequiredOpts))) || K <- maps:keys(RequiredOpts)],
 2276:     ?errh(T(RequiredOpts#{<<"target">> => true})),
 2277:     ?errh(T(RequiredOpts#{<<"text">> => <<"">>})).
 2278: 
 2279: mod_muc_light(_Config) ->
 2280:     check_module_defaults(mod_muc_light),
 2281:     T = fun(Opts) -> #{<<"modules">> => #{<<"mod_muc_light">> => Opts}} end,
 2282:     P = [modules, mod_muc_light],
 2283:     test_cache_config(P ++ [cache_affs], fun(Opts) -> T(#{<<"cache_affs">> => Opts}) end),
 2284:     ?cfgh(P ++ [backend], mnesia,
 2285:           T(#{<<"backend">> => <<"mnesia">>})),
 2286:     ?cfgh(P ++ [host], {prefix, <<"muclight.">>},
 2287:           T(#{<<"host">> => <<"muclight.@HOST@">>})),
 2288:     ?cfgh(P ++ [host], {fqdn, <<"muclight.test">>},
 2289:           T(#{<<"host">> => <<"muclight.test">>})),
 2290:     ?cfgh(P ++ [equal_occupants], true,
 2291:           T(#{<<"equal_occupants">> => true})),
 2292:     ?cfgh(P ++ [legacy_mode], false,
 2293:           T(#{<<"legacy_mode">> => false})),
 2294:     ?cfgh(P ++ [rooms_per_user], 100,
 2295:           T(#{<<"rooms_per_user">> => 100})),
 2296:     ?cfgh(P ++ [blocking], false,
 2297:           T(#{<<"blocking">> => false})),
 2298:     ?cfgh(P ++ [all_can_configure], true,
 2299:           T(#{<<"all_can_configure">> => true})),
 2300:     ?cfgh(P ++ [all_can_invite], false,
 2301:           T(#{<<"all_can_invite">> => false})),
 2302:     ?cfgh(P ++ [max_occupants], infinity,
 2303:           T(#{<<"max_occupants">> => <<"infinity">>})),
 2304:     ?cfgh(P ++ [rooms_per_page], 10,
 2305:           T(#{<<"rooms_per_page">> => 10})),
 2306:     ?cfgh(P ++ [rooms_in_rosters], true,
 2307:           T(#{<<"rooms_in_rosters">> => true})),
 2308:     ?errh(T(#{<<"backend">> => <<"frontend">>})),
 2309:     ?errh(T(#{<<"host">> => <<"what is a domain?!">>})),
 2310:     ?errh(T(#{<<"host">> => [<<"invalid.sub@HOST@">>]})),
 2311:     ?errh(T(#{<<"host">> => [<<"invalid.sub.@HOST@.as.well">>]})),
 2312:     ?errh(T(#{<<"equal_occupants">> => <<"true">>})),
 2313:     ?errh(T(#{<<"legacy_mode">> => 1234})),
 2314:     ?errh(T(#{<<"rooms_per_user">> => 0})),
 2315:     ?errh(T(#{<<"blocking">> => <<"true">>})),
 2316:     ?errh(T(#{<<"all_can_configure">> => []})),
 2317:     ?errh(T(#{<<"all_can_invite">> => #{}})),
 2318:     ?errh(T(#{<<"max_occupants">> => <<"seven">>})),
 2319:     ?errh(T(#{<<"rooms_per_page">> => false})),
 2320:     ?errh(T(#{<<"rooms_in_rosters">> => [1, 2, 3]})).
 2321: 
 2322: mod_muc_light_config_schema(_Config) ->
 2323:     T = fun(Opts) -> #{<<"modules">> =>
 2324:                            #{<<"mod_muc_light">> => #{<<"config_schema">> => Opts}}} end,
 2325:     P = [modules, mod_muc_light, config_schema],
 2326:     Field = #{<<"field">> => <<"my_field">>},
 2327:     ?cfgh(P, [], T([])),
 2328:     ?cfgh(P, [{<<"my_field">>, <<"My Room">>, my_field, binary}],
 2329:           T([Field#{<<"string_value">> => <<"My Room">>}])),
 2330:     ?cfgh(P, [{<<"my_field">>, 1, my_field, integer}],
 2331:           T([Field#{<<"integer_value">> => 1}])),
 2332:     ?cfgh(P, [{<<"my_field">>, 0.5, my_field, float}],
 2333:           T([Field#{<<"float_value">> => 0.5}])),
 2334:     ?cfgh(P, [{<<"my_field">>, 0, your_field, integer}],
 2335:           T([Field#{<<"integer_value">> => 0,
 2336:                     <<"internal_key">> => <<"your_field">>}])),
 2337:     ?cfgh(P, [{<<"żółć"/utf8>>, <<"Рентгеноэлектрокардиографический"/utf8>>, 'żółć', binary}],
 2338:           T([#{<<"field">> => <<"żółć"/utf8>>,
 2339:                <<"string_value">> => <<"Рентгеноэлектрокардиографический"/utf8>>}])),
 2340:     ?cfgh(P, [{<<"first">>, 1, first, integer}, % the config is u-key-sorted
 2341:               {<<"second">>, <<"two">>, second, binary}],
 2342:           T([#{<<"field">> => <<"second">>, <<"string_value">> => <<"two">>},
 2343:              #{<<"field">> => <<"second">>, <<"float_value">> => 2.0},
 2344:              #{<<"field">> => <<"first">>, <<"integer_value">> => 1}])),
 2345:     ?errh(T([#{<<"string_value">> => <<"My Room">>}])),
 2346:     ?errh(T([#{<<"field">> => <<>>,
 2347:                <<"string_value">> => <<"My Room">>}])),
 2348:     ?errh(T([Field#{<<"string_value">> => 0}])),
 2349:     ?errh(T([Field#{<<"integer_value">> => 1.5}])),
 2350:     ?errh(T([Field#{<<"float_value">> => 1}])),
 2351:     ?errh(T([Field#{<<"integer_value">> => 0,
 2352:                     <<"string_value">> => <<"My Room">>}])),
 2353:     ?errh(T([Field#{<<"integer_value">> => 0,
 2354:                     <<"internal_key">> => <<>>}])).
 2355: 
 2356: mod_offline(_Config) ->
 2357:     check_module_defaults(mod_offline),
 2358:     T = fun(Opts) -> #{<<"modules">> => #{<<"mod_offline">> => Opts}} end,
 2359:     P = [modules, mod_offline],
 2360:     ?cfgh(P ++ [access_max_user_messages], custom_max_user_offline_messages,
 2361:           T(#{<<"access_max_user_messages">> => <<"custom_max_user_offline_messages">>})),
 2362:     ?cfgh(P ++ [backend], rdbms,
 2363:           T(#{<<"backend">> => <<"rdbms">>})),
 2364:     ?cfgh(P ++ [riak, bucket_type], <<"test">>,
 2365:           T(#{<<"backend">> => <<"riak">>, <<"riak">> => #{<<"bucket_type">> => <<"test">>}})),
 2366:     ?errh(T(#{<<"access_max_user_messages">> => 1})),
 2367:     ?errh(T(#{<<"backend">> => <<"riak_is_the_best">>})),
 2368:     ?errh(T(#{<<"riak">> => #{<<"bucket_type">> => 1}})),
 2369:     ?errh(T(#{<<"riak">> => #{<<"bucket">> => <<"leaky">>}})).
 2370: 
 2371: mod_offline_chatmarkers(_Config) ->
 2372:     check_module_defaults(mod_offline_chatmarkers),
 2373:     T = fun(Opts) -> #{<<"modules">> => #{<<"mod_offline_chatmarkers">> => Opts}} end,
 2374:     P = [modules, mod_offline_chatmarkers],
 2375:     ?cfgh(P ++ [backend], rdbms,
 2376:           T(#{<<"backend">> => <<"rdbms">>})),
 2377:     ?cfgh(P ++ [store_groupchat_messages], true,
 2378:           T(#{<<"store_groupchat_messages">> => true})),
 2379:     ?errh(T(#{<<"store_groupchat_messages">> => 1})),
 2380:     ?errh(T(#{<<"backend">> => <<"riak_is_the_best">>})).
 2381: 
 2382: mod_ping(_Config) ->
 2383:     T = fun(Opts) -> #{<<"modules">> => #{<<"mod_ping">> => Opts}} end,
 2384:     P = [modules, mod_ping],
 2385:     check_iqdisc(mod_ping),
 2386:     check_module_defaults(mod_ping),
 2387:     ?cfgh(P ++ [send_pings], true,
 2388:           T(#{<<"send_pings">> => true})),
 2389:     ?cfgh(P ++ [ping_interval], timer:seconds(10),
 2390:           T(#{<<"ping_interval">> => 10})),
 2391:     ?cfgh(P ++ [timeout_action], kill,
 2392:           T(#{<<"timeout_action">> => <<"kill">>})),
 2393:     ?cfgh(P ++ [ping_req_timeout], timer:seconds(20),
 2394:           T(#{<<"ping_req_timeout">> => 20})),
 2395:     ?errh(T(#{<<"send_pings">> => 1})),
 2396:     ?errh(T(#{<<"ping_interval">> => 0})),
 2397:     ?errh(T(#{<<"timeout_action">> => <<"kill_them_all">>})),
 2398:     ?errh(T(#{<<"ping_req_timeout">> => 0})).
 2399: 
 2400: mod_privacy(_Config) ->
 2401:     test_privacy_opts(mod_privacy).
 2402: 
 2403: test_privacy_opts(Module) ->
 2404:     T = fun(Opts) -> #{<<"modules">> => #{atom_to_binary(Module) => Opts}} end,
 2405:     P = [modules, Module],
 2406:     check_module_defaults(Module),
 2407:     ?cfgh(P ++ [backend], mnesia,
 2408:           T(#{<<"backend">> => <<"mnesia">>})),
 2409:     ?cfgh(P ++ [riak, defaults_bucket_type], <<"defaults">>,
 2410:           T(#{<<"backend">> => <<"riak">>,
 2411:               <<"riak">> => #{<<"defaults_bucket_type">> => <<"defaults">>}})),
 2412:     ?cfgh(P ++ [riak, names_bucket_type], <<"names">>,
 2413:           T(#{<<"backend">> => <<"riak">>,
 2414:               <<"riak">> => #{<<"names_bucket_type">> => <<"names">>}})),
 2415:     ?cfgh(P ++ [riak, bucket_type], <<"bucket">>,
 2416:           T(#{<<"backend">> => <<"riak">>,
 2417:               <<"riak">> => #{<<"bucket_type">> => <<"bucket">>}})),
 2418:     ?cfgh(P ++ [riak],
 2419:           default_config([modules, mod_privacy, riak]),
 2420:           T(#{<<"backend">> => <<"riak">>})),
 2421:     ?errh(T(#{<<"backend">> => <<"mongoddt">>})),
 2422:     ?errh(T(#{<<"riak">> => #{<<"defaults_bucket_type">> => <<>>}})),
 2423:     ?errh(T(#{<<"riak">> => #{<<"names_bucket_type">> => 1}})),
 2424:     ?errh(T(#{<<"riak">> => #{<<"bucket_type">> => 1}})).
 2425: 
 2426: mod_private(_Config) ->
 2427:     check_iqdisc(mod_private),
 2428:     check_module_defaults(mod_private),
 2429:     T = fun(Opts) -> #{<<"modules">> => #{<<"mod_private">> => Opts}} end,
 2430:     P = [modules, mod_private],
 2431:     ?cfgh(P ++ [backend], riak, T(#{<<"backend">> => <<"riak">>})),
 2432:     ?cfgh(P ++ [riak, bucket_type], <<"private">>, T(#{<<"backend">> => <<"riak">>})),
 2433:     ?cfgh(P ++ [riak, bucket_type], <<"private_stuff">>, T(#{<<"backend">> => <<"riak">>,
 2434:         <<"riak">> => #{<<"bucket_type">> => <<"private_stuff">>}})),
 2435:     ?errh(T(#{<<"backend">> => <<"mssql">>})),
 2436:     ?errh(T(#{<<"riak">> => #{<<"bucket_type">> => 1}})).
 2437: 
 2438: mod_pubsub(_Config) ->
 2439:     check_iqdisc(mod_pubsub),
 2440:     check_module_defaults(mod_pubsub),
 2441:     T = fun(Opts) -> #{<<"modules">> => #{<<"mod_pubsub">> => Opts}} end,
 2442:     P = [modules, mod_pubsub],
 2443:     ?cfgh(P ++ [host], {prefix, <<"pubsub.">>},
 2444:           T(#{<<"host">> => <<"pubsub.@HOST@">>})),
 2445:     ?cfgh(P ++ [host], {fqdn, <<"pubsub.test">>},
 2446:           T(#{<<"host">> => <<"pubsub.test">>})),
 2447:     ?cfgh(P ++ [backend], rdbms,
 2448:           T(#{<<"backend">> => <<"rdbms">>})),
 2449:     ?cfgh(P ++ [access_createnode], all,
 2450:           T(#{<<"access_createnode">> => <<"all">>})),
 2451:     ?cfgh(P ++ [max_items_node], 20,
 2452:           T(#{<<"max_items_node">> => 20})),
 2453:     ?cfgh(P ++ [max_subscriptions_node], 30,
 2454:           T(#{<<"max_subscriptions_node">> => 30})),
 2455:     ?cfgh(P ++ [nodetree], nodetree_tree,
 2456:           T(#{<<"nodetree">> => <<"tree">>})),
 2457:     ?cfgh(P ++ [ignore_pep_from_offline], false,
 2458:           T(#{<<"ignore_pep_from_offline">> => false})),
 2459:     ?cfgh(P ++ [last_item_cache], rdbms,
 2460:           T(#{<<"last_item_cache">> => <<"rdbms">>})),
 2461:     ?cfgh(P ++ [plugins], [<<"flat">>, <<"dag">>],
 2462:           T(#{<<"plugins">> => [<<"flat">>, <<"dag">>]})),
 2463:     ?cfgh(P ++ [item_publisher], true,
 2464:           T(#{<<"item_publisher">> => true})),
 2465:     ?cfgh(P ++ [sync_broadcast], false,
 2466:           T(#{<<"sync_broadcast">> => false})),
 2467:     ?errh(T(#{<<"host">> => <<"">>})),
 2468:     ?errh(T(#{<<"host">> => <<"is this a host? no.">>})),
 2469:     ?errh(T(#{<<"host">> => [<<"invalid.sub@HOST@">>]})),
 2470:     ?errh(T(#{<<"host">> => [<<"invalid.sub.@HOST@.as.well">>]})),
 2471:     ?errh(T(#{<<"backend">> => <<"amnesia">>})),
 2472:     ?errh(T(#{<<"access_createnode">> => <<"">>})),
 2473:     ?errh(T(#{<<"max_items_node">> => -1})),
 2474:     ?errh(T(#{<<"max_subscriptions_node">> => 3.1415})),
 2475:     ?errh(T(#{<<"nodetree">> => <<"christmas_tree">>})),
 2476:     ?errh(T(#{<<"ignore_pep_from_offline">> => <<"maybe">>})),
 2477:     ?errh(T(#{<<"last_item_cache">> => false})),
 2478:     ?errh(T(#{<<"plugins">> => [<<"deep">>]})),
 2479:     ?errh(T(#{<<"item_publisher">> => 1})),
 2480:     ?errh(T(#{<<"sync_broadcast">> => []})).
 2481: 
 2482: mod_pubsub_pep_mapping(_Config) ->
 2483:     T = fun(Opts) -> #{<<"modules">> => #{<<"mod_pubsub">> =>
 2484:                                               #{<<"pep_mapping">> => Opts}}} end,
 2485:     P = [modules, mod_pubsub, pep_mapping],
 2486:     RequiredOpts = #{<<"namespace">> => <<"urn:xmpp:microblog:0">>,
 2487:                      <<"node">> => <<"mb">>},
 2488:     ?cfgh(P ++ [<<"urn:xmpp:microblog:0">>], <<"mb">>,
 2489:           T([RequiredOpts])),
 2490:     [?errh(T([maps:remove(Key, RequiredOpts)])) || Key <- maps:keys(RequiredOpts)],
 2491:     [?errh(T([RequiredOpts#{Key => <<>>}])) || Key <- maps:keys(RequiredOpts)].
 2492: 
 2493: mod_pubsub_default_node_config(_Config) ->
 2494:     T = fun(Opts) -> #{<<"modules">> => #{<<"mod_pubsub">> =>
 2495:                                               #{<<"default_node_config">> => Opts}}} end,
 2496:     P = [modules, mod_pubsub, default_node_config],
 2497:     ?cfgh(P, [{access_model, open}],
 2498:           T(#{<<"access_model">> => <<"open">>})),
 2499:     ?cfgh(P, [{deliver_notifications, true}],
 2500:           T(#{<<"deliver_notifications">> => true})),
 2501:     ?cfgh(P, [{deliver_payloads, false}],
 2502:           T(#{<<"deliver_payloads">> => false})),
 2503:     ?cfgh(P, [{max_items, 1000}],
 2504:           T(#{<<"max_items">> => 1000})),
 2505:     ?cfgh(P, [{max_payload_size, 1000}],
 2506:           T(#{<<"max_payload_size">> => 1000})),
 2507:     ?cfgh(P, [{node_type, dag}],
 2508:           T(#{<<"node_type">> => <<"dag">>})),
 2509:     ?cfgh(P, [{notification_type, headline}],
 2510:           T(#{<<"notification_type">> => <<"headline">>})),
 2511:     ?cfgh(P, [{notify_config, true}],
 2512:           T(#{<<"notify_config">> => true})),
 2513:     ?cfgh(P, [{notify_delete, false}],
 2514:           T(#{<<"notify_delete">> => false})),
 2515:     ?cfgh(P, [{notify_retract, true}],
 2516:           T(#{<<"notify_retract">> => true})),
 2517:     ?cfgh(P, [{persist_items, false}],
 2518:           T(#{<<"persist_items">> => false})),
 2519:     ?cfgh(P, [{presence_based_delivery, true}],
 2520:           T(#{<<"presence_based_delivery">> => true})),
 2521:     ?cfgh(P, [{publish_model, open}],
 2522:           T(#{<<"publish_model">> => <<"open">>})),
 2523:     ?cfgh(P, [{purge_offline, false}],
 2524:           T(#{<<"purge_offline">> => false})),
 2525:     ?cfgh(P, [{roster_groups_allowed, [<<"friends">>]}],
 2526:           T(#{<<"roster_groups_allowed">> => [<<"friends">>]})),
 2527:     ?cfgh(P, [{send_last_published_item, on_sub_and_presence}],
 2528:           T(#{<<"send_last_published_item">> => <<"on_sub_and_presence">>})),
 2529:     ?cfgh(P, [{subscribe, true}],
 2530:           T(#{<<"subscribe">> => true})),
 2531:     ?errh(T(#{<<"access_model">> => <<>>})),
 2532:     ?errh(T(#{<<"deliver_notifications">> => <<"yes">>})),
 2533:     ?errh(T(#{<<"deliver_payloads">> => 0})),
 2534:     ?errh(T(#{<<"max_items">> => -1})),
 2535:     ?errh(T(#{<<"max_payload_size">> => -1})),
 2536:     ?errh(T(#{<<"node_type">> => [<<"dag">>]})),
 2537:     ?errh(T(#{<<"notification_type">> => <<>>})),
 2538:     ?errh(T(#{<<"notify_config">> => <<"false">>})),
 2539:     ?errh(T(#{<<"notify_delete">> => [true]})),
 2540:     ?errh(T(#{<<"notify_retract">> => #{}})),
 2541:     ?errh(T(#{<<"persist_items">> => 1})),
 2542:     ?errh(T(#{<<"presence_based_delivery">> => []})),
 2543:     ?errh(T(#{<<"publish_model">> => <<"">>})),
 2544:     ?errh(T(#{<<"purge_offline">> => 1})),
 2545:     ?errh(T(#{<<"roster_groups_allowed">> => [<<>>]})),
 2546:     ?errh(T(#{<<"send_last_published_item">> => <<>>})),
 2547:     ?errh(T(#{<<"subscribe">> => <<"never">>})).
 2548: 
 2549: mod_push_service_mongoosepush(_Config) ->
 2550:     check_module_defaults(mod_push_service_mongoosepush),
 2551:     P = [modules, mod_push_service_mongoosepush],
 2552:     T = fun(Opts) -> #{<<"modules">> => #{<<"mod_push_service_mongoosepush">> => Opts}} end,
 2553:     ?cfgh(P ++ [pool_name], test_pool,
 2554:           T(#{<<"pool_name">> => <<"test_pool">>})),
 2555:     ?cfgh(P ++ [api_version], <<"v2">>,
 2556:           T(#{<<"api_version">> => <<"v2">>})),
 2557:     ?cfgh(P ++ [max_http_connections], 999,
 2558:           T(#{<<"max_http_connections">> => 999})),
 2559:     ?errh(T(#{<<"pool_name">> => 1})),
 2560:     ?errh(T(#{<<"api_version">> => <<"v4">>})),
 2561:     ?errh(T(#{<<"max_http_connections">> => -1})).
 2562: 
 2563: mod_register(_Config) ->
 2564:     check_module_defaults(mod_register),
 2565:     check_iqdisc(mod_register),
 2566:     P = [modules, mod_register],
 2567:     ?cfgh(P ++ [access], register,
 2568:           ip_access_register(<<"127.0.0.1">>)),
 2569:     ?cfgh(P ++ [ip_access], [{allow, "127.0.0.0/8"},
 2570:                              {deny, "0.0.0.0"}],
 2571:           ip_access_register(<<"0.0.0.0">>)),
 2572:     ?cfgh(P ++ [ip_access], [{allow, "127.0.0.0/8"},
 2573:                              {deny, "0.0.0.4"}],
 2574:           ip_access_register(<<"0.0.0.4">>)),
 2575:     ?cfgh(P ++ [ip_access], [{allow, "127.0.0.0/8"},
 2576:                              {deny, "::1"}],
 2577:           ip_access_register(<<"::1">>)),
 2578:     ?cfgh(P ++ [ip_access], [{allow, "127.0.0.0/8"},
 2579:                              {deny, "::1/128"}],
 2580:           ip_access_register(<<"::1/128">>)),
 2581:     ?errh(invalid_ip_access_register()),
 2582:     ?errh(invalid_ip_access_register_ipv6()),
 2583:     ?errh(ip_access_register(<<"hello">>)),
 2584:     ?errh(ip_access_register(<<"0.d">>)),
 2585:     ?cfgh(P ++ [welcome_message], {"Subject", "Body"},
 2586:           welcome_message()),
 2587:     %% List of jids
 2588:     ?cfgh(P ++ [registration_watchers], [<<"alice@bob">>, <<"ilovemongoose@help">>],
 2589:           registration_watchers([<<"alice@bob">>, <<"ilovemongoose@help">>])),
 2590:     ?errh(registration_watchers([<<"alice@bob">>, <<"jids@have@no@feelings!">>])),
 2591:     %% non-negative integer
 2592:     ?cfgh(P ++ [password_strength], 42,
 2593:           password_strength_register(42)),
 2594:     ?errh(password_strength_register(<<"42">>)),
 2595:     ?errh(password_strength_register(<<"strong">>)),
 2596:     ?errh(password_strength_register(-150)),
 2597:     ?errh(welcome_message(<<"Subject">>, 1)),
 2598:     ?errh(welcome_message(1, <<"Body">>)).
 2599: 
 2600: welcome_message() ->
 2601:     welcome_message(<<"Subject">>, <<"Body">>).
 2602: 
 2603: welcome_message(S, B) ->
 2604:     Opts = #{<<"welcome_message">> => #{<<"subject">> => S, <<"body">> => B}},
 2605:     #{<<"modules">> => #{<<"mod_register">> => Opts}}.
 2606: 
 2607: password_strength_register(Strength) ->
 2608:     Opts = #{<<"password_strength">> => Strength},
 2609:     #{<<"modules">> => #{<<"mod_register">> => Opts}}.
 2610: 
 2611: ip_access_register(Ip) ->
 2612:     Opts = #{<<"access">> => <<"register">>,
 2613:              <<"ip_access">> =>
 2614:                  [#{<<"address">> => <<"127.0.0.0/8">>, <<"policy">> => <<"allow">>},
 2615:                   #{<<"address">> => Ip, <<"policy">> => <<"deny">>}]},
 2616:     #{<<"modules">> => #{<<"mod_register">> => Opts}}.
 2617: 
 2618: invalid_ip_access_register() ->
 2619:     Opts = #{<<"access">> => <<"register">>,
 2620:              <<"ip_access">> =>
 2621:                  [#{<<"address">> => <<"127.0.0.0/8">>, <<"policy">> => <<"allawww">>},
 2622:                   #{<<"address">> => <<"8.8.8.8">>, <<"policy">> => <<"denyh">>}]},
 2623:     #{<<"modules">> => #{<<"mod_register">> => Opts}}.
 2624: 
 2625: invalid_ip_access_register_ipv6() ->
 2626:     Opts = #{<<"access">> => <<"register">>,
 2627:              <<"ip_access">> =>
 2628:                  [#{<<"address">> => <<"::1/129">>, <<"policy">> => <<"allow">>}]},
 2629:     #{<<"modules">> => #{<<"mod_register">> => Opts}}.
 2630: 
 2631: registration_watchers(JidBins) ->
 2632:     Opts = #{<<"registration_watchers">> => JidBins},
 2633:     #{<<"modules">> => #{<<"mod_register">> => Opts}}.
 2634: 
 2635: mod_roster(_Config) ->
 2636:     check_iqdisc(mod_roster),
 2637:     check_module_defaults(mod_roster),
 2638:     P = [modules, mod_roster],
 2639:     T = fun(Opts) -> #{<<"modules">> => #{<<"mod_roster">> => Opts}} end,
 2640:     ?cfgh(P ++ [versioning],  true,
 2641:           T(#{<<"versioning">> => true})),
 2642:     ?cfgh(P ++ [store_current_id], true,
 2643:           T(#{<<"store_current_id">> => true})),
 2644:     ?cfgh(P ++ [backend], rdbms,
 2645:           T(#{<<"backend">> => <<"rdbms">>})),
 2646:     ?cfgh(P ++ [riak], config_parser_helper:default_config(P ++ [riak]),
 2647:           T(#{<<"backend">> => <<"riak">>})),
 2648:     ?cfgh(P ++ [riak, bucket_type], <<"my_type">>,
 2649:           T(#{<<"backend">> => <<"riak">>, <<"riak">> => #{<<"bucket_type">> => <<"my_type">>}})),
 2650:     ?cfgh(P ++ [riak, version_bucket_type], <<"my_versions">>,
 2651:           T(#{<<"backend">> => <<"riak">>, <<"riak">> => #{<<"version_bucket_type">> => <<"my_versions">>}})),
 2652: 
 2653:     ?errh(T(#{<<"versioning">> => 1})),
 2654:     ?errh(T(#{<<"store_current_id">> => 1})),
 2655:     ?errh(T(#{<<"backend">> => 1})),
 2656:     ?errh(T(#{<<"backend">> => <<"iloveyou">>})),
 2657:     ?errh(T(#{<<"riak">> => #{<<"version_bucket_type">> => 1}})),
 2658:     ?errh(T(#{<<"riak">> => #{<<"bucket_type">> => 1}})).
 2659: 
 2660: mod_shared_roster_ldap(_Config) ->
 2661:     check_module_defaults(mod_shared_roster_ldap),
 2662:     P = [modules, mod_shared_roster_ldap],
 2663:     T = fun(Opts) -> #{<<"modules">> => #{<<"mod_shared_roster_ldap">> => Opts}} end,
 2664:     ?cfgh(P ++ [pool_tag], my_tag,
 2665:           T(#{<<"pool_tag">> => <<"my_tag">>})),
 2666:     ?cfgh(P ++ [base], <<"string">>,
 2667:           T(#{<<"base">> => <<"string">>})),
 2668:     ?cfgh(P ++ [deref], always,
 2669:           T(#{<<"deref">> => <<"always">>})),
 2670:     %% Options: attributes
 2671:     ?cfgh(P ++ [groupattr], <<"cn">>,
 2672:           T(#{<<"groupattr">> => <<"cn">>})),
 2673:     ?cfgh(P ++ [groupdesc], <<"default">>,
 2674:           T(#{<<"groupdesc">> => <<"default">>})),
 2675:     ?cfgh(P ++ [userdesc], <<"cn">>,
 2676:           T(#{<<"userdesc">> => <<"cn">>})),
 2677:     ?cfgh(P ++ [useruid], <<"cn">>,
 2678:           T(#{<<"useruid">> => <<"cn">>})),
 2679:     ?cfgh(P ++ [memberattr], <<"memberUid">>,
 2680:           T(#{<<"memberattr">> => <<"memberUid">>})),
 2681:     ?cfgh(P ++ [memberattr_format], <<"%u">>,
 2682:           T(#{<<"memberattr_format">> => <<"%u">>})),
 2683:     ?cfgh(P ++ [memberattr_format_re], <<"">>,
 2684:           T(#{<<"memberattr_format_re">> => <<"">>})),
 2685:     %% Options: parameters
 2686:     ?cfgh(P ++ [auth_check], true,
 2687:           T(#{<<"auth_check">> => true})),
 2688:     ?cfgh(P ++ [user_cache_validity], 300,
 2689:           T(#{<<"user_cache_validity">> => 300})),
 2690:     ?cfgh(P ++ [group_cache_validity], 300,
 2691:           T(#{<<"group_cache_validity">> => 300})),
 2692:     ?cfgh(P ++ [user_cache_size], 300,
 2693:           T(#{<<"user_cache_size">> => 300})),
 2694:     ?cfgh(P ++ [group_cache_size], 300,
 2695:           T(#{<<"group_cache_size">> => 300})),
 2696:     %% Options: LDAP filters
 2697:     ?cfgh(P ++ [rfilter], <<"rfilter_test">>,
 2698:           T(#{<<"rfilter">> => <<"rfilter_test">>})),
 2699:     ?cfgh(P ++ [gfilter], <<"gfilter_test">>,
 2700:           T(#{<<"gfilter">> => <<"gfilter_test">>})),
 2701:     ?cfgh(P ++ [ufilter], <<"ufilter_test">>,
 2702:           T(#{<<"ufilter">> => <<"ufilter_test">>})),
 2703:     ?cfgh(P ++ [filter], <<"filter_test">>,
 2704:           T(#{<<"filter">> => <<"filter_test">>})),
 2705:     ?errh(T(#{<<"pool_tag">> => 1})),
 2706:     ?errh(T(#{<<"base">> => 1})),
 2707:     ?errh(T(#{<<"deref">> => 1})),
 2708:     %% Options: attributes
 2709:     ?errh(T(#{<<"groupattr">> => 1})),
 2710:     ?errh(T(#{<<"groupdesc">> => 1})),
 2711:     ?errh(T(#{<<"userdesc">> => 1})),
 2712:     ?errh(T(#{<<"useruid">> => 1})),
 2713:     ?errh(T(#{<<"memberattr">> => 1})),
 2714:     ?errh(T(#{<<"memberattr_format">> => 1})),
 2715:     ?errh(T(#{<<"memberattr_format_re">> => 1})),
 2716:     %% Options: parameters
 2717:     ?errh(T(#{<<"auth_check">> => 1})),
 2718:     ?errh(T(#{<<"user_cache_validity">> => -1})),
 2719:     ?errh(T(#{<<"group_cache_validity">> => -1})),
 2720:     ?errh(T(#{<<"user_cache_size">> => -1})),
 2721:     ?errh(T(#{<<"group_cache_size">> => -1})),
 2722:     %% Options: LDAP filters
 2723:     ?errh(T(#{<<"rfilter">> => 1})),
 2724:     ?errh(T(#{<<"gfilter">> => 1})),
 2725:     ?errh(T(#{<<"ufilter">> => 1})),
 2726:     ?errh(T(#{<<"filter">> => 1})).
 2727: 
 2728: mod_sic(_Config) ->
 2729:     check_module_defaults(mod_sic),
 2730:     check_iqdisc(mod_sic).
 2731: 
 2732: mod_smart_markers(_Config) ->
 2733:     check_module_defaults(mod_smart_markers),
 2734:     check_iqdisc(mod_smart_markers),
 2735:     P = [modules, mod_smart_markers],
 2736:     T = fun(Opts) -> #{<<"modules">> => #{<<"mod_smart_markers">> => Opts}} end,
 2737:     ?cfgh(P ++ [backend], rdbms, T(#{<<"backend">> => <<"rdbms">>})),
 2738:     ?cfgh(P ++ [keep_private], true, T(#{<<"keep_private">> => true})),
 2739:     ?cfgh(P ++ [async_writer], #{pool_size => 8}, T(#{<<"async_writer">> => #{<<"pool_size">> => 8}})),
 2740:     ?errh(T(#{<<"backend">> => <<"nodejs">>})),
 2741:     ?errh(T(#{<<"keep_private">> => 1})).
 2742: 
 2743: mod_stream_management(_Config) ->
 2744:     check_module_defaults(mod_stream_management),
 2745:     T = fun(Opts) -> #{<<"modules">> => #{<<"mod_stream_management">> => Opts}} end,
 2746:     P = [modules, mod_stream_management],
 2747:     ?cfgh(P ++ [buffer_max], no_buffer, T(#{<<"buffer">> => false})),
 2748:     ?cfgh(P ++ [buffer_max], 10,  T(#{<<"buffer_max">> => 10})),
 2749:     ?cfgh(P ++ [ack_freq], never, T(#{<<"ack">> => false})),
 2750:     ?cfgh(P ++ [ack_freq], 1, T(#{<<"ack_freq">> => 1})),
 2751:     ?cfgh(P ++ [resume_timeout], 999, T(#{<<"resume_timeout">> => 999})),
 2752: 
 2753:     ?errh(T(#{<<"buffer">> => 0})),
 2754:     ?errh(T(#{<<"buffer_max">> => -1})),
 2755:     ?errh(T(#{<<"ack">> => <<"false">>})),
 2756:     ?errh(T(#{<<"ack_freq">> => 0})),
 2757:     ?errh(T(#{<<"resume_timeout">> => true})),
 2758:     ?errh(T(#{<<"backend">> => <<"iloveyou">>})).
 2759: 
 2760: mod_stream_management_stale_h(_Config) ->
 2761:     P = [modules, mod_stream_management, stale_h],
 2762:     T = fun(Opts) -> #{<<"modules">> =>
 2763:                            #{<<"mod_stream_management">> => #{<<"stale_h">> => Opts}}} end,
 2764:     ?cfgh(P ++ [enabled], true, T(#{<<"enabled">> => true})),
 2765:     ?cfgh(P ++ [repeat_after], 999, T(#{<<"repeat_after">> => 999})),
 2766:     ?cfgh(P ++ [geriatric], 999, T(#{<<"geriatric">> => 999})),
 2767:     ?cfgh(P, config_parser_helper:default_config(P), T(#{})),
 2768: 
 2769:     ?errh(T(#{<<"enabled">> => <<"true">>})),
 2770:     ?errh(T(#{<<"repeat_after">> => -1})),
 2771:     ?errh(T(#{<<"geriatric">> => <<"one">>})).
 2772: 
 2773: mod_time(_Config) ->
 2774:     check_iqdisc(mod_time),
 2775:     check_module_defaults(mod_time).
 2776: 
 2777: mod_vcard(_Config) ->
 2778:     check_module_defaults(mod_vcard),
 2779:     check_iqdisc(mod_vcard),
 2780:     P = [modules, mod_vcard],
 2781:     T = fun(Opts) -> #{<<"modules">> => #{<<"mod_vcard">> => Opts}} end,
 2782:     ?cfgh(P ++ [iqdisc], one_queue,
 2783:           T(#{<<"iqdisc">> => #{<<"type">> => <<"one_queue">>}})),
 2784:     ?cfgh(P ++ [host], {prefix, <<"vjud.">>},
 2785:           T(#{<<"host">> => <<"vjud.@HOST@">>})),
 2786:     ?cfgh(P ++ [host], {fqdn, <<"vjud.test">>},
 2787:           T(#{<<"host">> => <<"vjud.test">>})),
 2788:     ?cfgh(P ++ [search], true,
 2789:           T(#{<<"search">> => true})),
 2790:     ?cfgh(P ++ [backend], mnesia,
 2791:           T(#{<<"backend">> => <<"mnesia">>})),
 2792:     ?cfgh(P ++ [matches], infinity,
 2793:           T(#{<<"matches">> => <<"infinity">>})),
 2794:     %% ldap
 2795:     ?cfgh(P ++ [ldap], config_parser_helper:default_config(P ++ [ldap]),
 2796:           T(#{<<"backend">> => <<"ldap">>})),
 2797:     ?cfgh(P ++ [ldap, pool_tag], my_tag,
 2798:           T(#{<<"backend">> => <<"ldap">>, <<"ldap">> => #{<<"pool_tag">> => <<"my_tag">>}})),
 2799:     ?cfgh(P ++ [ldap, base], <<"ou=Users,dc=ejd,dc=com">>,
 2800:           T(#{<<"backend">> => <<"ldap">>, <<"ldap">> => #{<<"base">> => <<"ou=Users,dc=ejd,dc=com">>}})),
 2801:     ?cfgh(P ++ [ldap, filter], <<"(&(objectClass=shadowAccount)(memberOf=Jabber Users))">>,
 2802:           T(#{<<"backend">> => <<"ldap">>, <<"ldap">> => #{<<"filter">> => <<"(&(objectClass=shadowAccount)(memberOf=Jabber Users))">>}})),
 2803:     ?cfgh(P ++ [ldap, deref], always,
 2804:           T(#{<<"backend">> => <<"ldap">>, <<"ldap">> => #{<<"deref">> => <<"always">>}})),
 2805:     ?cfgh(P ++ [ldap, search_operator], 'or',
 2806:           T(#{<<"backend">> => <<"ldap">>, <<"ldap">> => #{<<"search_operator">> => <<"or">>}})),
 2807:     ?cfgh(P ++ [ldap, binary_search_fields], [<<"PHOTO">>],
 2808:           T(#{<<"backend">> => <<"ldap">>, <<"ldap">> => #{<<"binary_search_fields">> => [<<"PHOTO">>]}})),
 2809:     %% riak
 2810:     ?cfgh(P ++ [riak, bucket_type], <<"vcard">>,
 2811:           T(#{<<"backend">> => <<"riak">>, <<"riak">> =>  #{<<"bucket_type">> => <<"vcard">>}})),
 2812:     ?cfgh(P ++ [riak, search_index], <<"vcard">>,
 2813:           T(#{<<"backend">> => <<"riak">>, <<"riak">> =>  #{<<"search_index">> => <<"vcard">>}})),
 2814: 
 2815:     ?errh(T(#{<<"host">> => 1})),
 2816:     ?errh(T(#{<<"host">> => <<"is this a host? no.">>})),
 2817:     ?errh(T(#{<<"host">> => [<<"invalid.sub@HOST@">>]})),
 2818:     ?errh(T(#{<<"host">> => [<<"invalid.sub.@HOST@.as.well">>]})),
 2819:     ?errh(T(#{<<"search">> => 1})),
 2820:     ?errh(T(#{<<"backend">> => <<"mememesia">>})),
 2821:     ?errh(T(#{<<"matches">> => -1})),
 2822:     %% ldap
 2823:     ?errh(T(#{<<"ldap_pool_tag">> => -1})),
 2824:     ?errh(T(#{<<"ldap_base">> => -1})),
 2825:     ?errh(T(#{<<"ldap_field">> => -1})),
 2826:     ?errh(T(#{<<"ldap_deref">> => <<"nevernever">>})),
 2827:     ?errh(T(#{<<"ldap_search_operator">> => <<"more">>})),
 2828:     ?errh(T(#{<<"ldap_binary_search_fields">> => [1]})),
 2829:     %% riak
 2830:     ?errh(T(#{<<"riak">> =>  #{<<"bucket_type">> => 1}})),
 2831:     ?errh(T(#{<<"riak">> =>  #{<<"search_index">> => 1}})).
 2832: 
 2833: mod_vcard_ldap_uids(_Config) ->
 2834:     P = [modules, mod_vcard, ldap, uids],
 2835:     T = fun(Opts) -> #{<<"modules">> =>
 2836:                            #{<<"mod_vcard">> => #{<<"backend">> => <<"ldap">>,
 2837:                                                   <<"ldap">> => #{<<"uids">> => Opts}}}} end,
 2838:     RequiredOpts = #{<<"attr">> => <<"name">>},
 2839:     ExpectedCfg = <<"name">>,
 2840:     ?cfgh(P, [], T([])),
 2841:     ?cfgh(P, [ExpectedCfg], T([RequiredOpts])),
 2842:     ?cfgh(P, [{<<"name">>, <<"%u@mail.example.org">>}],
 2843:           T([RequiredOpts#{<<"format">> => <<"%u@mail.example.org">>}])),
 2844:     ?cfgh(P, [{<<"name">>, <<"%u@mail.example.org">>}, ExpectedCfg],
 2845:           T([RequiredOpts#{<<"format">> => <<"%u@mail.example.org">>}, RequiredOpts])),
 2846:     [?errh(T([maps:remove(Key, RequiredOpts)])) || Key <- maps:keys(RequiredOpts)],
 2847:     ?errh(T(RequiredOpts#{<<"attr">> := 1})),
 2848:     ?errh(T(RequiredOpts#{<<"format">> => true})).
 2849: 
 2850: mod_vcard_ldap_vcard_map(_Config) ->
 2851:     P = [modules, mod_vcard, ldap, vcard_map],
 2852:     T = fun(Opts) -> #{<<"modules">> =>
 2853:                            #{<<"mod_vcard">> => #{<<"backend">> => <<"ldap">>,
 2854:                                                   <<"ldap">> => #{<<"vcard_map">> => Opts}}}} end,
 2855:     RequiredOpts = #{<<"vcard_field">> => <<"FAMILY">>,
 2856:                      <<"ldap_pattern">> => <<"%s">>,
 2857:                      <<"ldap_field">> => <<"sn">>},
 2858:     ExpectedCfg = {<<"FAMILY">>, <<"%s">>, [<<"sn">>]},
 2859:     ?cfgh(P, [], T([])),
 2860:     ?cfgh(P, [ExpectedCfg], T([RequiredOpts])),
 2861:     [?errh(T([maps:remove(Key, RequiredOpts)])) || Key <- maps:keys(RequiredOpts)],
 2862:     ?errh(T(RequiredOpts#{<<"vcard_field">> := false})),
 2863:     ?errh(T(RequiredOpts#{<<"ldap_pattern">> := false})),
 2864:     ?errh(T(RequiredOpts#{<<"ldap_field">> := -1})).
 2865: 
 2866: mod_vcard_ldap_search_fields(_Config) ->
 2867:     P = [modules, mod_vcard, ldap, search_fields],
 2868:     T = fun(Opts) -> #{<<"modules">> =>
 2869:                            #{<<"mod_vcard">> => #{<<"backend">> => <<"ldap">>,
 2870:                                                   <<"ldap">> => #{<<"search_fields">> => Opts}}}} end,
 2871:     RequiredOpts = #{<<"search_field">> => <<"Full Name">>,
 2872:                      <<"ldap_field">> => <<"cn">>},
 2873:     ExpectedCfg = {<<"Full Name">>, <<"cn">>},
 2874:     ?cfgh(P, [], T([])),
 2875:     ?cfgh(P, [ExpectedCfg], T([RequiredOpts])),
 2876:     [?errh(T([maps:remove(Key, RequiredOpts)])) || Key <- maps:keys(RequiredOpts)],
 2877:     ?errh(T(RequiredOpts#{<<"search_field">> := false})),
 2878:     ?errh(T(RequiredOpts#{<<"ldap_field">> := -1})).
 2879: 
 2880: mod_vcard_ldap_search_reported(_Config) ->
 2881:     P = [modules, mod_vcard, ldap, search_reported],
 2882:     T = fun(Opts) -> #{<<"modules">> =>
 2883:                            #{<<"mod_vcard">> => #{<<"backend">> => <<"ldap">>,
 2884:                                                   <<"ldap">> => #{<<"search_reported">> => Opts}}}} end,
 2885:     RequiredOpts = #{<<"search_field">> => <<"Full Name">>,
 2886:                      <<"vcard_field">> => <<"FN">>},
 2887:     ExpectedCfg = {<<"Full Name">>, <<"FN">>},
 2888:     ?cfgh(P, [], T([])),
 2889:     ?cfgh(P, [ExpectedCfg], T([RequiredOpts])),
 2890:     [?errh(T([maps:remove(Key, RequiredOpts)])) || Key <- maps:keys(RequiredOpts)],
 2891:     ?errh(T(RequiredOpts#{<<"search_field">> := false})),
 2892:     ?errh(T(RequiredOpts#{<<"vcard_field">> := -1})).
 2893: 
 2894: mod_version(_Config) ->
 2895:     check_module_defaults(mod_version),
 2896:     check_iqdisc(mod_version),
 2897:     P = [modules, mod_version],
 2898:     T = fun(Opts) -> #{<<"modules">> => #{<<"mod_version">> => Opts}} end,
 2899:     ?cfgh(P ++ [os_info], true, T(#{<<"os_info">> => true})),
 2900:     ?errh(T(#{<<"os_info">> => 1})).
 2901: 
 2902: modules_without_config(_Config) ->
 2903:     ?cfgh([modules, mod_amp], #{}, #{<<"modules">> => #{<<"mod_amp">> => #{}}}),
 2904:     ?errh(#{<<"modules">> => #{<<"mod_wrong">> => #{}}}).
 2905: 
 2906: incorrect_module(_Config) ->
 2907:     ?errh(#{<<"modules">> => #{<<"mod_incorrect">> => #{}}}).
 2908: 
 2909: %% Services
 2910: 
 2911: service_admin_extra(_Config) ->
 2912:     P = [services, service_admin_extra],
 2913:     T = fun(Opts) -> #{<<"services">> => #{<<"service_admin_extra">> => Opts}} end,
 2914:     ?cfg(P, default_config(P), T(#{})),
 2915:     ?cfg(P ++ [submods], [node], T(#{<<"submods">> => [<<"node">>]})),
 2916:     ?err(T(#{<<"submods">> => 1})),
 2917:     ?err(T(#{<<"submods">> => [1]})),
 2918:     ?err(T(#{<<"submods">> => [<<"nodejshaha">>]})).
 2919: 
 2920: service_domain_db(_Config) ->
 2921:     P = [services, service_domain_db],
 2922:     T = fun(Opts) -> #{<<"services">> => #{<<"service_domain_db">> => Opts}} end,
 2923:     ?cfg(P, default_config(P), T(#{})),
 2924:     ?cfg(P ++ [event_cleaning_interval], 1000, T(#{<<"event_cleaning_interval">> => 1000})),
 2925:     ?cfg(P ++ [event_max_age], 5000, T(#{<<"event_max_age">> => 5000})),
 2926:     ?cfg(P ++ [db_pool], my_pool, T(#{<<"db_pool">> => <<"my_pool">>})),
 2927:     ?err(T(#{<<"event_cleaning_interval">> => 0})),
 2928:     ?err(T(#{<<"event_max_age">> => 0})),
 2929:     ?err(T(#{<<"db_pool">> => 10})).
 2930: 
 2931: service_mongoose_system_metrics(_Config) ->
 2932:     P = [services, service_mongoose_system_metrics],
 2933:     T = fun(Opts) -> #{<<"services">> => #{<<"service_mongoose_system_metrics">> => Opts}} end,
 2934:     ?cfg(P, default_config(P), T(#{})),
 2935:     ?cfg(P ++ [initial_report], 5000, T(#{<<"initial_report">> => 5000})),
 2936:     ?cfg(P ++ [periodic_report], 5000, T(#{<<"periodic_report">> => 5000})),
 2937:     ?cfg(P ++ [tracking_id], "UA-123456789", T(#{<<"tracking_id">> => <<"UA-123456789">>})),
 2938:     ?cfg(P ++ [report], true, T(#{<<"report">> => true})),
 2939:     ?err(T(#{<<"initial_report">> => <<"forever">>})),
 2940:     ?err(T(#{<<"periodic_report">> => <<"forever">>})),
 2941:     ?err(T(#{<<"initial_report">> => -1})),
 2942:     ?err(T(#{<<"periodic_report">> => -1})),
 2943:     ?err(T(#{<<"tracking_id">> => 666})),
 2944:     ?err(T(#{<<"report">> => <<"maybe">>})).
 2945: 
 2946: %% Helpers for module tests
 2947: 
 2948: check_iqdisc(Module) ->
 2949:     P = [modules, Module],
 2950:     T = fun(Opts) -> #{<<"modules">> => #{atom_to_binary(Module) => Opts}} end,
 2951:     check_iqdisc(P, T).
 2952: 
 2953: check_iqdisc(Module, RequiredOpts) when is_map(RequiredOpts) ->
 2954:     P = [modules, Module],
 2955:     T = fun(Opts) ->
 2956:                 #{<<"modules">> => #{atom_to_binary(Module) => maps:merge(RequiredOpts, Opts)}}
 2957:         end,
 2958:     check_iqdisc(P, T);
 2959: check_iqdisc(ParentP, ParentT) when is_function(ParentT, 1) ->
 2960:     P = ParentP ++ [iqdisc],
 2961:     T = fun(Opts) -> ParentT(#{<<"iqdisc">> => Opts}) end,
 2962:     ?cfgh(P, {queues, 10}, T(#{<<"type">> => <<"queues">>, <<"workers">> => 10})),
 2963:     ?cfgh(P, parallel, T(#{<<"type">> => <<"parallel">>})),
 2964:     ?cfgh(P, one_queue, T(#{<<"type">> => <<"one_queue">>})),
 2965:     ?cfgh(P, no_queue, T(#{<<"type">> => <<"no_queue">>})),
 2966:     ?errh(T(#{<<"type">> => <<"one_queue_and_a_half">>})),
 2967:     ?errh(T(#{<<"type">> => <<"queues">>, <<"workers">> => 0})),
 2968:     ?errh(T(#{<<"type">> => <<"no_queue">>, <<"workers">> => 10})),
 2969:     ?errh(T(#{<<"workers">> => 10})).
 2970: 
 2971: check_module_defaults(Mod) ->
 2972:     ExpectedCfg = default_mod_config(Mod),
 2973:     ?cfgh([modules, Mod], ExpectedCfg, #{<<"modules">> => #{atom_to_binary(Mod) => #{}}}).
 2974: 
 2975: %% helpers for 'listen' tests
 2976: 
 2977: listener(Type, Opts) ->
 2978:     config([listen, Type], Opts).
 2979: 
 2980: graphql_handler_raw(Opts) ->
 2981:     http_handler_raw(mongoose_graphql_cowboy_handler,
 2982:                      maps:merge(#{<<"schema_endpoint">> => <<"admin">>}, Opts)).
 2983: 
 2984: http_handler_raw(Type, Opts) ->
 2985:     MergedOpts = maps:merge(#{<<"host">> => <<"localhost">>, <<"path">> => <<"/api">>}, Opts),
 2986:     listen_raw(http, #{<<"port">> => 5280,
 2987:                        <<"handlers">> => #{atom_to_binary(Type) => [remove_undefined(MergedOpts)]}}
 2988:               ).
 2989: 
 2990: listen_raw(Type, Opts) ->
 2991:     #{<<"listen">> => #{atom_to_binary(Type) => [remove_undefined(Opts)]}}.
 2992: 
 2993: remove_undefined(M) ->
 2994:     maps:filter(fun(_, V) -> V =/= undefined end, M).
 2995: 
 2996: %% helpers for 'auth' tests
 2997: 
 2998: auth_ldap_raw(Opts) ->
 2999:     auth_raw(<<"ldap">>, Opts).
 3000: 
 3001: auth_raw(Method, Opts) ->
 3002:     #{<<"auth">> => #{Method => Opts}}.
 3003: 
 3004: %% helpers for 'pool' tests
 3005: 
 3006: pool_raw(Type, Tag, Opts) ->
 3007:     #{<<"outgoing_pools">> => #{Type => #{Tag => Opts}}}.
 3008: 
 3009: pool_conn_raw(Type, Opts) ->
 3010:     #{<<"outgoing_pools">> => #{Type => #{<<"default">> => #{<<"connection">> => Opts}}}}.
 3011: 
 3012: %% helpers for 'access' tests
 3013: 
 3014: access_raw(RuleName, RuleSpec) ->
 3015:     #{<<"access">> => #{RuleName => RuleSpec}}.
 3016: 
 3017: %% helpers for 'host_config' tests
 3018: 
 3019: host_config(Config) ->
 3020:     #{<<"host_config">> => [Config#{<<"host_type">> => ?HOST}]}.
 3021: 
 3022: %% helpers for parsing
 3023: 
 3024: -spec parse(map()) -> [mongoose_config_parser_toml:config()].
 3025: parse(M0) ->
 3026:     %% As 'hosts' (or 'host_types') and 'default_server_domain' options are mandatory,
 3027:     %% this function inserts them with dummy values if they are missing.
 3028:     %% To prevent the insertion, add a 'without' option to the map, e.g. without => [<<"hosts">>]
 3029:     %% The resulting map is then passed to the TOML config parser.
 3030:     M = maybe_insert_dummy_domain(M0),
 3031:     mongoose_config_parser:get_opts(mongoose_config_parser_toml:process(M)).
 3032: 
 3033: maybe_insert_dummy_domain(M) ->
 3034:     DummyGenM = #{<<"default_server_domain">> => ?HOST,
 3035:                   <<"hosts">> => [?HOST]},
 3036:     {FilteredGenM, RawConfig} = case maps:take(without, M) of
 3037:                                     {Keys, Cfg} -> {maps:without(Keys, DummyGenM), Cfg};
 3038:                                     error -> {DummyGenM, M}
 3039:                                 end,
 3040:     OldGenM = maps:get(<<"general">>, RawConfig, #{}),
 3041:     NewGenM = maps:merge(FilteredGenM, OldGenM),
 3042:     RawConfig#{<<"general">> => NewGenM}.
 3043: 
 3044: %% helpers for testing individual options
 3045: 
 3046: -spec host_opts([{key_prefix(), mongoose_config:value()}]) ->
 3047:           [{mongoose_config:key() | mongoose_config:key_path(), mongoose_config:value()}].
 3048: host_opts(ExpectedOptions) ->
 3049:     lists:map(fun({Key, Value}) -> {host_key(Key), Value} end, ExpectedOptions).
 3050: 
 3051: %% @doc Build full per-host config key for host-or-global options
 3052: -spec host_key(top_level_key_prefix()) -> mongoose_config:key();
 3053:               (key_path_prefix()) -> mongoose_config:key_path().
 3054: host_key([TopKey | Rest]) when is_atom(TopKey) ->
 3055:     [{TopKey, ?HOST} | Rest];
 3056: host_key(Key) when is_atom(Key) ->
 3057:     {Key, ?HOST}.
 3058: 
 3059: -spec assert_options([{mongoose_config:key() | mongoose_config:key_path(), mongoose_config:value()}],
 3060:                      [mongoose_config_parser_toml:config()]) -> any().
 3061: assert_options(ExpectedOptions, Config) ->
 3062:     lists:foreach(fun({Key, Value}) -> assert_option(Key, Value, Config) end, ExpectedOptions).
 3063: 
 3064: -spec assert_option(mongoose_config:key() | mongoose_config:key_path(), mongoose_config:value(),
 3065:                     [mongoose_config_parser_toml:config()]) -> any().
 3066: assert_option(KeyPath, Value, Config) when is_list(KeyPath) ->
 3067:     compare_nodes(KeyPath, Value, get_config_value(KeyPath, Config));
 3068: assert_option(Key, Value, Config) ->
 3069:     assert_option([Key], Value, Config).
 3070: 
 3071: -spec get_config_value(mongoose_config:key_path(), [mongoose_config_parser_toml:config()]) ->
 3072:           mongoose_config:value().
 3073: get_config_value([TopKey | Rest], Config) ->
 3074:     case lists:keyfind(TopKey, 1, Config) of
 3075:         false -> ct:fail({"option not found", TopKey, Config});
 3076:         {_, TopValue} -> lists:foldl(fun get_value/2, TopValue, Rest)
 3077:     end.
 3078: 
 3079: get_value(Index, List) when is_integer(Index), Index > 0, is_list(List) ->
 3080:     lists:nth(Index, List);
 3081: get_value(Key, Map) when not is_integer(Key), is_map(Map) ->
 3082:     maps:get(Key, Map).
 3083: 
 3084: %% helpers for file tests
 3085: 
 3086: test_config_file(Config, File) ->
 3087:     OptionsPath = ejabberd_helper:data(Config, File ++ ".options"),
 3088:     ExpectedOpts = config_parser_helper:options(File),
 3089: 
 3090:     TOMLPath = ejabberd_helper:data(Config, File ++ ".toml"),
 3091:     State = mongoose_config_parser:parse_file(TOMLPath),
 3092:     TOMLOpts = mongoose_config_parser:get_opts(State),
 3093: 
 3094:     %% Save the parsed TOML options
 3095:     %% - for debugging
 3096:     %% - to update tests after a config change - always check the diff!
 3097:     save_opts(OptionsPath ++ ".parsed", TOMLOpts),
 3098:     compare_config(ExpectedOpts, TOMLOpts).
 3099: 
 3100: save_opts(Path, Opts) ->
 3101:     FormattedOpts = [io_lib:format("~p.~n", [Opt]) || Opt <- lists:sort(Opts)],
 3102:     file:write_file(Path, FormattedOpts).
 3103: 
 3104: compare_config(C1, C2) ->
 3105:     compare_unordered_lists(C1, C2, fun handle_config_option/2).
 3106: 
 3107: handle_config_option({K1, V1}, {K2, V2}) ->
 3108:     ?eq(K1, K2),
 3109:     compare_nodes([K1], V1, V2);
 3110: handle_config_option(Opt1, Opt2) ->
 3111:     ?eq(Opt1, Opt2).
 3112: 
 3113: %% Comparisons for config options that have paths (top-level or nested in maps)
 3114: 
 3115: -spec compare_nodes(mongoose_config:key_path(), mongoose_config:value(), mongoose_config:value()) ->
 3116:           any().
 3117: compare_nodes([listen] = P, V1, V2) ->
 3118:     compare_ordered_lists_of_nodes(P, V1, V2);
 3119: compare_nodes([listen, I, handlers] = P, V1, V2) when is_integer(I) ->
 3120:     compare_ordered_lists_of_nodes(P, V1, V2);
 3121: compare_nodes([outgoing_pools] = P, V1, V2) ->
 3122:     compare_ordered_lists_of_nodes(P, V1, V2);
 3123: compare_nodes(Node, V1, V2) when is_map(V1), is_map(V2) ->
 3124:     compare_maps(V1, V2, fun({K1, MV1}, {K2, MV2}) ->
 3125:                                  ?eq(K1, K2),
 3126:                                  compare_nodes(Node ++ [K1], MV1, MV2)
 3127:                          end);
 3128: compare_nodes(Node, V1, V2) ->
 3129:     ?eq({Node, V1}, {Node, V2}).
 3130: 
 3131: compare_ordered_lists_of_nodes(Path, L1, L2) when length(L1) =:= length(L2) ->
 3132:     lists:foreach(fun({I, V1, V2}) -> compare_nodes(Path ++ [I], V1, V2) end,
 3133:                   lists:zip3(lists:seq(1, length(L1)), L1, L2)).
 3134: 
 3135: %% Generic assertions, use the 'F' handler for any custom cases
 3136: compare_unordered_lists(L1, L2) when is_list(L1), is_list(L2) ->
 3137:     compare_unordered_lists(L1, L2, fun(V1, V2) -> ?eq(V1, V2) end).
 3138: 
 3139: compare_unordered_lists(L1, L2, F) when is_list(L1), is_list(L2) ->
 3140:     SL1 = lists:sort(L1),
 3141:     SL2 = lists:sort(L2),
 3142:     compare_ordered_lists(SL1, SL2, F).
 3143: 
 3144: compare_ordered_lists([H1|T1], [H1|T2], F) ->
 3145:     compare_ordered_lists(T1, T2, F);
 3146: compare_ordered_lists([H1|T1] = L1, [H2|T2] = L2, F) ->
 3147:     try F(H1, H2)
 3148:     catch error:R:S ->
 3149:             ct:fail({"Failed to compare ordered lists", L1, L2, R, S})
 3150:     end,
 3151:     compare_ordered_lists(T1, T2, F);
 3152: compare_ordered_lists([], [], _) ->
 3153:     ok.
 3154: 
 3155: compare_maps(M1, M2) ->
 3156:     compare_maps(M1, M2, fun(V1, V2) -> ?eq(V1, V2) end).
 3157: 
 3158: compare_maps(M1, M2, F) ->
 3159:     compare_unordered_lists(maps:to_list(M1), maps:to_list(M2), F).
 3160: 
 3161: create_files(Config) ->
 3162:     %% The files must exist for validation to pass
 3163:     Root = small_path_helper:repo_dir(Config),
 3164:     file:make_dir("priv"),
 3165:     [ensure_copied(filename:join(Root, From), To) || {From, To} <- files_to_copy()],
 3166:     ok = file:write_file("priv/access_psk", ""),
 3167:     ok = file:write_file("priv/provision_psk", ""),
 3168:     ok = filelib:ensure_dir("www/muc/dummy").
 3169: 
 3170: ensure_copied(From, To) ->
 3171:     case file:copy(From, To) of
 3172:         {ok,_} ->
 3173:             ok;
 3174:         Other ->
 3175:             error(#{what => ensure_copied_failed, from => From, to => To,
 3176:                     reason => Other})
 3177:     end.
 3178: 
 3179: files_to_copy() ->
 3180:     [{"tools/ssl/mongooseim/privkey.pem", "priv/dc1.pem"},
 3181:      {"tools/ssl/mongooseim/cert.pem", "priv/cert.pem"},
 3182:      {"tools/ssl/mongooseim/dh_server.pem", "priv/dh.pem"},
 3183:      {"tools/ssl/mongooseim/server.pem", "priv/server.pem"},
 3184:      {"tools/ssl/ca/cacert.pem", "priv/ca.pem"}].