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