Skip to content

Commit 0a73922

Browse files
Test oauth_bootstrap.js with/out jwt/opaque token
1 parent 77184c2 commit 0a73922

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

deps/oauth2_client/src/oauth2_client.erl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,9 @@ get_env(Par, Def) ->
917917
set_env(Par, Val) ->
918918
application:set_env(rabbitmq_auth_backend_oauth2, Par, Val).
919919

920-
-spec is_jwt_token(binary() | map()) -> boolean().
920+
-spec is_jwt_token(list() | binary() | map()) -> boolean().
921+
is_jwt_token(Token) when is_list(Token) ->
922+
is_jwt_token(list_to_binary(Token));
921923
is_jwt_token(Token) when is_binary(Token) ->
922924
case binary:split(Token, <<".">>, [global]) of
923925
[_, _, _] -> true;

deps/rabbitmq_management/test/rabbit_mgmt_wm_auth_SUITE.erl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,14 @@ introspect_opaque_token_returns_401_from_auth_server(Config) ->
10301030
oauth_bootstrap_with_jwt_token_in_header(Config) ->
10311031
URI = rabbit_mgmt_test_util:uri_base_from(Config, 0, "") ++ "js/oidc-oauth/bootstrap.js",
10321032
Result = httpc:request(get, {URI, [{"Authorization", "bearer active"}]}, [], []),
1033-
ct:log("response idp: ~p ~p", [URI, Result]).
1033+
{ok, {{_HTTP, 200, _}, _Headers, ResBody}} = Result,
1034+
ct:log("resbody: ~p", [ResBody]),
1035+
case string:find(ResBody,"set_token_auth(") of
1036+
nomatch -> ct:fail("expected setting token");
1037+
Reminder ->
1038+
{match, [Token | _]} = re:run(Reminder, "'([^']*)'", [{capture, [1], list}]),
1039+
?assertEqual(true, oauth2_client:is_jwt_token(Token))
1040+
end.
10341041

10351042
oauth_bootstrap_with_jwt_token_in_cookie(Config) ->
10361043
URI = rabbit_mgmt_test_util:uri_base_from(Config, 0, "") ++ "js/oidc-oauth/bootstrap.js",
@@ -1044,13 +1051,16 @@ oauth_bootstrap_with_opaque_token_in_cookie(Config) ->
10441051

10451052
oauth_bootstrap_cannot_introspect_opaque_token(Config) ->
10461053
URI = rabbit_mgmt_test_util:uri_base_from(Config, 0, "") ++ "js/oidc-oauth/bootstrap.js",
1047-
Result = httpc:request(get, {URI, [{"Authorization", "bearer active"}]}, [], []),
1048-
ct:log("response idp: ~p ~p", [URI, Result]).
1054+
{ok, {{_HTTP, 401, _}, _Headers, _ResBody}} =
1055+
httpc:request(get, {URI, [{"Authorization", "bearer inactive"}]}, [], []).
10491056

10501057
oauth_bootstrap_without_any_token(Config) ->
10511058
URI = rabbit_mgmt_test_util:uri_base_from(Config, 0, "") ++ "js/oidc-oauth/bootstrap.js",
1052-
Result = httpc:request(get, {URI, [{"Authorization", "bearer active"}]}, [], []),
1053-
ct:log("response idp: ~p ~p", [URI, Result]).
1059+
{ok, {{_HTTP, 200, _}, _Headers, ResBody}} = httpc:request(get, {URI, []}, [], []),
1060+
case string:find(ResBody,"set_token_auth(") of
1061+
nomatch -> ok;
1062+
Reminder -> ct:fail("expected no set_token_auth call")
1063+
end.
10541064

10551065

10561066
%% -------------------------------------------------------------------

0 commit comments

Comments
 (0)