Skip to content

Commit 219a715

Browse files
Fix test case for multi-oauth with proxy
1 parent 660fc4f commit 219a715

File tree

7 files changed

+29
-28
lines changed

7 files changed

+29
-28
lines changed

deps/oauth2_client/src/oauth2_client.erl

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ ensure_http_client_started(Id, ProxyOptions) ->
6262
root -> root;
6363
_ -> binary_to_atom(Id)
6464
end,
65-
rabbit_log:debug("Starting http client ~p", [Profile]),
65+
rabbit_log:debug("Starting http client ~p ...", [Profile]),
6666
case inets:start(httpc, [{profile, Profile}]) of
67-
ok ->
67+
{ok, _} ->
6868
HttpProxyOptions = map_proxy_to_httpc_option(ProxyOptions),
6969
case ensure_http_proxy_options_if_any(Profile, HttpProxyOptions) of
7070
ok -> {ok, Profile};
@@ -73,23 +73,21 @@ ensure_http_client_started(Id, ProxyOptions) ->
7373
{error, {already_started, _}} ->
7474
rabbit_log:debug("Already started http client ~p", [Profile]),
7575
{ok, Profile};
76-
Error -> Error
76+
Error ->
77+
rabbit_log:error("Failed to start httpc client: ~p", [Error]),
78+
Error
7779
end.
7880
ensure_http_proxy_options_if_any(_Profile, []) ->
7981
ok;
80-
ensure_http_proxy_options_if_any(Profile, HttpProxyOptions) ->
81-
case httpc:get_options([proxy]) of
82-
{ok, _} -> ok;
83-
{error, _} ->
84-
rabbit_log:debug("Setting Proxy options to http client ~p", [Profile]),
85-
case httpc:set_options(HttpProxyOptions, Profile) of
86-
ok ->
87-
rabbit_log:debug("SetOptions ~p on http client ~p",
88-
[HttpProxyOptions, Profile]),
89-
ok;
90-
{error, _} = Error -> Error
91-
end
82+
ensure_http_proxy_options_if_any(Profile, HttpProxyOptions) ->
83+
case httpc:set_options(HttpProxyOptions, Profile) of
84+
ok ->
85+
rabbit_log:debug("Successfully set_options ~p on http client ~p",
86+
[HttpProxyOptions, Profile]),
87+
ok;
88+
{error, _} = Error -> Error
9289
end.
90+
9391
http_post(Id, URL, Header, Type, Body, HTTPOptions, ProxyOptions) ->
9492
http_request(Id, post, {URL, Header, Type, Body}, HTTPOptions, ProxyOptions).
9593
http_get(Id, URL, HTTPOptions, ProxyOptions) ->
@@ -470,33 +468,33 @@ lookup_root_oauth_provider() ->
470468
authorization_endpoint = get_env(authorization_endpoint),
471469
end_session_endpoint = get_env(end_session_endpoint),
472470
ssl_options = extract_ssl_options_as_list(Map),
473-
proxy_options = extract_proxy_options(Map)
471+
proxy_options = extract_proxy_options(get_env(proxy, []))
474472
}.
475473

476474
-spec extract_proxy_options(#{atom() => any()}|list()) -> proxy_options() | undefined.
477475
extract_proxy_options(List) when is_list(List) ->
478-
case {proplists:get_value(proxy_host, List, undefined),
479-
proplists:get_value(proxy_port, List, 0)} of
476+
case {proplists:get_value(host, List, undefined),
477+
proplists:get_value(port, List, 0)} of
480478
{undefined, _} -> undefined;
481479
{_, 0} -> undefined;
482480
{H, P} ->
483481
#proxy_options{
484482
host = H,
485483
port = P,
486-
username = proplists:get_value(proxy_username, List, undefined),
487-
password = proplists:get_value(proxy_password, List, undefined)
484+
username = proplists:get_value(username, List, undefined),
485+
password = proplists:get_value(password, List, undefined)
488486
}
489487
end;
490488
extract_proxy_options(Map) ->
491-
case {maps:get(proxy_host, Map, undefined), maps:get(proxy_port, Map, 0)} of
489+
case {maps:get(host, Map, undefined), maps:get(port, Map, 0)} of
492490
{undefined, _} -> undefined;
493491
{_, 0} -> undefined;
494492
{H, P} ->
495493
#proxy_options{
496494
host = H,
497495
port = P,
498-
username = maps:get(proxy_username, Map, undefined),
499-
password = maps:get(proxy_password, Map, undefined)
496+
username = maps:get(username, Map, undefined),
497+
password = maps:get(password, Map, undefined)
500498
}
501499
end.
502500

@@ -713,7 +711,7 @@ map_to_oauth_provider(PropList) when is_list(PropList) ->
713711
extract_ssl_options_as_list(maps:from_list(
714712
proplists:get_value(https, PropList, []))),
715713
proxy_options =
716-
extract_proxy_options(PropList)
714+
extract_proxy_options(proplists:get_value(proxy, PropList, []))
717715
}.
718716
map_to_access_token_response(Code, Reason, Headers, Body) ->
719717
case decode_body(proplists:get_value("content-type", Headers, ?CONTENT_JSON), Body) of

selenium/bin/components/devkeycloak-proxy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ start_devkeycloak-proxy() {
4141
${HTTPD_DOCKER_IMAGE}
4242

4343
#wait_for_url $OAUTH_PROVIDER_URL ${FORWARD_PROXY_URL}
44+
wait_for_message devkeycloak-proxy "initializing worker proxy:forward local"
4445
end "devkeycloak-proxy is ready"
4546
}

selenium/bin/components/forward-proxy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@ start_forward-proxy() {
4242
${HTTPD_DOCKER_IMAGE}
4343

4444
#wait_for_url $OAUTH_PROVIDER_URL ${FORWARD_PROXY_URL}
45+
wait_for_message forward-proxy "initializing worker proxy:forward local"
4546
end "forward-proxy is ready"
4647
}

selenium/bin/components/prodkeycloak-proxy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ start_prodkeycloak-proxy() {
3636
--detach \
3737
--name prodkeycloak-proxy \
3838
--net ${DOCKER_NETWORK} \
39-
--publish 9091:9092 \
39+
--publish 9091:9091 \
4040
--mount "type=bind,source=${MOUNT_HTTPD_CONFIG_DIR},target=/usr/local/apache2/conf" \
4141
${HTTPD_DOCKER_IMAGE}
4242

43+
wait_for_message prodkeycloak-proxy "initializing worker proxy:forward local"
4344
end "prodkeycloak-proxy is ready"
4445
}

selenium/test/multi-oauth/devkeycloak-proxy/httpd.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ LogLevel warn
131131

132132

133133
<VirtualHost *:9092>
134-
AllowCONNECT 8443
134+
AllowCONNECT 8442
135135

136136
ProxyRequests On
137137
ProxyVia On
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export PRODKEYCLOAK_PROXY_HOST=prodkeycloak-proxy
2-
export PRODKEYCLOAK_PROXY_PORT=9092
2+
export PRODKEYCLOAK_PROXY_PORT=9091
33
export PRODKEYCLOAK_PROXY_USERNAME=guest
44
export PRODKEYCLOAK_PROXY_PASSWORD=guest

selenium/test/multi-oauth/prodkeycloak-proxy/httpd.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ LogLevel warn
130130
</IfModule>
131131

132132

133-
<VirtualHost *:9092>
133+
<VirtualHost *:9091>
134134
AllowCONNECT 8443
135135

136136
ProxyRequests On

0 commit comments

Comments
 (0)