Skip to content

Commit 6aaff09

Browse files
MarcialRosalesmichaelklishin
authored andcommitted
Set up cacertfile when it is set
1 parent 2b30bf8 commit 6aaff09

File tree

5 files changed

+80
-15
lines changed

5 files changed

+80
-15
lines changed

deps/oauth2_client/BUILD.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,10 @@ rabbitmq_integration_suite(
125125
],
126126
)
127127

128+
129+
rabbitmq_suite(
130+
name = "unit_SUITE",
131+
size = "small",
132+
)
133+
128134
assert_suites()

deps/oauth2_client/app.bzl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,12 @@ def test_suite_beam_files(name = "test_suite_beam_files"):
8181
app_name = "oauth2_client",
8282
erlc_opts = "//:test_erlc_opts",
8383
)
84+
erlang_bytecode(
85+
name = "unit_SUITE_beam_files",
86+
testonly = True,
87+
srcs = ["test/unit_SUITE.erl"],
88+
outs = ["test/unit_SUITE.beam"],
89+
hdrs = ["include/oauth2_client.hrl"],
90+
app_name = "oauth2_client",
91+
erlc_opts = "//:test_erlc_opts",
92+
)

deps/oauth2_client/src/oauth2_client.erl

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
-module(oauth2_client).
88
-export([get_access_token/2,
99
refresh_access_token/2,
10-
get_oauth_provider/1,get_oauth_provider/2
10+
get_oauth_provider/1,get_oauth_provider/2,
11+
extract_ssl_options_as_list/1
1112
]).
1213

1314
-include("oauth2_client.hrl").
@@ -270,31 +271,46 @@ lookup_oauth_provider_from_keyconfig() ->
270271

271272
-spec extract_ssl_options_as_list(#{atom() => any()}) -> proplists:proplist().
272273
extract_ssl_options_as_list(Map) ->
273-
Verify = case maps:get(peer_verification, Map, verify_peer) of
274+
{Verify, CaCerts, CaCertFile} = case maps:get(peer_verification, Map, verify_peer) of
274275
verify_peer ->
275276
case maps:get(cacertfile, Map, undefined) of
276277
undefined ->
277278
case public_key:cacerts_get() of
278-
[] -> verify_none;
279-
_ -> verify_peer
279+
[] -> {verify_none, undefined, undefined};
280+
Certs -> {verify_peer, Certs, undefined}
280281
end;
281-
_ -> verify_peer
282+
CaCert -> {verify_peer, undefined, CaCert}
282283
end;
283-
verify_none -> verify_none
284+
verify_none -> {verify_none, undefined, undefined}
284285
end,
285286

286-
[ {verify, Verify},
287-
{cacertfile, maps:get(cacertfile, Map, "")},
288-
{depth, maps:get(depth, Map, 10)},
289-
{crl_check, maps:get(crl_check, Map, false)},
290-
{fail_if_no_peer_cert, maps:get(fail_if_no_peer_cert, Map, false)}
291-
] ++
292-
case maps:get(hostname_verification, Map, none) of
287+
[ {verify, Verify} ]
288+
++
289+
case Verify of
290+
verify_none -> [];
291+
_ ->
292+
[
293+
{depth, maps:get(depth, Map, 10)},
294+
{crl_check, maps:get(crl_check, Map, false)},
295+
{fail_if_no_peer_cert, maps:get(fail_if_no_peer_cert, Map, false)}
296+
]
297+
end
298+
++
299+
case Verify of
300+
verify_none -> [];
301+
_ ->
302+
case {CaCerts, CaCertFile} of
303+
{_, undefined} -> [{cacerts, CaCerts}];
304+
{undefined, _} -> [{cacertfile, CaCertFile}]
305+
end
306+
end
307+
++
308+
case maps:get(hostname_verification, Map, none) of
293309
wildcard ->
294310
[{customize_hostname_check, [{match_fun, public_key:pkix_verify_hostname_match_fun(https)}]}];
295311
none ->
296312
[]
297-
end.
313+
end.
298314

299315
lookup_oauth_provider_config(OAuth2ProviderId) ->
300316
case application:get_env(rabbitmq_auth_backend_oauth2, oauth_providers) of

deps/oauth2_client/test/system_SUITE.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ groups() ->
177177
ssl_connection_error,
178178
{group, with_all_oauth_provider_settings},
179179
{group, without_all_oauth_providers_settings}
180-
]}
180+
]}
181181
].
182182

183183
init_per_suite(Config) ->
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
%% This Source Code Form is subject to the terms of the Mozilla Public
2+
%% License, v. 2.0. If a copy of the MPL was not distributed with this
3+
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
%%
5+
%% Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
6+
%%
7+
8+
-module(unit_SUITE).
9+
10+
-include_lib("common_test/include/ct.hrl").
11+
-include_lib("eunit/include/eunit.hrl").
12+
13+
-include_lib("oauth2_client.hrl").
14+
15+
-compile(export_all).
16+
17+
18+
all() ->
19+
[
20+
{group, ssl_options}
21+
].
22+
23+
groups() ->
24+
[
25+
{ssl_options, [], [
26+
no_ssl_options_set
27+
]}
28+
].
29+
30+
no_ssl_options_set(_) ->
31+
Map = #{ },
32+
?assertEqual([
33+
{verify, verify_none}
34+
], oauth2_client:extract_ssl_options_as_list(Map)).

0 commit comments

Comments
 (0)