2024-09-20 18:10:26 +08:00
|
|
|
%% This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
%% License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
%%
|
|
|
|
|
%% Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
|
|
|
|
|
%%
|
|
|
|
|
-module(rabbit_mgmt_schema_SUITE).
|
|
|
|
|
|
|
|
|
|
-compile(export_all).
|
|
|
|
|
|
|
|
|
|
-include_lib("common_test/include/ct.hrl").
|
|
|
|
|
-include_lib("eunit/include/eunit.hrl").
|
|
|
|
|
|
|
|
|
|
-import(rabbit_mgmt_schema, [translate_endpoint_params/2, translate_oauth_resource_servers/1]).
|
|
|
|
|
|
|
|
|
|
all() ->
|
2024-09-24 01:04:53 +08:00
|
|
|
[
|
2024-09-20 18:10:26 +08:00
|
|
|
test_empty_endpoint_params,
|
|
|
|
|
test_invalid_endpoint_params,
|
|
|
|
|
test_translate_endpoint_params,
|
|
|
|
|
test_with_one_resource_server,
|
|
|
|
|
test_with_many_resource_servers
|
|
|
|
|
].
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test_empty_endpoint_params(_) ->
|
2024-09-24 17:49:21 +08:00
|
|
|
[] = translate_endpoint_params("oauth_authorization_endpoint_params", []),
|
|
|
|
|
[] = translate_endpoint_params("oauth_token_endpoint_params", []).
|
2024-09-20 18:10:26 +08:00
|
|
|
|
|
|
|
|
test_invalid_endpoint_params(_) ->
|
|
|
|
|
try translate_endpoint_params("oauth_authorization_endpoint_params", [
|
|
|
|
|
{["param1","param2"], "some-value1"}]) of
|
|
|
|
|
_ -> {throw, should_have_failed}
|
|
|
|
|
catch
|
|
|
|
|
_ -> ok
|
|
|
|
|
end.
|
|
|
|
|
|
2024-09-24 01:04:53 +08:00
|
|
|
test_translate_endpoint_params(_) ->
|
2024-09-24 17:49:21 +08:00
|
|
|
[ {<<"param1">>, <<"some-value1">>} ] =
|
2024-09-20 18:10:26 +08:00
|
|
|
translate_endpoint_params("oauth_authorization_endpoint_params", [
|
|
|
|
|
{["management","oauth_authorization_endpoint_params","param1"], "some-value1"}
|
|
|
|
|
]).
|
|
|
|
|
|
|
|
|
|
test_with_one_resource_server(_) ->
|
|
|
|
|
Conf = [
|
|
|
|
|
{["management","oauth_resource_servers","rabbitmq1","id"],"rabbitmq1"}
|
2024-09-24 01:04:53 +08:00
|
|
|
],
|
2024-09-20 18:10:26 +08:00
|
|
|
#{
|
2024-09-24 19:15:45 +08:00
|
|
|
<<"rabbitmq1">> := [
|
|
|
|
|
{id, <<"rabbitmq1">>}
|
2024-09-20 18:10:26 +08:00
|
|
|
]
|
|
|
|
|
} = translate_oauth_resource_servers(Conf).
|
|
|
|
|
|
|
|
|
|
test_with_many_resource_servers(_) ->
|
|
|
|
|
Conf = [
|
|
|
|
|
{["management","oauth_resource_servers","keycloak","label"],"Keycloak"},
|
|
|
|
|
{["management","oauth_resource_servers","uaa","label"],"Uaa"}
|
|
|
|
|
],
|
|
|
|
|
#{
|
2024-09-24 19:15:45 +08:00
|
|
|
<<"keycloak">> := [
|
|
|
|
|
{label, <<"Keycloak">>},
|
|
|
|
|
{id, <<"keycloak">>}
|
2024-09-20 18:10:26 +08:00
|
|
|
],
|
2024-09-24 19:15:45 +08:00
|
|
|
<<"uaa">> := [
|
|
|
|
|
{label, <<"Uaa">>},
|
|
|
|
|
{id, <<"uaa">>}
|
2024-09-20 18:10:26 +08:00
|
|
|
]
|
|
|
|
|
} = translate_oauth_resource_servers(Conf).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cert_filename(Conf) ->
|
|
|
|
|
string:concat(?config(data_dir, Conf), "certs/cert.pem").
|
|
|
|
|
|
|
|
|
|
sort_settings(MapOfListOfSettings) ->
|
|
|
|
|
maps:map(fun(_K,List) ->
|
|
|
|
|
lists:sort(fun({K1,_}, {K2,_}) -> K1 < K2 end, List) end, MapOfListOfSettings).
|