Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: default cors plugin formdata validation error #1855

Merged
merged 3 commits into from
May 10, 2021

Conversation

liuxiran
Copy link
Contributor

@liuxiran liuxiran commented May 7, 2021

Please answer these questions before submitting a pull request, or your PR will get closed.

Why submit this pull request?

  • Bugfix
  • New feature provided
  • Improve performance
  • Backport patches

What changes will this PR take into?

when I submitted default cors plugin configure in form mode, a validation error occured:

2021-05-07 13-40-50屏幕截图

the error shows that allow_origins_by_regex should have at least 1 character.

  • Reason

schema of cors plugin:

{
    "properties": {
        ...
	"allow_origins_by_regex": {
	    "description": "you can use regex to allow specific origins when no credentials,for example use [.*\\.test.com] to allow a.test.com and b.test.com",
	    "items": {
		 "maxLength": 4096,
		 "minLength": 1,
		 "type": "string"
	    },
	    "minItems": 1,
	    "type": "array",
	    "uniqueItems": true
	},
    },
   "type": "object"
}

shows that allow_origins_by_regex is not a required item, but when it configured, it should be at least 1 character.

the default post data is:

{
    "allow_credential": false
    "allow_headers": "*"
    "allow_methods": ["*"]
    "allow_origins": "*"
    "allow_origins_by_regex": [""]
    "expose_headers": "*"
    "max_age": 5
}

the mistake is "allow_origins_by_regex": [""], why the value is [""]? In order to make UI better to use, we set default allow_origins_by_regex empty to have one input box in the page.

  • How to fix
    omit allow_origins_by_regex when it is not configured

Checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible? If it is not backward compatible, please discuss on the mailing list first

@netlify
Copy link

netlify bot commented May 7, 2021

Deploy preview for apisix-dashboard ready!

Built with commit 07b9a7c

https://deploy-preview-1855--apisix-dashboard.netlify.app

@codecov-commenter
Copy link

codecov-commenter commented May 7, 2021

Codecov Report

Merging #1855 (bf445c8) into master (b1e66a2) will increase coverage by 0.36%.
The diff coverage is 100.00%.

❗ Current head bf445c8 differs from pull request most recent head 07b9a7c. Consider uploading reports for the commit 07b9a7c to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1855      +/-   ##
==========================================
+ Coverage   72.10%   72.47%   +0.36%     
==========================================
  Files         125      125              
  Lines        2947     2950       +3     
  Branches      711      712       +1     
==========================================
+ Hits         2125     2138      +13     
+ Misses        822      812      -10     
Flag Coverage Δ
frontend-e2e-test 72.47% <100.00%> (+0.36%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
web/src/components/Plugin/UI/cors.tsx 86.95% <ø> (+21.73%) ⬆️
web/src/components/Plugin/PluginDetail.tsx 65.75% <100.00%> (+2.81%) ⬆️
web/src/helpers.tsx 72.13% <0.00%> (+3.27%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b1e66a2...07b9a7c. Read the comment docs.

@juzhiyuan juzhiyuan requested a review from LiteSun May 7, 2021 11:28
@juzhiyuan juzhiyuan requested a review from imjoey May 8, 2021 14:22
Copy link
Member

@imjoey imjoey left a comment

Choose a reason for hiding this comment

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

/lgtm
Thanks.

@imjoey imjoey merged commit a4c7898 into apache:master May 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants