Skip to content

Commit

Permalink
Merge pull request #3872 from esl/mu-fix-cassandra-auth-cfg
Browse files Browse the repository at this point in the history
Fix cassandra auth parameters parsing
  • Loading branch information
Kamil Wąż authored Nov 30, 2022
2 parents fe6f638 + efa2c8e commit 65be9ea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/wpool/mongoose_wpool_cassandra.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
-export([start/4]).
-export([stop/2]).

-ifdef(TEST).
-export([prepare_cqerl_opts/1]).
-endif.

%% --------------------------------------------------------------
%% mongoose_wpool callbacks
-spec init() -> ok.
Expand Down Expand Up @@ -50,7 +54,7 @@ prepare_cqerl_opts(ConnOpts) ->
cqerl_opts(keyspace, #{keyspace := Keyspace}) ->
[{keyspace, Keyspace}];
cqerl_opts(auth, #{auth := #{plain := #{username := UserName, password := Password}}}) ->
[{cqerl_auth_plain_handler, [{UserName, Password}]}];
[{auth, {cqerl_auth_plain_handler, [{UserName, Password}]}}];
cqerl_opts(tcp, #{}) ->
[{tcp_opts, [{keepalive, true}]}]; % always set
cqerl_opts(tls, #{tls := TLSOpts}) ->
Expand Down
10 changes: 9 additions & 1 deletion test/mongoose_wpool_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ all() ->
dead_pool_is_restarted,
dead_pool_is_stopped_before_restarted,
riak_pool_cant_be_started_with_available_worker_strategy,
redis_pool_cant_be_started_with_available_worker_strategy
redis_pool_cant_be_started_with_available_worker_strategy,
cassandra_prepare_opts
].

%%--------------------------------------------------------------------
Expand Down Expand Up @@ -269,6 +270,13 @@ pool_cant_be_started_with_available_worker_strategy(Type) ->
?assertError({strategy_not_supported, Type, Host, Tag, available_worker},
mongoose_wpool:start_configured_pools(PoolDef)).

cassandra_prepare_opts(_Config) ->
%% Check that we pass auth options in the correct format to the Cassandra driver
AuthCfg = #{auth => #{plain => #{username => <<"user">>, password => <<"password">>}}},
?assertEqual([{auth, {cqerl_auth_plain_handler, [{<<"user">>, <<"password">>}]}},
{tcp_opts, [{keepalive, true}]}],
mongoose_wpool_cassandra:prepare_cqerl_opts(AuthCfg)).

%%--------------------------------------------------------------------
%% Helpers
%%--------------------------------------------------------------------
Expand Down

0 comments on commit 65be9ea

Please sign in to comment.