Skip to content

Commit 37f2e7b

Browse files
Declare display order of oauth2 resources
Using the index attribute defined in the managemnet.oauth_resource_servers.<>.index
1 parent c263619 commit 37f2e7b

File tree

8 files changed

+32
-55
lines changed

8 files changed

+32
-55
lines changed

deps/rabbitmq_management/priv/schema/rabbitmq_management.schema

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,12 @@ end}.
529529
[{datatype, string}]
530530
}.
531531

532+
{mapping,
533+
"management.oauth_resource_servers.$name.index",
534+
"rabbitmq_management.oauth_resource_servers",
535+
[{datatype, string}]
536+
}.
537+
532538
{mapping,
533539
"management.oauth_resource_servers.$name.oauth_provider_url",
534540
"rabbitmq_management.oauth_resource_servers",

deps/rabbitmq_management/src/rabbit_mgmt_schema.erl

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
]).
1616

1717
extract_key_as_binary({Name,_}) -> list_to_binary(Name).
18+
extract_value({_Name,V}) -> V.
1819

1920
-spec translate_oauth_resource_servers([{list(), binary()}]) -> map().
2021
translate_oauth_resource_servers(Conf) ->
2122
Settings = cuttlefish_variable:filter_by_prefix(
22-
"management.oauth_resource_servers", Conf),
23+
"management.oauth_resource_servers", Conf),
2324
Map = merge_list_of_maps([
2425
extract_resource_server_properties(Settings),
2526
extract_resource_server_endpoint_params(oauth_authorization_endpoint_params, Settings),
@@ -48,18 +49,13 @@ convert_list_to_binary(V) when is_list(V) ->
4849
convert_list_to_binary(V) ->
4950
V.
5051

51-
extract_resource_server_properties(Settings) ->
52+
extract_resource_server_properties(Settings) ->
53+
KeyFun = fun extract_key_as_binary/1,
54+
ValueFun = fun extract_value/1,
55+
5256
OAuthResourceServers = [{Name, {list_to_atom(Key), convert_list_to_binary(V)}}
5357
|| {["management","oauth_resource_servers", Name, Key], V} <- Settings ],
54-
OAuthResourceServers1 = lists:foldl(fun ({K, Value}, Acc) ->
55-
Key = list_to_binary(K),
56-
Attrs = case maps:get(Key, Acc, []) of
57-
[] -> [] ++ [{index, maps:size(Acc)+1}, Value];
58-
List -> List ++ [Value]
59-
end,
60-
maps:put(Key, Attrs, Acc) end, #{}, OAuthResourceServers),
61-
ct:log("OAuthResourceServers1: ~p", [OAuthResourceServers1]),
62-
OAuthResourceServers1.
58+
maps:groups_from_list(KeyFun, ValueFun, OAuthResourceServers).
6359

6460

6561
extract_resource_server_endpoint_params(Variable, Settings) ->

deps/rabbitmq_management/src/rabbit_mgmt_wm_auth.erl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
-include_lib("rabbitmq_management_agent/include/rabbit_mgmt_records.hrl").
1515
-include_lib("oauth2_client/include/oauth2_client.hrl").
16+
-include_lib("kernel/include/logger.hrl").
1617

1718
%%--------------------------------------------------------------------
1819

@@ -119,6 +120,7 @@ buildRootResourceServerIfAny(Id, Props) ->
119120

120121
authSettings() ->
121122
ManagementProps = application:get_all_env(rabbitmq_management),
123+
?LOG_DEBUG("ManagementProps: ~p", [ManagementProps]),
122124
OAuth2BackendProps = application:get_all_env(rabbitmq_auth_backend_oauth2),
123125
EnableOAUTH = proplists:get_value(oauth_enabled, ManagementProps, false),
124126
case EnableOAUTH of

deps/rabbitmq_management/test/rabbit_mgmt_schema_SUITE.erl

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ all() ->
1919
test_invalid_endpoint_params,
2020
test_translate_endpoint_params,
2121
test_with_one_resource_server,
22-
test_with_many_resource_servers,
23-
test_preserve_order_when_using_many_resource_servers
22+
test_with_many_resource_servers
2423
].
2524

2625

@@ -71,39 +70,6 @@ test_with_many_resource_servers(_) ->
7170
]
7271
} = translate_oauth_resource_servers(Conf).
7372

74-
test_preserve_order_when_using_many_resource_servers(_) ->
75-
Conf = [
76-
{["management","oauth_resource_servers","uaa","label"],"Uaa"},
77-
{["management","oauth_resource_servers","uaa","oauth_client_id"],"uaa-client"},
78-
{["management","oauth_resource_servers","spring","label"],"Spring"},
79-
{["management","oauth_resource_servers","spring","oauth_client_id"],"spring-client"},
80-
{["management","oauth_resource_servers","keycloak","label"],"Keycloak"},
81-
{["management","oauth_resource_servers","keycloak","oauth_client_id"],"keycloak-client"}
82-
],
83-
SortByIndex = fun({_, A}, {_, B}) ->
84-
proplists:get_value(index, A) =< proplists:get_value(index, B) end,
85-
86-
[
87-
{<<"uaa">>, [
88-
{index, 1},
89-
{label, <<"Uaa">>},
90-
{oauth_client_id, <<"uaa-client">>},
91-
{id, <<"uaa">>}
92-
]},
93-
{<<"spring">>, [
94-
{index, 2},
95-
{label, <<"Spring">>},
96-
{oauth_client_id, <<"spring-client">>},
97-
{id, <<"spring">>}
98-
]},
99-
{<<"keycloak">>, [
100-
{index, 3},
101-
{label, <<"Keycloak">>},
102-
{oauth_client_id, <<"keycloak-client">>},
103-
{id, <<"keycloak">>}
104-
]}
105-
] = lists:sort(SortByIndex, maps:to_list(translate_oauth_resource_servers(Conf))).
106-
10773
cert_filename(Conf) ->
10874
string:concat(?config(data_dir, Conf), "certs/cert.pem").
10975

selenium/bin/components/devkeycloak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ start_devkeycloak() {
4848
--https-certificate-key-file=/opt/keycloak/data/import/server_devkeycloak_key.pem \
4949
--hostname=devkeycloak --hostname-admin=devkeycloak --https-port=8442
5050

51-
wait_for_oidc_endpoint devkeycloak $DEVKEYCLOAK_URL $MOUNT_DEVKEYCLOAK_CONF_DIR/ca_certificate.pem
51+
wait_for_oidc_endpoint devkeycloak $DEVKEYCLOAK_URL $MOUNT_DEVKEYCLOAK_CONF_DIR/ca_devkeycloak_certificate.pem
5252
end "devkeycloak is ready"
5353
print " Note: If you modify devkeycloak configuration, make sure to run the following command to export the configuration."
5454
print " docker exec -it devkeycloak /opt/keycloak/bin/kc.sh export --users realm_file --realm test --dir /opt/keycloak/data/import/"

selenium/bin/components/prodkeycloak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ start_prodkeycloak() {
4747
--https-certificate-key-file=/opt/keycloak/data/import/server_prodkeycloak_key.pem \
4848
--hostname=prodkeycloak --hostname-admin=prodkeycloak --https-port=8443
4949

50-
wait_for_oidc_endpoint prodkeycloak $PRODKEYCLOAK_URL $MOUNT_PRODKEYCLOAK_CONF_DIR/ca_certificate.pem
50+
wait_for_oidc_endpoint prodkeycloak $PRODKEYCLOAK_URL $MOUNT_PRODKEYCLOAK_CONF_DIR/ca_prodkeycloak_certificate.pem
5151
end "prodkeycloak is ready"
5252
print " Note: If you modify prodkeycloak configuration, make sure to run the following command to export the configuration."
5353
print " docker exec -it prodkeycloak /opt/keycloak/bin/kc.sh export --users realm_file --realm test --dir /opt/keycloak/data/import/"

selenium/test/multi-oauth/rabbitmq.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ management.oauth_scopes = openid profile rabbitmq.tag:management rabbitmq.tag:ad
4040
## Management ui settings for each declared resource server
4141
management.oauth_resource_servers.1.id = rabbit_prod
4242
management.oauth_resource_servers.1.oauth_client_id = rabbit_prod_mgt_ui
43+
management.oauth_resource_servers.1.index = 1
4344

4445
management.oauth_resource_servers.2.id = rabbit_dev
4546
management.oauth_resource_servers.2.oauth_client_id = rabbit_dev_mgt_ui
47+
management.oauth_resource_servers.2.index = 2
4648

4749
management.oauth_resource_servers.3.id = rabbit_internal
4850
management.oauth_resource_servers.3.disabled = true

selenium/test/multi-oauth/without-basic-auth/landing.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,20 @@ describe('Given three oauth resources but only two enabled, an unauthenticated u
2727
resources = await homePage.getOAuthResourceOptions()
2828
if (hasProfile("with-resource-label")) {
2929
assertAllOptions([
30-
{ value : "rabbit_dev", text : "RabbitMQ Development" },
31-
{ value : "rabbit_prod", text : "RabbitMQ Production" }
32-
], resources)
30+
{ value : "rabbit_prod", text : "RabbitMQ Production" },
31+
{ value : "rabbit_dev", text : "RabbitMQ Development" }
32+
], resources);
33+
// assert resources are rendered in the same order they are configured : prod and then dev
34+
assert.equal("RabbitMQ Production", resources[0].text);
35+
assert.equal("RabbitMQ Development", resources[1].text);
3336
}else {
3437
assertAllOptions([
35-
{ value : "rabbit_dev", text : "rabbit_dev" },
36-
{ value : "rabbit_prod", text : "rabbit_prod" }
37-
], resources)
38-
}
38+
{ value : "rabbit_prod", text : "rabbit_prod" },
39+
{ value : "rabbit_dev", text : "rabbit_dev" }
40+
], resources);
41+
assert.equal("rabbit_prod", resources[0].text);
42+
assert.equal("rabbit_dev", resources[1].text);
43+
}
3944
})
4045

4146
it('should not be presented with a login button to log in using Basic Auth', async function () {

0 commit comments

Comments
 (0)