Skip to content

Commit

Permalink
Merge pull request #3553 from esl/mod_vcard-map
Browse files Browse the repository at this point in the history
Put mod_vcard config options in a map
  • Loading branch information
chrzaszcz authored Feb 23, 2022
2 parents 7c3eb5f + b1ee098 commit 028f9e4
Show file tree
Hide file tree
Showing 14 changed files with 215 additions and 150 deletions.
2 changes: 1 addition & 1 deletion big_tests/tests/domain_removal_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ group_to_modules(roster_removal) ->
group_to_modules(offline_removal) ->
[{mod_offline, [{backend, rdbms}]}];
group_to_modules(vcard_removal) ->
[{mod_vcard, [{backend, rdbms}]}];
[{mod_vcard, config_parser_helper:mod_config(mod_vcard, #{backend => rdbms})}];
group_to_modules(last_removal) ->
[{mod_last, [{backend, rdbms}]}].

Expand Down
9 changes: 8 additions & 1 deletion big_tests/tests/gdpr_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,14 @@ pick_enabled_backend() ->


vcard_required_modules() ->
[{mod_vcard, [{backend, pick_enabled_backend()}]}].
Backend = pick_enabled_backend(),
[{mod_vcard, config_parser_helper:mod_config(mod_vcard, vcard_backend_opts(Backend))}].

vcard_backend_opts(riak) ->
#{backend => riak, riak => #{bucket_type => <<"vcard">>,
search_index => <<"vcard">>}};
vcard_backend_opts(Backend) ->
#{backend => Backend}.

offline_required_modules() ->
[{mod_offline, [{backend, pick_enabled_backend()}]}].
Expand Down
3 changes: 2 additions & 1 deletion big_tests/tests/service_mongoose_system_metrics_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ init_per_testcase(xmpp_components_are_reported, Config) ->
Config1;
init_per_testcase(module_backend_is_reported, Config) ->
create_events_collection(),
dynamic_modules:ensure_modules(host_type(), [{mod_vcard, []}]),
DefModVCardConfig = config_parser_helper:default_mod_config(mod_vcard),
dynamic_modules:ensure_modules(host_type(), [{mod_vcard, DefModVCardConfig}]),
enable_system_metrics(mim()),
Config;
init_per_testcase(xmpp_stanzas_counts_are_reported = CN, Config) ->
Expand Down
62 changes: 25 additions & 37 deletions big_tests/tests/vcard_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,10 @@ init_per_group(Group, Config) when Group == rw; Group == params_limited_infinity
end;
init_per_group(ldap_only, Config) ->
VCardConfig = ?config(mod_vcard_opts, Config),
case proplists:get_value(backend, VCardConfig) of
case maps:get(backend, VCardConfig) of
ldap ->
Config1 = restart_and_prepare_vcard(ldap_only, Config),
insert_alice_photo(Config1);
%Config1;
_ ->
{skip, "this group is only for ldap vCard backend"}
end;
Expand Down Expand Up @@ -905,7 +904,6 @@ search_open_limited(Config) ->
escalus_stanza:search_iq(DirJID,
escalus_stanza:search_fields(Fields))),
escalus:assert(is_iq_result, Res),
%% {allow_return_all, false}
[] = search_result_item_tuples(Res)
end).

Expand Down Expand Up @@ -1015,12 +1013,7 @@ prepare_vcards(Config) ->
Config.

get_backend(Config) ->
case lists:keyfind(backend, 1, ?config(mod_vcard_opts, Config)) of
{backend, Backend} ->
Backend;
_ ->
mnesia
end.
maps:get(backend, ?config(mod_vcard_opts, Config), mnesia).

prepare_vcard(ldap, JID, Fields) ->
[User, Server] = binary:split(JID, <<"@">>),
Expand Down Expand Up @@ -1155,7 +1148,6 @@ prepare_vcard_module(Config) ->
%% Keep the old config, so we can undo our changes, once finished testing
Config1 = dynamic_modules:save_modules(host_types(), Config),
%% Get a list of options, we can use as a prototype to start new modules
_HostType = domain_helper:host_type(),
VCardOpts = dynamic_modules:get_saved_config(host_type(), mod_vcard, Config1),
[{mod_vcard_opts, VCardOpts} | Config1].

Expand All @@ -1167,46 +1159,43 @@ stop_vcard_mod(_Config) ->
ok.

params_all(Config) ->
add_backend_param([], ?config(mod_vcard_opts, Config)).
add_backend_param(#{}, ?config(mod_vcard_opts, Config)).

params_limited(Config) ->
add_backend_param([{matches, 1},
{host, subhost_pattern("directory.@HOST@")}],
add_backend_param(#{matches => 1,
host => subhost_pattern("directory.@HOST@")},
?config(mod_vcard_opts, Config)).

params_limited_infinity(Config) ->
add_backend_param([{matches, infinity},
{host, subhost_pattern("directory.@HOST@")}],
add_backend_param(#{matches => infinity,
host => subhost_pattern("directory.@HOST@")},
?config(mod_vcard_opts, Config)).

params_no(Config) ->
add_backend_param([{search, false},
{host, subhost_pattern("vjud.@HOST@")}],
add_backend_param(#{search => false,
host => subhost_pattern("vjud.@HOST@")},
?config(mod_vcard_opts, Config)).

params_ldap_only(Config) ->
Reported = [{<<"Full Name">>, <<"FN">>},
{<<"Given Name">>, <<"FIRST">>},
{<<"Middle Name">>, <<"MIDDLE">>},
{<<"Family Name">>, <<"LAST">>},
{<<"Nickname">>, <<"NICK">>},
{<<"Birthday">>, <<"BDAY">>},
{<<"Country">>, <<"CTRY">>},
{<<"City">>, <<"LOCALITY">>},
{<<"Email">>, <<"EMAIL">>},
{<<"Organization Name">>, <<"ORGNAME">>},
{<<"Organization Unit">>, <<"ORGUNIT">>},
{<<"Photo">>, <<"PHOTO">>}],
add_backend_param([{ldap_search_operator, 'or'},
{ldap_binary_search_fields, [<<"PHOTO">>]},
{ldap_search_reported, Reported}],
{<<"Given Name">>, <<"FIRST">>},
{<<"Middle Name">>, <<"MIDDLE">>},
{<<"Family Name">>, <<"LAST">>},
{<<"Nickname">>, <<"NICK">>},
{<<"Birthday">>, <<"BDAY">>},
{<<"Country">>, <<"CTRY">>},
{<<"City">>, <<"LOCALITY">>},
{<<"Email">>, <<"EMAIL">>},
{<<"Organization Name">>, <<"ORGNAME">>},
{<<"Organization Unit">>, <<"ORGUNIT">>},
{<<"Photo">>, <<"PHOTO">>}],
add_backend_param(#{ldap_search_operator => 'or',
ldap_binary_search_fields => [<<"PHOTO">>],
ldap_search_reported => Reported},
?config(mod_vcard_opts, Config)).

add_backend_param(Opts, CurrentVCardConfig) ->
F = fun({Key, _} = Item, Cfg) ->
lists:keystore(Key, 1, Cfg, Item)
end,
lists:foldl(F, CurrentVCardConfig, Opts).
maps:merge(CurrentVCardConfig, Opts).

%%----------------------
%% xmlel shortcuts
Expand Down Expand Up @@ -1549,8 +1538,7 @@ secondary_domain() ->
ct:get_config({hosts, mim, secondary_domain}).

wait_for_riak() ->
HostType = ct:get_config({hosts, mim, host_type}),
case mam_helper:is_riak_enabled(HostType) of
case mam_helper:is_riak_enabled(host_type()) of
true ->
timer:sleep(timer:seconds(3)); %give some time to Yokozuna to index vcards
false ->
Expand Down
16 changes: 9 additions & 7 deletions big_tests/tests/vcard_simple_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -454,12 +454,14 @@ configure_mod_vcard(Config) ->
end.

ldap_opts() ->
[{backend,ldap}, {host, subhost_pattern("vjud.@HOST@")},
{ldap_uids, [{<<"uid">>}]}, %% equivalent to {<<"uid">>, <<"%u">>}
{ldap_filter,<<"(objectClass=inetOrgPerson)">>},
{ldap_base,"ou=Users,dc=esl,dc=com"},
{ldap_search_fields, [{"Full Name","cn"},{"User","uid"}]},
{ldap_vcard_map,[{"FN","%s",["cn"]}]}].
VCardOpts = #{backend => ldap,
host => subhost_pattern("vjud.@HOST@"),
ldap_uids => [{<<"uid">>}], %% equivalent to {<<"uid">>, <<"%u">>}
ldap_filter => <<"(objectClass=inetOrgPerson)">>,
ldap_base => "ou=Users,dc=esl,dc=com",
ldap_search_fields => [{"Full Name", "cn"}, {"User", "uid"}],
ldap_vcard_map => [{"FN", "%s", ["cn"]}]},
config_parser_helper:mod_config(mod_vcard, VCardOpts).

ensure_started(HostType, Opts) ->
dynamic_modules:stop(HostType, mod_vcard),
Expand All @@ -469,7 +471,7 @@ prepare_vcard_module(Config) ->
%% Keep the old config, so we can undo our changes, once finished testing
Config1 = dynamic_modules:save_modules(host_types(), Config),
%% Get a list of options, we can use as a prototype to start new modules
VCardOpts = dynamic_modules:get_saved_config(host_type(), mod_vcard, Config1),
VCardOpts = config_parser_helper:default_mod_config(mod_vcard),
[{mod_vcard_opts, VCardOpts} | Config1].

restore_vcard_module(Config) ->
Expand Down
4 changes: 2 additions & 2 deletions doc/authentication-methods/ldap.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ LDAP base directory which stores user accounts.
* **Syntax:** array of TOML tables with the following content:
* `attr` - string, mandatory, name of the attribute
* `format` - pattern, default: `"%u"`, requires `attr`
* **Default:** `[{attr = "my_uid"}]`
* **Example:** `uids = [{attr = "my_uid", format = "%u@example.org"}, {attr = "another_uid"}]`
* **Default:** `[{attr = "uid"}]`
* **Example:** `uids = [{attr = "uid", format = "%u@example.org"}, {attr = "another_uid"}]`

List of LDAP attributes that contain the user name (user's part of the JID), used to search for user accounts.
They are used as alternatives - it is enough if one of them contains the name.
Expand Down
20 changes: 9 additions & 11 deletions doc/modules/mod_vcard.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This module provides support for vCards, as specified in [XEP-0054: vcard-temp](

### `modules.mod_vcard.iqdisc.type`
* **Syntax:** string, one of `"one_queue"`, `"no_queue"`, `"queues"`, `"parallel"`
* **Default:** `"one_queue"`
* **Default:** `"parallel"`

Strategy to handle incoming stanzas. For details, please refer to
[IQ processing policies](../configuration/Modules.md#iq-processing-policies).
Expand Down Expand Up @@ -47,34 +47,34 @@ Maximum search results to be returned to the user.

The following options are the same as for the [LDAP authentication module](../authentication-methods/ldap.md#configuration-options):

* [`modules.mod_vcard.ldap_pool_tag`](../authentication-methods/ldap.md#authldappool_tag)
* [`modules.mod_vcard.ldap_base`](../authentication-methods/ldap.md#authldapbase)
* [`modules.mod_vcard.ldap_uids`](../authentication-methods/ldap.md#authldapuids)
* [`modules.mod_vcard.ldap_filter`](../authentication-methods/ldap.md#authldapfilter)
* [`modules.mod_vcard.ldap_deref`](../authentication-methods/ldap.md#authldapderef)
* #### [`modules.mod_vcard.ldap_pool_tag`](../authentication-methods/ldap.md#authldappool_tag)
* #### [`modules.mod_vcard.ldap_base`](../authentication-methods/ldap.md#authldapbase)
* #### [`modules.mod_vcard.ldap_uids`](../authentication-methods/ldap.md#authldapuids)
* #### [`modules.mod_vcard.ldap_filter`](../authentication-methods/ldap.md#authldapfilter)
* #### [`modules.mod_vcard.ldap_deref`](../authentication-methods/ldap.md#authldapderef)

#### `modules.mod_vcard.ldap_vcard_map`
* **Syntax:** Array of TOML tables with the following keys: `"vcard_field"`, `"ldap_pattern"`, `"ldap_field"` and string values.
* **Default:** see description
* **Example:** `ldap_vcard_map = [{vcard_field = "FN", ldap_pattern = "%s", ldap_field = "displayName"}]`

Mappings between VCard and LDAP fields. For the default settings, please see `[MongooseIM root]/src/mod_vcard_ldap.erl`, line 79.
Mappings between VCard and LDAP fields. For the default settings, please see `[MongooseIM root]/src/mod_vcard_ldap.erl`.

#### `modules.mod_vcard.ldap_search_fields`
* **Syntax:** Array of TOML tables with the following keys: `"search_field"`, `"ldap_field"` and string values.
* **Default:** see description
* **Example:** `ldap_search_fields = [{search_field = "User", ldap_field = "%u"}]`

Mappings between the human-readable search fields and LDAP fields.
For the default settings, please see `[MongooseIM root]/src/mod_vcard_ldap.erl`, line 101.
For the default settings, please see `[MongooseIM root]/src/mod_vcard_ldap.erl`.

#### `modules.mod_vcard.ldap_search_reported`
* **Syntax:** Array of TOML tables with the following keys: `"search_field"`, `"vcard_field"` and string values.
* **Default:** see description
* **Example:** `ldap_search_reported = [{search_field = "Full Name", vcard_field = "FN"}]`

Mappings between the human-readable search fields and VCard fields.
For the default settings, please see `[MongooseIM root]/src/mod_vcard_ldap.erl`, line 114.
For the default settings, please see `[MongooseIM root]/src/mod_vcard_ldap.erl`.

#### `modules.mod_vcard.ldap_search_operator`
* **Syntax:** string, one of `"or"`, `"and"`
Expand Down Expand Up @@ -110,8 +110,6 @@ Riak index name.

```toml
[modules.mod_vcard]
allow_return_all = true
search_all_hosts = true
matches = 1
search = true
host = "directory.example.com"
Expand Down
2 changes: 0 additions & 2 deletions include/mod_vcard.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
orgunit, lorgunit}).
-record(vcard, {us, vcard}).

-define(JUD_MATCHES, 30).

-define(TLFIELD(Type, Label, Var),
#xmlel{name = <<"field">>,
attrs =
Expand Down
Loading

0 comments on commit 028f9e4

Please sign in to comment.