Skip to content

Commit 032a64a

Browse files
Annotate oauth_resource_server with index attribute
1 parent fa62b23 commit 032a64a

File tree

9 files changed

+105
-32
lines changed

9 files changed

+105
-32
lines changed

deps/rabbitmq_management/priv/www/js/oidc-oauth/helper.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,12 @@ export function hasAnyResourceServerReady(oauth, onReadyCallback) {
392392
warnings.push(warningMessageOAuthResources(url, notCompliantResources, " not compliant"))
393393
}
394394
}
395-
oauth.declared_resource_servers_count = oauth.resource_servers.length
395+
oauth.declared_resource_servers_count = oauth.resource_servers.length;
396396
oauth.resource_servers = oauth.resource_servers.filter((resource) =>
397-
!notReadyServers.includes(resource.oauth_provider_url) && !notCompliantServers.includes(resource.oauth_provider_url))
397+
!notReadyServers.includes(resource.oauth_provider_url) && !notCompliantServers.includes(resource.oauth_provider_url));
398+
oauth.resource_servers.sort((a, b) => a.index - b.index);
398399

399-
onReadyCallback(oauth, warnings)
400+
onReadyCallback(oauth, warnings)
400401

401402
})
402403
}else {

deps/rabbitmq_management/src/rabbit_mgmt_schema.erl

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,22 @@
1515
]).
1616

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

2019
-spec translate_oauth_resource_servers([{list(), binary()}]) -> map().
2120
translate_oauth_resource_servers(Conf) ->
21+
%% Note: Conf must be reversed because cuttlefish_generator:transform_datatypes
22+
%% reverse the order of the configuration from rabbitmq.conf.
23+
%% Exactly on this line: `{[{Variable, NewValue}|Acc], ErrorAcc};`
24+
2225
Settings = cuttlefish_variable:filter_by_prefix(
23-
"management.oauth_resource_servers", Conf),
26+
"management.oauth_resource_servers", lists:reverse(Conf)),
27+
2428
Map = merge_list_of_maps([
2529
extract_resource_server_properties(Settings),
2630
extract_resource_server_endpoint_params(oauth_authorization_endpoint_params, Settings),
2731
extract_resource_server_endpoint_params(oauth_token_endpoint_params, Settings)
2832
]),
33+
?LOG_DEBUG("translate_oauth_resource_servers: ~p", [Map]),
2934
Map0 = maps:map(fun(K,V) ->
3035
case proplists:get_value(id, V) of
3136
undefined -> V ++ [{id, K}];
@@ -49,15 +54,18 @@ convert_list_to_binary(V) when is_list(V) ->
4954
convert_list_to_binary(V) ->
5055
V.
5156

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

6270
extract_resource_server_endpoint_params(Variable, Settings) ->
6371
KeyFun = fun extract_key_as_binary/1,

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: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ test_with_one_resource_server(_) ->
4848
],
4949
#{
5050
<<"rabbitmq1">> := [
51+
{index, 1},
5152
{id, <<"rabbitmq1">>}
5253
]
5354
} = translate_oauth_resource_servers(Conf).
@@ -59,10 +60,12 @@ test_with_many_resource_servers(_) ->
5960
],
6061
#{
6162
<<"keycloak">> := [
63+
{index, 1},
6264
{label, <<"Keycloak">>},
6365
{id, <<"keycloak">>}
6466
],
6567
<<"uaa">> := [
68+
{index, 2},
6669
{label, <<"Uaa">>},
6770
{id, <<"uaa">>}
6871
]
@@ -71,23 +74,35 @@ test_with_many_resource_servers(_) ->
7174
test_preserve_order_when_using_many_resource_servers(_) ->
7275
Conf = [
7376
{["management","oauth_resource_servers","uaa","label"],"Uaa"},
77+
{["management","oauth_resource_servers","uaa","oauth_client_id"],"uaa-client"},
7478
{["management","oauth_resource_servers","spring","label"],"Spring"},
75-
{["management","oauth_resource_servers","keycloak","label"],"Keycloak"}
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"}
7682
],
77-
#{
78-
<<"uaa">> := [
83+
SortByIndex = fun({_, A}, {_, B}) ->
84+
proplists:get_value(index, A) =< proplists:get_value(index, B) end,
85+
86+
[
87+
{<<"uaa">>, [
88+
{index, 1},
7989
{label, <<"Uaa">>},
90+
{oauth_client_id, <<"uaa-client">>},
8091
{id, <<"uaa">>}
81-
],
82-
<<"spring">> := [
92+
]},
93+
{<<"spring">>, [
94+
{index, 2},
8395
{label, <<"Spring">>},
84-
{id, <<"spring">>}
85-
],
86-
<<"keycloak">> := [
96+
{oauth_client_id, <<"spring-client">>},
97+
{id, <<"spring">>}
98+
]},
99+
{<<"keycloak">>, [
100+
{index, 3},
87101
{label, <<"Keycloak">>},
88-
{id, <<"keycloak">>}
89-
]
90-
} = translate_oauth_resource_servers(Conf).
102+
{oauth_client_id, <<"keycloak-client">>},
103+
{id, <<"keycloak">>}
104+
]}
105+
] = lists:sort(SortByIndex, maps:to_list(translate_oauth_resource_servers(Conf))).
91106

92107
cert_filename(Conf) ->
93108
string:concat(?config(data_dir, Conf), "certs/cert.pem").

selenium/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ FROM node:24 AS base
33
WORKDIR /code
44

55
COPY package.json package.json
6+
COPY .npmrc .npmrc
67

78
FROM base AS test
89
RUN npm install --verbose

selenium/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,44 @@ following command:
236236
MOCHA_DOCKER_FILE=\location\of\my\Dockerfile ./run-suites.sh
237237
```
238238

239+
## How to solve : NPM packages are blocked by network firewalls
240+
241+
This network issue manifests in two stages. One stage is when you run the tests
242+
interactively, i.e. using `npm` directly in the host machine. The steps below configures
243+
npm, in the host machine, so that it is not blocked by network firewalls.
244+
245+
1. Make sure you are connected to the VPN in Full Tunnel mode. Artifactory returns an HTTP 403 forbidden error from anywhere outside the full corporate network.
246+
2. `cd selenium`
247+
3. `npm config set registry https://usw1.packages.broadcom.com/artifactory/api/npm/tds-rabbitmq-npm-virtual/ -L project`
248+
4. `npm login --auth-type=web`
249+
5. After you run the last command you should see the folowing sentence
250+
`Login at:
251+
https://usw1.packages.broadcom.com/ui/auth-provider/npm?uuid=JEGSj5dC8X4S8TGKPL2CbSPR3CSnVgvz5r3hMZAbioQy9o98Y7hKvQ7NjA7pxZ21upVkiP1pWkRjpb4CDUDRur4UFwdGhndcas5JexreDXpykBtGsy6
252+
Press ENTER to open in the browser...
253+
`
254+
6. Press enter so that it opens on a browser
255+
7. JFrog loads and it prompts you if you are loging in. You accept you are logging.
256+
8. You should get the message `Login performed successfully. Redirecting to home page.`
257+
258+
For further information, checkout https://github.gwd.broadcom.net/TNZ/rabbitmq-private-docs/wiki/Artifactory-NPM.
259+
260+
If you need to build a `mocha-test` image because you want to run the tests in
261+
silent mode, i.e. in the background, you need to configure NPM in docker.
262+
Follow these steps:
263+
264+
1. Navigate to https://usw1.packages.broadcom.com/
265+
2. Log in with your Broadcom credentials
266+
3. Click on your username in the top-right corner
267+
4. Select "Edit Profile"
268+
5. In the left sidebar, click "Generate an Identity Token"
269+
6. Copy the generated token
270+
7. Edit file selenium/.npmrc and make sure it has this format.
271+
```
272+
registry=https://usw1.packages.broadcom.com/artifactory/api/npm/tds-rabbitmq-npm-virtual/
273+
//usw1.packages.broadcom.com/artifactory/api/npm/tds-rabbitmq-npm-virtual/:_authToken=<paste_here_the_token>
274+
```
275+
Note: The `Dockerfile` copies the .npmrc into the image.
276+
277+
For further information, check out https://github.gwd.broadcom.net/TNZ/rabbitmq-private-docs/wiki/Artifactory-Docker#step-1-generate-artifactory-token.
278+
279+
Note: You will notice that building the mocha-image takes far longer now.

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/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)