Skip to content

Commit

Permalink
Merge pull request #3646 from esl/graphql/merge-http-handlers-config-…
Browse files Browse the repository at this point in the history
…rerwork

GraphQL - Merge master with HTTP handlers config reworked
  • Loading branch information
chrzaszcz authored May 13, 2022
2 parents 6b21198 + f786e54 commit bfc1ee0
Show file tree
Hide file tree
Showing 90 changed files with 893 additions and 1,013 deletions.
5 changes: 4 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ commands:
steps:
- run:
name: Prepare cache key
command: tools/make-certs-cache-key.sh > certs_cache_key
command: tools/make-certs-cache-key.sh > certs_cache_key && cat certs_cache_key
- restore_cache:
name: Restore certificates
key: *CERT_KEY
Expand All @@ -41,6 +41,9 @@ commands:
- run:
name: Print cert hashes for debugging
command: find tools/ssl -type f -exec md5sum {} \; | sort
- run:
name: Continue if certificate exists
command: test -f tools/ssl/mongooseim/key.pem
- save_cache:
name: Cache built certs
key: *CERT_KEY
Expand Down
2 changes: 1 addition & 1 deletion big_tests/rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
{csv, "3.0.3", {pkg, csve}},
{amqp_client, "3.9.5"},
{esip, "1.0.43"},
{jid, "1.1.1", {pkg, mongoose_jid}}
{jid, "2.0.0", {pkg, mongoose_jid}}
]}.
6 changes: 3 additions & 3 deletions big_tests/rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{<<"fusco">>,{pkg,<<"fusco">>,<<"0.1.1">>},0},
{<<"goldrush">>,{pkg,<<"goldrush">>,<<"0.1.9">>},1},
{<<"gun">>,{pkg,<<"gun">>,<<"2.0.0-rc.2">>},0},
{<<"jid">>,{pkg,<<"mongoose_jid">>,<<"1.1.1">>},0},
{<<"jid">>,{pkg,<<"mongoose_jid">>,<<"2.0.0">>},0},
{<<"jiffy">>,{pkg,<<"jiffy">>,<<"1.1.1">>},0},
{<<"jsx">>,{pkg,<<"jsx">>,<<"3.1.0">>},2},
{<<"lager">>,{pkg,<<"lager">>,<<"3.9.2">>},0},
Expand Down Expand Up @@ -50,7 +50,7 @@
{<<"fusco">>, <<"3DD6A90151DFEF30EA1937CC44E9A59177C0094918388D9BCAA2F2DC5E2AE4AA">>},
{<<"goldrush">>, <<"F06E5D5F1277DA5C413E84D5A2924174182FB108DABB39D5EC548B27424CD106">>},
{<<"gun">>, <<"7C489A32DEDCCB77B6E82D1F3C5A7DADFBFA004EC14E322CDB5E579C438632D2">>},
{<<"jid">>, <<"C9D92768FBC120C717E944AFE523FA0062C5B665E4D776724B2F8E54831AB2CA">>},
{<<"jid">>, <<"0D0FD1130EAD05DF672D1C9E0405D3000F0C87A7D446577755CF5EB173104FE9">>},
{<<"jiffy">>, <<"ACA10F47AA91697BF24AB9582C74E00E8E95474C7EF9F76D4F1A338D0F5DE21B">>},
{<<"jsx">>, <<"D12516BAA0BB23A59BB35DCCAF02A1BD08243FCBB9EFE24F2D9D056CCFF71268">>},
{<<"lager">>, <<"4CAB289120EB24964E3886BD22323CB5FEFE4510C076992A23AD18CF85413D8C">>},
Expand Down Expand Up @@ -82,7 +82,7 @@
{<<"fusco">>, <<"6343551BD1E824F2A6CA85E1158C5B37C320FD449FBFEC7450A73F192AAF9022">>},
{<<"goldrush">>, <<"99CB4128CFFCB3227581E5D4D803D5413FA643F4EB96523F77D9E6937D994CEB">>},
{<<"gun">>, <<"6B9D1EAE146410D727140DBF8B404B9631302ECC2066D1D12F22097AD7D254FC">>},
{<<"jid">>, <<"61EDDBAC9908747DA29F7C79545C744C31A25652CCB53248E684DBB083EFBE9A">>},
{<<"jid">>, <<"7BAE8403552D5BCECD1CD2A848445B5FC3533F5EEB355173A0531A1A1AA8E008">>},
{<<"jiffy">>, <<"62E1F0581C3C19C33A725C781DFA88410D8BFF1BBAFC3885A2552286B4785C4C">>},
{<<"jsx">>, <<"0C5CC8FDC11B53CC25CF65AC6705AD39E54ECC56D1C22E4ADB8F5A53FB9427F3">>},
{<<"lager">>, <<"7F904D9E87A8CB7E66156ED31768D1C8E26EBA1D54F4BC85B1AA4AC1F6340C28">>},
Expand Down
4 changes: 2 additions & 2 deletions big_tests/tests/accounts_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ registration_conflict(Config) ->
admin_notify(Config) ->
[{Name1, UserSpec1}, {Name2, UserSpec2}] = escalus_users:get_users([alice, bob]),
[{_, AdminSpec}] = escalus_users:get_users([admin]),
[Username1, _Server1, _Pass1] = escalus_users:get_usp(Config, UserSpec1),
[Username2, _Server2, _Pass2] = escalus_users:get_usp(Config, UserSpec2),
Username1 = jid:str_tolower(escalus_users:get_username(Config, UserSpec1)),
Username2 = jid:str_tolower(escalus_users:get_username(Config, UserSpec2)),
[AdminU, AdminS, AdminP] = escalus_users:get_usp(Config, AdminSpec),

rpc(mim(), ejabberd_auth, try_register, [mongoose_helper:make_jid(AdminU, AdminS), AdminP]),
Expand Down
2 changes: 1 addition & 1 deletion big_tests/tests/domain_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ secondary_host_type(NodeKey) ->
get_or_fail({hosts, NodeKey, secondary_host_type}).

make_metrics_prefix(HostType) ->
rpc(mim(), mongoose_metrics, make_host_type_name, [HostType]).
metrics_helper:make_host_type_name(HostType).

insert_configured_domains() ->
for_each_configured_domain(fun insert_persistent_domain/3).
Expand Down
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 @@ -419,7 +419,7 @@ connect_and_disconnect(Spec) ->
escalus_connection:stop(Client).

does_cached_user_exist(Config, User) ->
Jid = #jid{server = Domain} = jid:from_binary(escalus_users:get_jid(Config, User)),
Jid = #jid{lserver = Domain} = jid:from_binary(escalus_users:get_jid(Config, User)),
HostType = domain_to_host_type(mim(), Domain),
rpc(mim(), mod_cache_users, does_cached_user_exist, [false, HostType, Jid, stored]).

Expand Down
7 changes: 4 additions & 3 deletions big_tests/tests/domain_rest_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ listener_opts(Params) ->
transport => config([listen, http, transport], #{num_acceptors => 10})}).

domain_handler(Params) ->
{"localhost", "/api", mongoose_domain_handler, handler_opts(Params)}.
maps:merge(#{host => "localhost", path => "/api", module => mongoose_domain_handler},
handler_opts(Params)).

handler_opts(#{skip_auth := true}) ->
[];
#{};
handler_opts(_Params) ->
[{password, <<"secret">>}, {username, <<"admin">>}].
#{password => <<"secret">>, username => <<"admin">>}.
25 changes: 8 additions & 17 deletions big_tests/tests/graphql_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ execute(EpName, Body, Creds) ->

execute_auth(Body, Config) ->
Ep = ?config(schema_endpoint, Config),
Opts = get_listener_opts(Ep),
User = proplists:get_value(username, Opts),
Password = proplists:get_value(password, Opts),
execute(Ep, Body, {User, Password}).
#{username := Username, password := Password} = get_listener_opts(Ep),
execute(Ep, Body, {Username, Password}).

execute_domain_auth(Body, Config) ->
Ep = ?config(schema_endpoint, Config),
Expand All @@ -56,7 +54,7 @@ get_listener_config(EpName) ->
init_admin_handler(Config) ->
Endpoint = admin,
Opts = get_listener_opts(Endpoint),
case proplists:is_defined(username, Opts) of
case maps:is_key(username, Opts) of
true ->
[{schema_endpoint, Endpoint}, {listener_opts, Opts} | Config];
false ->
Expand All @@ -76,15 +74,8 @@ end_domain_admin_handler(Config) ->
domain_helper:delete_domain_password(mim(), Domain).

get_listener_opts(EpName) ->
#{handlers := Handlers} = get_listener_config(EpName),
[Opts2] = lists:filtermap(
fun
({_, _Path, mongoose_graphql_cowboy_handler, Args}) ->
{true, Args};
(_) ->
false
end, Handlers),
Opts2.
#{handlers := [Opts]} = get_listener_config(EpName),
Opts.

-spec get_err_msg(#{errors := [#{message := binary()}]}) -> binary().
get_err_msg(Resp) ->
Expand Down Expand Up @@ -128,9 +119,9 @@ get_value([Field | Fields], Data) ->
Data2 = maps:get(BinField, Data),
get_value(Fields, Data2).

is_graphql_config(#{handlers := Handlers}, EpName) ->
lists:any(fun({_, _Path, mongoose_graphql_cowboy_handler, Args}) ->
atom_to_binary(EpName) == proplists:get_value(schema_endpoint, Args);
is_graphql_config(#{module := ejabberd_cowboy, handlers := Handlers}, EpName) ->
lists:any(fun(#{module := mongoose_graphql_cowboy_handler, schema_endpoint := EpBin}) ->
atom_to_binary(EpName) =:= EpBin;
(_) -> false
end, Handlers);
is_graphql_config(_, _EpName) ->
Expand Down
8 changes: 4 additions & 4 deletions big_tests/tests/graphql_muc_light_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ user_create_room_story(Config, Alice) ->
Res = execute(Ep, user_create_room_body(MucServer, Name, Subject, null), Creds),
#{<<"jid">> := JID, <<"name">> := Name, <<"subject">> := Subject,
<<"participants">> := Participants} = get_ok_value(?CREATE_ROOM_PATH, Res),
?assertMatch(#jid{server = MucServer}, jid:from_binary(JID)),
?assertMatch(#jid{lserver = MucServer}, jid:from_binary(JID)),
?assertEqual([#{<<"jid">> => AliceBinLower, <<"affiliation">> => <<"OWNER">>}], Participants),
% Try with a non-existent domain
Res2 = execute(Ep, user_create_room_body(?UNKNOWN_DOMAIN, Name, Subject, null), Creds),
Expand All @@ -149,7 +149,7 @@ user_create_identified_room_story(Config, Alice) ->
Res = execute(Ep, user_create_room_body(MucServer, Name, Subject, Id), Creds),
#{<<"jid">> := JID, <<"name">> := Name, <<"subject">> := Subject} =
get_ok_value(?CREATE_ROOM_PATH, Res),
?assertMatch(#jid{user = Id, server = MucServer}, jid:from_binary(JID)),
?assertMatch(#jid{luser = Id, lserver = MucServer}, jid:from_binary(JID)),
% Create a room with an existing ID
Res2 = execute(Ep, user_create_room_body(MucServer, <<"snd room">>, Subject, Id), Creds),
?assertNotEqual(nomatch, binary:match(get_err_msg(Res2), <<"already exists">>)),
Expand Down Expand Up @@ -568,7 +568,7 @@ admin_create_room_story(Config, Alice) ->
Res = execute_auth(admin_create_room_body(MucServer, Name, AliceBin, Subject, null), Config),
#{<<"jid">> := JID, <<"name">> := Name, <<"subject">> := Subject,
<<"participants">> := Participants} = get_ok_value(?CREATE_ROOM_PATH, Res),
?assertMatch(#jid{server = MucServer}, jid:from_binary(JID)),
?assertMatch(#jid{lserver = MucServer}, jid:from_binary(JID)),
?assertEqual([#{<<"jid">> => AliceBinLower, <<"affiliation">> => <<"OWNER">>}], Participants),
% Try with a non-existent domain
Res2 = execute_auth(admin_create_room_body(?UNKNOWN_DOMAIN, Name, AliceBin, Subject, null),
Expand All @@ -587,7 +587,7 @@ admin_create_identified_room_story(Config, Alice) ->
Res = execute_auth(admin_create_room_body(MucServer, Name, AliceBin, Subject, Id), Config),
#{<<"jid">> := JID, <<"name">> := Name, <<"subject">> := Subject} =
get_ok_value(?CREATE_ROOM_PATH, Res),
?assertMatch(#jid{user = Id, server = MucServer}, jid:from_binary(JID)),
?assertMatch(#jid{luser = Id, lserver = MucServer}, jid:from_binary(JID)),
% Create a room with an existing ID
Res2 = execute_auth(admin_create_room_body(MucServer, <<"snd room">>, AliceBin, Subject, Id),
Config),
Expand Down
3 changes: 2 additions & 1 deletion big_tests/tests/graphql_stanza_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,15 @@ admin_send_stanza_from_unknown_user_story(Config, Bob) ->
Body = <<"Hi!">>,
Server = escalus_client:server(Bob),
From = <<"YeeeAH@", Server/binary>>,
LFrom = jid:str_tolower(From),
Stanza = escalus_stanza:from(escalus_stanza:chat_to_short_jid(Bob, Body), From),
Vars = #{stanza => exml:to_binary(Stanza)},
Res = execute_send_stanza(Vars, Config),
{{<<"200">>,<<"OK">>},
#{<<"data">> := #{<<"stanza">> := #{<<"sendStanza">> := null}},
<<"errors">> := Errors}} = Res,
[#{<<"extensions">> := #{<<"code">> := <<"unknown_user">>,
<<"jid">> := From},
<<"jid">> := LFrom},
<<"message">> := ErrMsg, <<"path">> := ErrPath}] = Errors,
?assertEqual(<<"Given user does not exist">>, ErrMsg),
?assertEqual([<<"stanza">>, <<"sendStanza">>], ErrPath).
Expand Down
2 changes: 1 addition & 1 deletion big_tests/tests/inbox_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1397,7 +1397,7 @@ rpc_stop_hook_handler(HookExtra, HostType) ->
hook_handler_fn(Acc,
#{args := [_HostType, User, _Stored]} = _Params,
#{test_case_pid := Pid} = _Extra) ->
Pid ! {input, User#jid.user},
Pid ! {input, User#jid.luser},
{ok, Acc}.

verify_hook_listener(RoomName) ->
Expand Down
9 changes: 4 additions & 5 deletions big_tests/tests/mongooseimctl_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,7 @@ remove_old_messages_test(Config) ->
OldTimestamp = fallback_timestamp(10, os:system_time(microsecond)),
OfflineOld = generate_offline_message(JidRecordAlice, JidRecordBob, Msg1, OldTimestamp),
OfflineNew = generate_offline_message(JidRecordAlice, JidRecordBob, Msg2, os:system_time(microsecond)),
{jid, _, _, _, LUser, LServer, _} = JidRecordBob,
{LUser, LServer} = jid:to_lus(JidRecordBob),
HostType = host_type(),
rpc_call(mod_offline_backend, write_messages, [host_type(), LUser, LServer, [OfflineOld, OfflineNew]]),
%% when
Expand Down Expand Up @@ -1300,7 +1300,7 @@ remove_expired_messages_test(Config) ->
JidRecordKate, Msg4,
OldTimestamp,
ExpirationTimeFuture),
{jid, _, _, _, LUser, LServer, _} = JidRecordKate,
{LUser, LServer} = jid:to_lus(JidRecordKate),
Args = [OfflineOld, OfflineNow, OfflineFuture, OfflineFuture2],
HostType = host_type(),
rpc_call(mod_offline_backend, write_messages, [HostType, LUser, LServer, Args]),
Expand All @@ -1321,12 +1321,12 @@ nick_to_jid(UserName, Config) when is_atom(UserName) ->
escalus_utils:jid_to_lower(escalus_users:get_jid(Config, UserSpec)).

generate_offline_message(From, To, Msg, TimeStamp) ->
{jid, _, _, _, LUser, LServer, _} = To,
{LUser, LServer} = jid:to_lus(To),
#offline_msg{us = {LUser, LServer}, timestamp = TimeStamp, expire = never,
from = From, to = To, packet = Msg}.

generate_offline_expired_message(From, To, Msg, TimeStamp, ExpirationTime) ->
{jid, _, _, _, LUser, LServer, _} = To,
{LUser, LServer} = jid:to_lus(To),
#offline_msg{us = {LUser, LServer}, timestamp = TimeStamp,
expire = ExpirationTime, from = From, to = To, packet = Msg}.

Expand Down Expand Up @@ -1367,7 +1367,6 @@ delete_users(_Config) ->

match_user_status(Users, StatusTxt) ->
Statuses = string:tokens(StatusTxt, "\n"),

true = (length(Users) == length(Statuses)),
match_user_status2(Users, Statuses).

Expand Down
4 changes: 2 additions & 2 deletions big_tests/tests/muc_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ generate_rpc_jid({_,User}) ->
{server, Server} = lists:keyfind(server, 1, User),
LUsername = escalus_utils:jid_to_lower(Username),
LServer = escalus_utils:jid_to_lower(Server),
{jid, Username, Server, <<"rpc">>, LUsername, LServer, <<"rpc">>}.
jid:make_noprep(LUsername, LServer, <<"rpc">>).

create_instant_room(Room, From, Nick, Opts) ->
ServerHost = ct:get_config({hosts, mim, domain}),
Expand All @@ -170,7 +170,7 @@ destroy_room(Config) ->
destroy_room(muc_host(), ?config(room, Config)).

destroy_room(Host, Room) when is_binary(Host), is_binary(Room) ->
Room1 = rpc(mim(), jid, nodeprep, [Room]),
Room1 = jid:nodeprep(Room),
case rpc(mim(), ets, lookup, [muc_online_room, {Room1, Host}]) of
[{_,_,Pid}|_] ->
%% @TODO related to gen_fsm_compat: after migration to gen_statem
Expand Down
7 changes: 3 additions & 4 deletions big_tests/tests/oauth_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ token_login_failure(Config, User, Token) ->

get_revoked_token(Config, UserName) ->
BJID = escalus_users:get_jid(Config, UserName),
JID = rpc(mim(), jid, from_binary, [BJID]),
JID = jid:from_binary(BJID),
HostType = domain_helper:host_type(),
Token = rpc(mim(), mod_auth_token, token, [HostType, JID, refresh]),
ValidSeqNo = rpc(mim(), mod_auth_token_rdbms, get_valid_sequence_number, [HostType, JID]),
Expand Down Expand Up @@ -280,7 +280,7 @@ token_revocation_test(Config) ->
get_owner_seqno_to_revoke(Config, User) ->
{_, RefreshToken} = request_tokens_once_logged_in_impl(Config, User),
[_, BOwner, _, SeqNo, _] = binary:split(RefreshToken, <<0>>, [global]),
Owner = rpc(mim(), jid, from_binary, [BOwner]),
Owner = jid:from_binary(BOwner),
{Owner, binary_to_integer(SeqNo), RefreshToken}.

revoke_token(Owner) ->
Expand Down Expand Up @@ -433,8 +433,7 @@ make_provision_token(Config, User, VCard) ->
ExpiryFarInTheFuture = {{2055, 10, 27}, {10, 54, 22}},
Username = escalus_users:get_username(Config, User),
Domain = escalus_users:get_server(Config, User),
ServerSideJID = {jid, Username, Domain, <<>>,
Username, Domain, <<>>},
ServerSideJID = jid:make(Username, Domain, <<>>),
T0 = {token, provision,
ExpiryFarInTheFuture,
ServerSideJID,
Expand Down
16 changes: 16 additions & 0 deletions big_tests/tests/rdbms_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ rdbms_queries_cases() ->
insert_batch_with_null_case,
test_cast_insert,
test_request_insert,
test_request_transaction,
test_incremental_upsert,
arguments_from_two_tables].

Expand Down Expand Up @@ -374,6 +375,18 @@ test_request_insert(Config) ->
selected_to_sorted(SelectResult))
end, ok, #{name => request_queries}).

test_request_transaction(Config) ->
erase_table(Config),
Queries = [<<"INSERT INTO test_types(unicode) VALUES ('check1')">>,
<<"INSERT INTO test_types(unicode) VALUES ('check2')">>],
sql_transaction_request(Config, Queries),
mongoose_helper:wait_until(
fun() ->
SelectResult = sql_query(Config, "SELECT unicode FROM test_types"),
?assertEqual({selected, [{<<"check1">>}, {<<"check2">>}]},
selected_to_sorted(SelectResult))
end, ok, #{name => request_queries}).

test_incremental_upsert(Config) ->
case is_odbc() of
true ->
Expand Down Expand Up @@ -438,6 +451,9 @@ sql_execute_upsert(_Config, Name, Insert, Update, Unique) ->
sql_query_request(_Config, Query) ->
slow_rpc(mongoose_rdbms, sql_query_request, [host_type(), Query]).

sql_transaction_request(_Config, Query) ->
slow_rpc(mongoose_rdbms, sql_transaction_request, [host_type(), Query]).

escape_null(_Config) ->
escalus_ejabberd:rpc(mongoose_rdbms, escape_null, []).

Expand Down
Loading

0 comments on commit bfc1ee0

Please sign in to comment.