Skip to content

Commit d956635

Browse files
Fix tests
update_secret will always return ok even though it is not. That is because it sends ok to all the channels. And then it sends an error to the connection.
1 parent 874caa9 commit d956635

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

deps/rabbitmq_auth_backend_oauth2/src/rabbit_auth_backend_oauth2.erl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ check_topic_access(#auth_user{impl = DecodedTokenFun},
110110
end).
111111

112112
update_state(AuthUser, NewToken) ->
113-
?LOG_DEBUG("Calling (update_state)"),
114-
115113
TokenResult = case oauth2_client:is_jwt_token(NewToken) of
116114
true -> {ok, NewToken};
117115
false ->
@@ -124,7 +122,6 @@ update_state(AuthUser, NewToken) ->
124122
{error, Err1}
125123
end
126124
end,
127-
?LOG_DEBUG("Calling (update_state) tokenResult: ~p", [TokenResult]),
128125
case TokenResult of
129126
{ok, Token} ->
130127
case resolve_resource_server(Token) of

deps/rabbitmq_auth_backend_oauth2/test/system_SUITE.erl

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ groups() ->
8888
{with_introspection_endpoint, [], [
8989
test_successful_connection_with_valid_opaque_token,
9090
test_unsuccessful_connection_with_invalid_opaque_token,
91-
test_successful_opaque_token_refresh
92-
%test_successful_opaque_token_refresh_with_more_restrictive_token,
93-
%test_unsuccessful_opaque_token_refresh_with_inactive_token
91+
test_successful_opaque_token_refresh,
92+
test_successful_opaque_token_refresh_with_more_restrictive_token,
93+
test_unsuccessful_opaque_token_refresh_with_inactive_token
9494
]}
9595
].
9696

@@ -573,11 +573,12 @@ test_unsuccessful_opaque_token_refresh_with_inactive_token(Config) ->
573573
#'queue.declare_ok'{queue = _} =
574574
amqp_channel:call(Ch, #'queue.declare'{exclusive = true}),
575575

576-
Result = amqp_connection:update_secret(Conn, <<"inactive">>, <<"token refresh">>),
577-
ct:log("Result: ~p", [Result]),
578-
579-
?assertException(exit, {{nodedown,not_allowed},_}, Result).
576+
amqp_connection:update_secret(Conn, <<"inactive">>, <<"token refresh">>),
577+
578+
?assertExit({{shutdown, {connection_closing, {server_initiated_close, 530, _}}}, _},
579+
amqp_connection:open_channel(Conn)),
580580

581+
catch close_connection(Conn).
581582

582583

583584
mqtt(Config) ->
@@ -1087,12 +1088,17 @@ test_failed_token_refresh_case1(Config) ->
10871088
catch close_connection(Conn).
10881089

10891090
refreshed_token_cannot_change_username(Config) ->
1090-
{_, Token} = generate_valid_token_with_sub(Config, <<"username">>),
1091-
Conn = open_unmanaged_connection(Config, 0, <<"vhost4">>, <<"username">>, Token),
1091+
{_, Token} = generate_valid_token_with_sub(Config, <<"username3">>),
1092+
Conn = open_unmanaged_connection(Config, 0, <<"vhost1">>, <<"username3">>, Token),
10921093
{_, RefreshedToken} = generate_valid_token_with_sub(Config, <<"username2">>),
10931094

10941095
%% the error is communicated asynchronously via a connection-level error
1095-
?assertException(exit, {{nodedown,not_allowed},_}, amqp_connection:update_secret(Conn, RefreshedToken, <<"token refresh">>)).
1096+
amqp_connection:update_secret(Conn, RefreshedToken, <<"should fail token refresh">>),
1097+
1098+
?assertExit({{shutdown, {connection_closing, {server_initiated_close, 530, _}}}, _},
1099+
amqp_connection:open_channel(Conn)),
1100+
1101+
catch close_connection(Conn).
10961102

10971103

10981104
test_failed_token_refresh_case2(Config) ->

0 commit comments

Comments
 (0)