From edabd8816b8071a8c11c52d5297728cfaad260eb Mon Sep 17 00:00:00 2001 From: Marcial Rosales Date: Tue, 4 Oct 2022 16:43:18 +0200 Subject: [PATCH] Support multiple path segments in management path Updated selenium tests to tests against 2 path segments rather than just one --- .../priv/www/js/oidc-oauth/helper.js | 14 ++++++-------- deps/rabbitmq_management/selenium/README.md | 18 ++++++++++++++++++ .../suites/oauth-with-uaa-with-mgt-prefix.sh | 4 +++- .../test/oauth/rabbitmq-localhost.config | 4 ++-- .../test/oauth/rabbitmq-with-mgt-prefix.config | 2 +- .../selenium/test/oauth/uaa-localhost/uaa.yml | 6 +++--- .../test/oauth/uaa-with-mgt-prefix/uaa.yml | 2 +- 7 files changed, 34 insertions(+), 16 deletions(-) diff --git a/deps/rabbitmq_management/priv/www/js/oidc-oauth/helper.js b/deps/rabbitmq_management/priv/www/js/oidc-oauth/helper.js index 97bbf40491..7fc780e7c2 100644 --- a/deps/rabbitmq_management/priv/www/js/oidc-oauth/helper.js +++ b/deps/rabbitmq_management/priv/www/js/oidc-oauth/helper.js @@ -4,8 +4,9 @@ var _management_logger; function oauth_initialize_if_required() { rabbit_port = window.location.port ? ":" + window.location.port : "" + rabbit_path_prefix = window.location.pathname.replace(/(\/js\/oidc-oauth\/.*$|\/+$)/, "") rabbit_base_uri = window.location.protocol + "//" + window.location.hostname - + rabbit_port + rabbit_path_prefix() + + rabbit_port + rabbit_path_prefix var request = new XMLHttpRequest(); request.open("GET", rabbit_base_uri + "/api/auth", false); @@ -17,10 +18,7 @@ function oauth_initialize_if_required() { } } -function rabbit_path_prefix() { - paths = window.location.pathname.split("/") - return paths[1] === "js" || paths[1] === "" ? "" : "/" + paths[1] -} + function auth_settings_apply_defaults(authSettings) { if (authSettings.enable_uaa == "true") { @@ -144,13 +142,13 @@ function oauth_initiateLogin() { function oauth_redirectToHome(oauth) { set_auth_pref(oauth.user_name + ":" + oauth.access_token); - location.href = "/" + location.href = rabbit_path_prefix + "/" } function oauth_redirectToLogin(error) { _management_logger.debug("oauth_redirectToLogin called"); - if (!error) location.href = "/" + if (!error) location.href = rabbit_path_prefix + "/" else { - location.href = "/?error=" + error + location.href = rabbit_path_prefix + "/?error=" + error } } function oauth_completeLogin() { diff --git a/deps/rabbitmq_management/selenium/README.md b/deps/rabbitmq_management/selenium/README.md index 1e4439cc12..6d5ab26200 100644 --- a/deps/rabbitmq_management/selenium/README.md +++ b/deps/rabbitmq_management/selenium/README.md @@ -49,6 +49,24 @@ And this is how we run all suites: run-suites.sh ``` +If you want to test your local changes, you can still build an image with these 2 commands from the +root folder of the `rabbitmq-server` repo: +``` +cd ../../../../ +make package-generic-unix +make docker-image +``` + +The last command prints something like this: +``` + => => naming to docker.io/pivotalrabbitmq/rabbitmq:3.11.0-rc.2.51.g4f3e539.dirty 0.0s +``` + +To run a suite with a particular docker image we do it like this: +``` +cd deps/rabbitmq_management/selenium/suites +RABBITMQ_DOCKER_IMAGE=pivotalrabbitmq/rabbitmq:3.11.0-rc.2.51.g4f3e539.dirty ./oauth-with-uaa-with-mgt-prefix.sh +``` ## Run tests interactively using your local chrome browser diff --git a/deps/rabbitmq_management/selenium/suites/oauth-with-uaa-with-mgt-prefix.sh b/deps/rabbitmq_management/selenium/suites/oauth-with-uaa-with-mgt-prefix.sh index b3c85e09f2..b770389346 100755 --- a/deps/rabbitmq_management/selenium/suites/oauth-with-uaa-with-mgt-prefix.sh +++ b/deps/rabbitmq_management/selenium/suites/oauth-with-uaa-with-mgt-prefix.sh @@ -7,13 +7,15 @@ SUITE=$( basename "${BASH_SOURCE[0]}" .sh) # Path to the test cases this suite should run. It is relative to the selenium/test folder TEST_CASES_PATH=/oauth/with-uaa -# Path to the folder where all configuration file reside. It is relative to the selenim/test folder +# Path to the folder where all configuration file reside. It is relative to the selenim/test folder TEST_CONFIG_PATH=/oauth # Path to the uaa configuration. It is relative to the TEST_CONFIG_PATH UAA_CONFIG_PATH=/uaa-with-mgt-prefix # Name of the rabbitmq config file. It is relative to the TEST_CONFIG_PATH RABBITMQ_CONFIG_FILENAME=rabbitmq-with-mgt-prefix.config +RABBITMQ_URL=http://rabbitmq:15672/my-prefix/another-prefix/ + source $SCRIPT/suite_template _setup () { diff --git a/deps/rabbitmq_management/selenium/test/oauth/rabbitmq-localhost.config b/deps/rabbitmq_management/selenium/test/oauth/rabbitmq-localhost.config index afa456814c..d299cafe6f 100644 --- a/deps/rabbitmq_management/selenium/test/oauth/rabbitmq-localhost.config +++ b/deps/rabbitmq_management/selenium/test/oauth/rabbitmq-localhost.config @@ -3,10 +3,10 @@ {auth_backends, [rabbit_auth_backend_oauth2]} ]}, {rabbitmq_management, [ - {login_session_timeout, 1}, %% in minutes + {login_session_timeout, 150}, %% in minutes {enable_uaa, true}, {oauth_enabled, true}, - %% {path_prefix, "/my-prefix"}, + {path_prefix, "/my-prefix/another-prefix"}, {oauth_client_id, "rabbit_client_code"}, {oauth_client_secret, "rabbit_client_code"}, {oauth_provider_url, "http://localhost:8080"} diff --git a/deps/rabbitmq_management/selenium/test/oauth/rabbitmq-with-mgt-prefix.config b/deps/rabbitmq_management/selenium/test/oauth/rabbitmq-with-mgt-prefix.config index bb83c9e160..462939ce4c 100644 --- a/deps/rabbitmq_management/selenium/test/oauth/rabbitmq-with-mgt-prefix.config +++ b/deps/rabbitmq_management/selenium/test/oauth/rabbitmq-with-mgt-prefix.config @@ -6,7 +6,7 @@ {login_session_timeout, 1}, %% in minutes {enable_uaa, true}, {oauth_enabled, true}, - {path_prefix, "/my-prefix"}, + {path_prefix, "/my-prefix/another-prefix"}, {oauth_client_id, "rabbit_client_code"}, {oauth_client_secret, "rabbit_client_code"}, {oauth_provider_url, "http://uaa:8080"} diff --git a/deps/rabbitmq_management/selenium/test/oauth/uaa-localhost/uaa.yml b/deps/rabbitmq_management/selenium/test/oauth/uaa-localhost/uaa.yml index 7123bf45a4..8f89fe1816 100644 --- a/deps/rabbitmq_management/selenium/test/oauth/uaa-localhost/uaa.yml +++ b/deps/rabbitmq_management/selenium/test/oauth/uaa-localhost/uaa.yml @@ -62,7 +62,7 @@ jwt: token: policy: # Will override global validity policies for the default zone only. - accessTokenValiditySeconds: 15 + accessTokenValiditySeconds: 1500 keys: legacy-token-key: signingKey: | @@ -131,8 +131,8 @@ oauth: authorized-grant-types: authorization_code scope: rabbitmq.*,openid,profile authorities: uaa.resource,rabbitmq - redirect-uri: http://localhost:15672 - # redirect-uri: http://localhost:15672/my-prefix/ + #redirect-uri: http://localhost:15672 + redirect-uri: http://localhost:15672/my-prefix/another-prefix/ autoapprove: true mgt_api_client_2: diff --git a/deps/rabbitmq_management/selenium/test/oauth/uaa-with-mgt-prefix/uaa.yml b/deps/rabbitmq_management/selenium/test/oauth/uaa-with-mgt-prefix/uaa.yml index 9c9b731685..e510f61cfc 100644 --- a/deps/rabbitmq_management/selenium/test/oauth/uaa-with-mgt-prefix/uaa.yml +++ b/deps/rabbitmq_management/selenium/test/oauth/uaa-with-mgt-prefix/uaa.yml @@ -131,7 +131,7 @@ oauth: authorized-grant-types: authorization_code scope: rabbitmq.*,openid,profile authorities: uaa.resource,rabbitmq - redirect-uri: http://rabbitmq:15672/my-prefix/ + redirect-uri: http://rabbitmq:15672/my-prefix/another-prefix/ autoapprove: true mgt_api_client_2: