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 ClientAuthenticationFilter.checkTimestamp #3029

Merged
merged 3 commits into from
May 2, 2020

Conversation

liuzhijiang
Copy link
Contributor

@liuzhijiang liuzhijiang commented Apr 21, 2020

What's the purpose of this PR

return false when timestamp - currentTimeMills > 60 seconds

Which issue(s) this PR fixes:

Fixes #

Brief changelog

replace the code x <= TIMESTAMP_INTERVAL with x >= -TIMESTAMP_INTERVAL && x <= TIMESTAMP_INTERVAL

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Read the Contributing Guide before making this pull request.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit tests to verify the code.
  • Run mvn clean test to make sure this pull request doesn't break anything.

@@ -89,7 +89,7 @@ private boolean checkTimestamp(String timestamp) {
}

long x = System.currentTimeMillis() - requestTimeMillis;
return x <= TIMESTAMP_INTERVAL;
return x >= -TIMESTAMP_INTERVAL && x <= TIMESTAMP_INTERVAL;
Copy link
Member

Choose a reason for hiding this comment

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

Please add a unit test for this logic in case it is mistakenly modified in the future

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unit Test 已添加

@codecov-io
Copy link

codecov-io commented Apr 25, 2020

Codecov Report

Merging #3029 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #3029   +/-   ##
=========================================
  Coverage     51.25%   51.25%           
- Complexity     2230     2231    +1     
=========================================
  Files           432      432           
  Lines         13382    13382           
  Branches       1374     1374           
=========================================
  Hits           6859     6859           
  Misses         6047     6047           
  Partials        476      476           
Impacted Files Coverage Δ Complexity Δ
...nfigservice/filter/ClientAuthenticationFilter.java 91.30% <100.00%> (ø) 14.00 <0.00> (+1.00)

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 c81dd6d...eb4a927. Read the comment docs.

@liuzhijiang liuzhijiang force-pushed the lzj/fix_checktimestamp branch from 66bf44e to fea27c7 Compare April 25, 2020 15:45
@liuzhijiang liuzhijiang force-pushed the lzj/fix_checktimestamp branch from fea27c7 to 0b42e5c Compare April 25, 2020 15:52
Copy link
Member

@nobodyiam nobodyiam left a comment

Choose a reason for hiding this comment

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

LGTM

@nobodyiam nobodyiam merged commit e4d41da into apolloconfig:master May 2, 2020
@nobodyiam nobodyiam added this to the 1.7.0 milestone Jun 25, 2020
@zhaolin81
Copy link

why not make TIMESTAMP_INTERVAL configable,1 minute is too strick

@nobodyiam
Copy link
Member

@zhaolin81 I think it's better to make it configurable.

@zhaolin81
Copy link

zhaolin81 commented Aug 22, 2020 via email

@nisiyong
Copy link
Member

Sorry to see this PR now.

This implement was written by me, I once realized that TIMESTAMP_INTERVAL=60s is not the best way, and I agreed with what @zhaolin81 said, to make it configurable!

I don't agree with this PR solution. Maybe we can polish this logic soon.

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.

5 participants