Skip to content

api: Warn if query parameters have multiple values - #5009

Merged
nvazquez merged 4 commits into
apache:mainfrom
shapeblue:fix-query-param
Mar 8, 2022
Merged

nvazquez merged 4 commits into
apache:mainfrom
shapeblue:fix-query-param

Conversation

@davidjumani

@davidjumani davidjumani commented May 10, 2021

Copy link
Copy Markdown
Contributor

Description

Fixes #5007

When duplicate query parameters are passed with the same key but different values, ACS parses only the last occurrence.
Eg: keyword=rick&keyword=basic
It returns values matching basic

This PR fixes it so it throws an error when multiple values for the same key is sent

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

How Has This Been Tested?

http://localhost:8080/client/api/?command=listVirtualMachines&keyword=rick&keyword=basic

WARN  [c.c.a.ApiServlet] (qtp875678495-281:ctx-f7a451f1) (logid:742779bd) Query parameter 'keyword' has multiple values [rick, basic]

@davidjumani
davidjumani changed the base branch from master to 4.15 May 10, 2021 12:01
@davidjumani

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@davidjumani a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result: ✖️ centos7 ✖️ centos8 ✖️ debian. SL-JID 557

@davidjumani

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@davidjumani a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result: ✖️ centos7 ✖️ centos8 ✖️ debian. SL-JID 558

Comment on lines +460 to +462
String message = String.format("Query parameter '%s' has multiple values", param.getName());
s_logger.error(message);
throw new ServerApiException(ApiErrorCode.MALFORMED_PARAMETER_ERROR, message);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a repeating bit (also happening in ApuServlet) maybe we can move (parts of) it to a common utility?

@blueorangutan

Copy link
Copy Markdown

Packaging result: ✔️ centos7 ✖️ centos8 ✔️ debian. SL-JID 564

@davidjumani

Copy link
Copy Markdown
Contributor Author

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@davidjumani a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests

@blueorangutan

Copy link
Copy Markdown

Trillian test result (tid-646)
Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
Total time taken: 59837 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr5009-t646-kvm-centos7.zip
Intermittent failure detected: /marvin/tests/smoke/test_diagnostics.py
Intermittent failure detected: /marvin/tests/smoke/test_internal_lb.py
Intermittent failure detected: /marvin/tests/smoke/test_kubernetes_clusters.py
Intermittent failure detected: /marvin/tests/smoke/test_network.py
Intermittent failure detected: /marvin/tests/smoke/test_router_dns.py
Intermittent failure detected: /marvin/tests/smoke/test_vpc_redundant.py
Intermittent failure detected: /marvin/tests/smoke/test_vpc_router_nics.py
Smoke tests completed. 83 look OK, 4 have error(s)
Only failed tests results shown below:

Test Result Time (s) Test File
test_01_invalid_upgrade_kubernetes_cluster Failure 3611.06 test_kubernetes_clusters.py
test_02_deploy_and_upgrade_kubernetes_cluster Failure 3605.16 test_kubernetes_clusters.py
test_03_deploy_and_scale_kubernetes_cluster Failure 0.04 test_kubernetes_clusters.py
test_04_basic_lifecycle_kubernetes_cluster Failure 0.05 test_kubernetes_clusters.py
test_05_delete_kubernetes_cluster Failure 0.04 test_kubernetes_clusters.py
test_07_deploy_kubernetes_ha_cluster Failure 0.05 test_kubernetes_clusters.py
test_08_deploy_and_upgrade_kubernetes_ha_cluster Failure 0.04 test_kubernetes_clusters.py
test_09_delete_kubernetes_ha_cluster Failure 0.04 test_kubernetes_clusters.py
ContextSuite context=TestKubernetesCluster>:teardown Error 89.94 test_kubernetes_clusters.py
test_router_dns_guestipquery Failure 613.66 test_router_dns.py
test_01_create_redundant_VPC_2tiers_4VMs_4IPs_4PF_ACL Failure 485.13 test_vpc_redundant.py
test_01_VPC_nics_after_destroy Failure 933.88 test_vpc_router_nics.py

@GutoVeronezi

Copy link
Copy Markdown
Contributor

@davidjumani although you link the issue, could you improve the description of this PR with more context?

@yadvr

yadvr commented Aug 31, 2021

Copy link
Copy Markdown
Member

@davidjumani I'm not sure if it may cause any regression, since we're tight for a RC this or early next week, I'm moving the milestone.

@yadvr yadvr modified the milestones: 4.15.2.0, 4.16.0.0 Aug 31, 2021
@yadvr
yadvr changed the base branch from 4.15 to main August 31, 2021 09:01
@yadvr yadvr modified the milestones: 4.16.0.0, 4.16.1.0 Sep 14, 2021
@yadvr yadvr modified the milestones: 4.16.1.0, 4.17.0.0 Nov 25, 2021
@davidjumani
davidjumani marked this pull request as ready for review February 25, 2022 05:43
@davidjumani

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@davidjumani a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result: ✔️ el7 ✔️ el8 ✔️ debian ✔️ suse15. SL-JID 2713

@davidjumani

Copy link
Copy Markdown
Contributor Author

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@davidjumani a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests

@blueorangutan

Copy link
Copy Markdown

Trillian test result (tid-3433)
Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
Total time taken: 36295 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr5009-t3433-kvm-centos7.zip
Smoke tests completed. 92 look OK, 0 have errors
Only failed tests results shown below:

Test Result Time (s) Test File

@weizhouapache

Copy link
Copy Markdown
Member

this might cause backwards compatibility issue. I suggest to hold on
cc @nvazquez @DaanHoogland @davidjumani

@DaanHoogland

Copy link
Copy Markdown
Contributor

this might cause backwards compatibility issue. I suggest to hold on cc @nvazquez @DaanHoogland @davidjumani

what kind of issues, @weizhouapache ?

@weizhouapache

Copy link
Copy Markdown
Member

this might cause backwards compatibility issue. I suggest to hold on cc @nvazquez @DaanHoogland @davidjumani

what kind of issues, @weizhouapache ?

@DaanHoogland
I think we should allow duplicated query parameters. and display a warning not throw an error if possible.
some users might pass duplicated parameters in scripts and etc, it worked in the past, but with this PR it won't work any more.

@davidjumani davidjumani changed the title api: Ensure single query parameter value api: Warn if query parameters have multiple values Mar 4, 2022
@davidjumani

Copy link
Copy Markdown
Contributor Author

@weizhouapache I've updated it to a warning and to not throw an error

@davidjumani

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@davidjumani a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result: ✔️ el7 ✔️ el8 ✔️ debian ✔️ suse15. SL-JID 2762

@davidjumani

Copy link
Copy Markdown
Contributor Author

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@davidjumani a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests

@weizhouapache weizhouapache left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code lgtm

@nvazquez

nvazquez commented Mar 6, 2022

Copy link
Copy Markdown
Contributor

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@nvazquez a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests

@blueorangutan

Copy link
Copy Markdown

Trillian test result (tid-3507)
Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
Total time taken: 31199 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr5009-t3507-kvm-centos7.zip
Smoke tests completed. 92 look OK, 0 have errors
Only failed tests results shown below:

Test Result Time (s) Test File

Comment thread server/src/main/java/com/cloud/api/ApiServlet.java Outdated
Comment thread server/src/main/java/com/cloud/api/ApiServlet.java
@davidjumani

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@davidjumani a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result: ✔️ el7 ✔️ el8 ✔️ debian ✔️ suse15. SL-JID 2791

@davidjumani

Copy link
Copy Markdown
Contributor Author

Smoke tests won't be needed as they passed the previous time and only cosmetic changes were made

@nvazquez

nvazquez commented Mar 8, 2022

Copy link
Copy Markdown
Contributor

@davidjumani I've manually tested and looks good, I have some minor improvement request:

If passing multiples values for a parameter we use the last, however if I attempt the same on cmk, cmk only passes the first parameter. Can we change the value used to be the first instead of the last so they are consistent?

Comment on lines +468 to +470
String message = String.format("Query parameter '%s' has multiple values [%s, %s]. Only the last value will be respected." +
"It is advised to pass only a single parameter", param.getName(), param.getValue(), parameterMap.get(param.getName()));
s_logger.warn(message);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a joint ApiServer/ApiServlet Utility to put this warning message in, instead of copying the exact same text?
Alternatively can we change the text to indicate where/why we object to the duplicate parameter?

@davidjumani

Copy link
Copy Markdown
Contributor Author

@davidjumani I've manually tested and looks good, I have some minor improvement request:

If passing multiples values for a parameter we use the last, however if I attempt the same on cmk, cmk only passes the first parameter. Can we change the value used to be the first instead of the last so they are consistent?

This is a cmk specific implementation. If an API is called via a browser or tool which simply creates / forwards the requests the last value is respected

@nvazquez
nvazquez merged commit 5534b7a into apache:main Mar 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

Duplicate query string parameters

8 participants