fix: Remove duplicate / character on the proxy route (#10404)

The proxy method adds an extra slash even if the route param has the
character. It’s challenging to check the expected format on each route.
The simplest solution is to check if the route param begins with a
slash, and if not, append one.

NB: The existing tests are sufficient to cover this case. There’s no
need for an additional test to specifically test this.
This commit is contained in:
Pranav
2024-11-12 10:38:29 -08:00
committed by GitHub
parent 97d7b9d754
commit 7dc0eba48a

View File

@@ -18,11 +18,11 @@ class Api::V1::Accounts::Integrations::CaptainController < Api::V1::Accounts::Ba
end
def request_path
if params[:route] == '/sessions/profile'
'api/sessions/profile'
else
"api/accounts/#{hook.settings['account_id']}/#{params[:route]}"
end
request_route = with_leading_hash_on_route(params[:route])
return 'api/sessions/profile' if request_route == '/sessions/profile'
"api/accounts/#{hook.settings['account_id']}#{request_route}"
end
def request_url
@@ -41,6 +41,12 @@ class Api::V1::Accounts::Integrations::CaptainController < Api::V1::Accounts::Ba
method
end
def with_leading_hash_on_route(request_route)
return '' if request_route.blank?
request_route.start_with?('/') ? request_route : "/#{request_route}"
end
def permitted_params
params.permit(:method, :route, body: {})
end