Skip to content

Commit 9fc112a

Browse files
Insert control-cache headers to every resource and reload index.html
1 parent 5745fa6 commit 9fc112a

File tree

11 files changed

+102
-30
lines changed

11 files changed

+102
-30
lines changed

deps/rabbitmq_management/priv/www/index.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@
2121
<link href="css/main.css" rel="stylesheet" type="text/css"/>
2222
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon"/>
2323

24-
<script type="module">
25-
window.oauth = oauth_initialize_if_required();
26-
24+
<script type="module">
25+
window.oauth = oauth_initialize_if_required()
2726
</script>
2827

2928

deps/rabbitmq_management/priv/www/js/main.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ function check_login () {
127127
}
128128
return false;
129129
}
130-
130+
check_version()
131131
hide_popup_warn()
132132
replace_content('outer', format('layout', {}))
133133
var user_login_session_timeout = parseInt(user.login_session_timeout)
@@ -1862,3 +1862,12 @@ function get_chart_range_type(arg) {
18621862
console.log('[WARNING]: range type not found for arg: ' + arg);
18631863
return 'basic';
18641864
}
1865+
1866+
function check_version() {
1867+
let curVersion = sync_get('/version')
1868+
let storedVersion = get_pref('version')
1869+
if (!storedVersion || storedVersion != curVersion) {
1870+
store_pref('version', curVersion)
1871+
location.reload()
1872+
}
1873+
}

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -290,18 +290,21 @@ export function oauth_completeLogin() {
290290

291291
export function oauth_initiateLogout() {
292292
if (oauth.sp_initiated) {
293-
mgr.metadataService.getEndSessionEndpoint().then(endpoint => {
294-
if (endpoint == undefined) {
295-
// Logout only from management UI
296-
mgr.removeUser().then(res => {
297-
clear_auth()
298-
oauth_redirectToLogin()
299-
})
300-
}else {
301-
// OpenId Connect RP-Initiated Logout
302-
mgr.signoutRedirect()
303-
}
293+
return mgr.getUser().then(User => {
294+
mgr.metadataService.getEndSessionEndpoint().then(endpoint => {
295+
if (endpoint == undefined) {
296+
// Logout only from management UI
297+
mgr.removeUser().then(res => {
298+
clear_auth()
299+
oauth_redirectToLogin()
300+
})
301+
}else {
302+
// OpenId Connect RP-Initiated Logout
303+
mgr.signoutRedirect()
304+
}
305+
})
304306
})
307+
305308
} else {
306309
go_to_authority()
307310
}

deps/rabbitmq_management/src/rabbit_mgmt_dispatcher.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,5 +208,6 @@ dispatcher() ->
208208
{"/auth/attempts/:node/source", rabbit_mgmt_wm_auth_attempts, [by_source]},
209209
{"/login", rabbit_mgmt_wm_login, []},
210210
{"/config/effective", rabbit_mgmt_wm_environment, []},
211-
{"/auth/hash_password/:password", rabbit_mgmt_wm_hash_password, []}
211+
{"/auth/hash_password/:password", rabbit_mgmt_wm_hash_password, []},
212+
{"/version", rabbit_mgmt_wm_version, []}
212213
].

deps/rabbitmq_management/src/rabbit_mgmt_headers.erl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,18 @@ set_common_permission_headers(ReqData0, EndpointModule) ->
5555
lists:foldl(fun(Fun, ReqData) ->
5656
Fun(ReqData, EndpointModule)
5757
end, ReqData0,
58-
[fun set_csp_headers/2,
58+
[fun set_etag_based_cache_headers/2,
59+
fun set_csp_headers/2,
5960
fun set_hsts_headers/2,
6061
fun set_cors_headers/2,
6162
fun set_content_type_options_header/2,
6263
fun set_xss_protection_header/2,
6364
fun set_frame_options_header/2]).
6465

66+
set_etag_based_cache_headers(ReqData0, _Module) ->
67+
cowboy_req:set_resp_header(<<"cache-control">>, <<"public, max-age=0, must-revalidate">>, ReqData0).
68+
6569
set_no_cache_headers(ReqData0, _Module) ->
66-
ReqData1 = cowboy_req:set_resp_header(<<"cache-control">>, <<"no-cache, no-store, must-revalidate">>, ReqData0),
70+
ReqData1 = cowboy_req:set_resp_header(<<"cache-control">>, <<"no-cache, no-store, max-age=0, must-revalidate">>, ReqData0),
6771
ReqData2 = cowboy_req:set_resp_header(<<"pragma">>, <<"no-cache">>, ReqData1),
6872
cowboy_req:set_resp_header(<<"expires">>, rabbit_data_coercion:to_binary(0), ReqData2).
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
%% This Source Code Form is subject to the terms of the Mozilla Public
2+
%% License, v. 2.0. If a copy of the MPL was not distributed with this
3+
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
%%
5+
%% Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
6+
%%
7+
8+
-module(rabbit_mgmt_wm_version).
9+
10+
-export([init/2]).
11+
-export([to_json/2, content_types_provided/2]).
12+
-export([variances/2]).
13+
14+
-include_lib("rabbit_common/include/rabbit.hrl").
15+
-include_lib("rabbitmq_management_agent/include/rabbit_mgmt_records.hrl").
16+
17+
%%--------------------------------------------------------------------
18+
19+
init(Req, _State) ->
20+
{cowboy_rest, rabbit_mgmt_headers:set_no_cache_headers(
21+
rabbit_mgmt_headers:set_common_permission_headers(Req, ?MODULE), ?MODULE),
22+
#context{}}.
23+
24+
variances(Req, Context) ->
25+
{[<<"accept-encoding">>, <<"origin">>], Req, Context}.
26+
27+
content_types_provided(ReqData, Context) ->
28+
{rabbit_mgmt_util:responder_map(to_json), ReqData, Context}.
29+
30+
to_json(ReqData, Context) ->
31+
Version = case rabbit:product_version() of
32+
undefined -> rabbit:base_product_version();
33+
V -> V
34+
end,
35+
rabbit_mgmt_util:reply(list_to_binary(Version), ReqData, Context).
36+
37+
%%--------------------------------------------------------------------
38+

deps/rabbitmq_management/test/rabbit_mgmt_http_SUITE.erl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ all() ->
5656
].
5757

5858
groups() ->
59-
[
59+
[
6060
{all_tests_with_prefix, [], some_tests() ++ all_tests()},
6161
{all_tests_without_prefix, [], some_tests()},
6262
%% We have several groups because their interference is
@@ -104,7 +104,6 @@ definitions_group4_tests() ->
104104
definitions_vhost_test
105105
].
106106

107-
108107
all_tests() -> [
109108
cli_redirect_test,
110109
api_redirect_test,
@@ -205,7 +204,8 @@ all_tests() -> [
205204
amqp_sessions,
206205
amqpl_sessions,
207206
enable_plugin_amqp,
208-
cluster_and_node_tags_test
207+
cluster_and_node_tags_test,
208+
version_test
209209
].
210210

211211
%% -------------------------------------------------------------------
@@ -3896,6 +3896,13 @@ oauth_test(Config) ->
38963896
%% cleanup
38973897
rpc(Config, application, unset_env, [rabbitmq_management, oauth_enabled]).
38983898

3899+
version_test(Config) ->
3900+
ActualVersion = http_get(Config, "/version"),
3901+
ct:log("ActualVersion : ~p", [ActualVersion]),
3902+
ExpectedVersion = rpc(Config, rabbit, base_product_version, []),
3903+
ct:log("ExpectedVersion : ~p", [ExpectedVersion]),
3904+
?assertEqual(ExpectedVersion, binary_to_list(ActualVersion)).
3905+
38993906
login_test(Config) ->
39003907
http_put(Config, "/users/myuser", [{password, <<"myuser">>},
39013908
{tags, <<"management">>}], {group, '2xx'}),

selenium/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ not see any browser interaction, everything happens in the background, i.e. rabb
6262

6363
**The interactive mode** - This mode is convenient when we are still working on RabbitMQ source code and/or in the selenium tests. In this mode, you run RabbitMQ and tests directly from source to speed things up. The components, such as, UAA or keycloak, run in docker.
6464

65+
**IMPORTANT** - If you intend to switch between version of RabbitMQ, make sure
66+
you run `./clean.sh` to clear any state left from the last test run.
67+
6568

6669
## Run tests in headless-mode
6770

selenium/clean.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
rm -r $TMPDIR/rabbitmq-test-instances

selenium/test/basic-auth/unauthorized.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ describe('An user without management tag', function () {
1919
overview = new OverviewPage(driver)
2020
captureScreen = captureScreensFor(driver, __filename)
2121

22-
assert.ok(!await login.isPopupWarningDisplayed())
23-
await login.login('rabbit_no_management', 'rabbit_no_management')
24-
await !overview.isLoaded()
22+
//assert.ok(!await login.isPopupWarningDisplayed())
23+
await login.login('rabbit_no_management', 'guest')
2524
})
2625

2726
it('cannot log in into the management ui', async function () {
@@ -35,7 +34,7 @@ describe('An user without management tag', function () {
3534

3635
it('should get popup warning dialog', async function(){
3736
assert.ok(login.isPopupWarningDisplayed())
38-
assert.equal('Not_Authorized', await login.getPopupWarning())
37+
assert.equal('Not management user', await login.getPopupWarning())
3938
})
4039

4140
describe("After clicking on popup warning dialog button", function() {

0 commit comments

Comments
 (0)