Skip to content

Commit e8ca661

Browse files
Add negative system tests for refresh opaque token
1 parent 256dba4 commit e8ca661

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed

deps/rabbitmq_auth_backend_oauth2/test/introspect_http_handler.erl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ init(Req, State) ->
1818
{"scope", <<"rabbitmq.configure:*/* rabbitmq.write:*/* rabbitmq.read:*/*">>}]),
1919
{ok, cowboy_req:reply(200, #{<<"content-type">> => <<"application/json">>},
2020
Body, Req), State};
21+
<<"active-2">> ->
22+
Body = rabbit_json:encode([
23+
{"active", true},
24+
{"aud", <<"rabbitmq">>},
25+
{"scope", <<"rabbitmq.write:*/* rabbitmq.read:*/*">>}]),
26+
{ok, cowboy_req:reply(200, #{<<"content-type">> => <<"application/json">>},
27+
Body, Req), State};
2128
<<"inactive">> ->
2229
Body = rabbit_json:encode([
2330
{"active", false},

deps/rabbitmq_auth_backend_oauth2/test/rabbit_oauth2_provider_SUITE.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ start_https_oauth_server(Port, CertsDir, Expectations) when is_list(Expectations
479479
{'_', [{Path, oauth2_http_mock, Expected} ||
480480
#{request := #{path := Path}} = Expected <- Expectations ]}
481481
]),
482-
{ok, Pid} = cowboy:start_tls(
482+
{ok, _Pid} = cowboy:start_tls(
483483
mock_http_auth_listener,
484484
[{port, Port},
485485
{certfile, filename:join([CertsDir, "server", "cert.pem"])},

deps/rabbitmq_auth_backend_oauth2/test/system_SUITE.erl

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ groups() ->
8787
]},
8888
{with_introspection_endpoint, [], [
8989
test_successful_connection_with_valid_opaque_token,
90-
test_unsuccessful_connection_with_invalid_opaque_token
90+
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
9194
]}
9295
].
9396

@@ -303,7 +306,11 @@ init_per_testcase(multiple_resource_server_ids, Config) ->
303306
rabbit_ct_helpers:testcase_started(Config, multiple_resource_server_ids),
304307
Config;
305308

306-
init_per_testcase(Testcase, Config) when Testcase =:= test_successful_connection_with_valid_opaque_token ->
309+
init_per_testcase(Testcase, Config) when Testcase =:= test_successful_connection_with_valid_opaque_token orelse
310+
Testcase =:= test_successful_opaque_token_refresh orelse
311+
Testcase =:= test_successful_opaque_token_refresh_with_more_restrictive_token orelse
312+
Testcase =:= test_unsuccessful_opaque_token_refresh_with_inactive_token ->
313+
rabbit_ct_broker_helpers:add_vhost(Config, <<"vhost1">>),
307314
rabbit_ct_helpers:testcase_started(
308315
setup_introspection_configuration(Config), Testcase);
309316

@@ -372,7 +379,10 @@ end_per_testcase(multiple_resource_server_ids, Config) ->
372379
rabbit_ct_helpers:testcase_started(Config, multiple_resource_server_ids),
373380
Config;
374381

375-
end_per_testcase(Testcase, Config) when Testcase =:= test_successful_connection_with_valid_opaque_token ->
382+
end_per_testcase(Testcase, Config) when Testcase =:= test_successful_connection_with_valid_opaque_token orelse
383+
Testcase =:= test_successful_opaque_token_refresh orelse
384+
Testcase =:= test_successful_opaque_token_refresh_with_more_restrictive_token orelse
385+
Testcase =:= test_unsuccessful_opaque_token_refresh_with_inactive_token ->
376386
teardown_introspection_configuration(Config);
377387

378388
end_per_testcase(Testcase, Config) ->
@@ -524,6 +534,47 @@ test_unsuccessful_connection_with_invalid_opaque_token(Config) ->
524534
{error, Error} = open_unmanaged_connection(Config, 0, <<"username">>, <<"inactive">>),
525535
ct:log("Error : ~p", [Error]).
526536

537+
test_successful_opaque_token_refresh(Config) ->
538+
Conn = open_unmanaged_connection(Config, 0, <<"vhost1">>, <<"username">>, <<"active">>),
539+
{ok, Ch} = amqp_connection:open_channel(Conn),
540+
541+
#'queue.declare_ok'{queue = _} =
542+
amqp_channel:call(Ch, #'queue.declare'{exclusive = true}),
543+
544+
?assertEqual(ok, amqp_connection:update_secret(Conn, <<"active">>, <<"token refresh">>)),
545+
546+
{ok, Ch2} = amqp_connection:open_channel(Conn),
547+
548+
#'queue.declare_ok'{queue = _} =
549+
amqp_channel:call(Ch2, #'queue.declare'{exclusive = true}),
550+
551+
close_connection_and_channel(Conn, Ch).
552+
553+
test_successful_opaque_token_refresh_with_more_restrictive_token(Config) ->
554+
Conn = open_unmanaged_connection(Config, 0, <<"vhost1">>, <<"username">>, <<"active">>),
555+
{ok, Ch} = amqp_connection:open_channel(Conn),
556+
557+
#'queue.declare_ok'{queue = _} =
558+
amqp_channel:call(Ch, #'queue.declare'{exclusive = true}),
559+
560+
?assertEqual(ok, amqp_connection:update_secret(Conn, <<"active-2">>, <<"token refresh">>)),
561+
562+
{ok, Ch2} = amqp_connection:open_channel(Conn),
563+
564+
?assertExit({{shutdown, {server_initiated_close, 403, _}}, _},
565+
amqp_channel:call(Ch2, #'queue.declare'{queue = <<"a.q">>, exclusive = true})),
566+
567+
catch close_connection(Conn).
568+
569+
test_unsuccessful_opaque_token_refresh_with_inactive_token(Config) ->
570+
Conn = open_unmanaged_connection(Config, 0, <<"vhost1">>, <<"username">>, <<"active">>),
571+
{ok, Ch} = amqp_connection:open_channel(Conn),
572+
573+
#'queue.declare_ok'{queue = _} =
574+
amqp_channel:call(Ch, #'queue.declare'{exclusive = true}),
575+
576+
?assertException(exit, {{nodedown,not_allowed},_},
577+
amqp_connection:update_secret(Conn, <<"inactive">>, <<"token refresh">>)).
527578

528579
mqtt(Config) ->
529580
Topic = <<"test/topic">>,

0 commit comments

Comments
 (0)