-
Notifications
You must be signed in to change notification settings - Fork 38
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 #27 by using java.util.Date for storing expiration time #50
Fix #27 by using java.util.Date for storing expiration time #50
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. Just some minor formatting changes for consistency are required, plus changing the new function to private as its not part of the API.
Could you also change the commit message to:
Replace clj-time with native java.time (fixes #27)
Updates minimum required Java version to 8 due to use of java.time.Instant.
src/ring/middleware/oauth2.clj
Outdated
(:import (java.time Instant) | ||
(java.util Date))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use square brackets here, i.e.
(:import [java.time Instant]
[java.util Date])
src/ring/middleware/oauth2.clj
Outdated
(defn seconds-from-now-to-date [secs] | ||
(-> (Instant/now) | ||
(.plusSeconds secs) | ||
(Date/from))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function body probably all be on one line without losing clarity, and should be a private function as it's not part of the public API:
(defn- seconds-from-now-to-date [secs]
(-> (Instant/now) (.plusSeconds secs) (Date/from)))
test/ring/middleware/oauth2_test.clj
Outdated
@@ -75,12 +74,12 @@ | |||
(assoc :session {::oauth2/state "xyzxyz"}) | |||
(assoc :query-params {"code" "abcabc", "state" "xyzxyz"})) | |||
response (test-handler request) | |||
expires (-> 3600 time/seconds time/from-now)] | |||
expires (oauth2/seconds-from-now-to-date 3600)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you align it to match the removed like? So:
response (test-handler request)
expires (oauth2/seconds-from-now-to-date 3600)]
test/ring/middleware/oauth2_test.clj
Outdated
@@ -130,12 +129,13 @@ | |||
request (-> (mock/request :get "/oauth2/test/callback") | |||
(assoc :session {::oauth2/state "xyzxyz"}) | |||
(assoc :query-params {"code" "abcabc", "state" "xyzxyz"})) | |||
response (handler request)] | |||
response (handler request) | |||
expires (oauth2/seconds-from-now-to-date 3600)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response (handler request)
expires (oauth2/seconds-from-now-to-date 3600)
Align vars to be consistent with other lines in the let form.
6bb0174
to
631ef60
Compare
631ef60
to
ad4fb13
Compare
@weavejester I amended the commit with the requested changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there! Just one more change necessary to avoid tying the tests to private functions.
test/ring/middleware/oauth2_test.clj
Outdated
@@ -75,12 +74,12 @@ | |||
(assoc :session {::oauth2/state "xyzxyz"}) | |||
(assoc :query-params {"code" "abcabc", "state" "xyzxyz"})) | |||
response (test-handler request) | |||
expires (-> 3600 time/seconds time/from-now)] | |||
expires (#'oauth2/seconds-from-now-to-date 3600)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accessing a private var here saves a little code, but also ties the test case to the internals of the namespace being tested. Ideally we test only the public API. So instead, just inline the function:
expires (-> (Instant/now) (.plusSeconds 3600) (Date/from))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, though since identical code is used at four places in the test suite I might as well introduce a helper function for it in the tests I guess?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I mind. You could duplicate seconds-from-now-to-date
in the test namespace if you wanted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did it the other way, see what you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That works, too. Can you ensure that the lines modified in ring.middleware.oauth are within 80 characters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the modified lines are all within 80 characters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's one line in your patch that might be 85?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you perhaps noted the 2nd commit made that like shorter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, weird. Is the GitHub diff incorrect then? In any case, it looks like there are other lines over from previous commits, so I can always fix it with a later formatting commit. I just need the commits to be squashed down and then we're ready to merge.
Haven't had time to look at the code, but thanks for the work bringing it
up to par and merging this!
Jamie
--
*My homepage* <https://jamiep.org/> and *resume*
<https://www.jamiep.org/work/james-robert-pratt/>.
Phone no: *+48505206918 <https://wa.me/48505206918> (link messages me on
WhatsApp)*
Skype Name: *jamiepratt <https://join.skype.com/invite/ben7orDUhbwH>*
…On Wed, 16 Aug 2023 at 11:04, James Reeves ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In test/ring/middleware/oauth2_test.clj
<#50 (comment)>
:
> @@ -75,12 +74,12 @@
(assoc :session {::oauth2/state "xyzxyz"})
(assoc :query-params {"code" "abcabc", "state" "xyzxyz"}))
response (test-handler request)
- expires (-> 3600 time/seconds time/from-now)]
+ expires (#'oauth2/seconds-from-now-to-date 3600)]
I don't think I mind. You could duplicate seconds-from-now-to-date in the
test namespace if you wanted.
—
Reply to this email directly, view it on GitHub
<#50 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEINPDUCHJX2LQKGTAQCATXVSELXANCNFSM6AAAAAA3RDCVHM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Looks good! Can you squash your commits, and it should be ready to merge. |
f3907ea
to
a4aac7c
Compare
Squashed |
Thanks! Can you also fix the commit message? It has "Implement changes from review feedback" added to the end of it now. |
Requires Java 8 due to use of java.time.
a4aac7c
to
82a7d1b
Compare
Oh sorry, I thought I had removed that. Fixed now. |
@weavejester Anything else? |
Nope! That's all good. Thanks for your work on this. |
@weavejester Good. Perhaps it would be worth making a 0.2.1 release with this fix since it seemed like a highly anticipated change. |
Released 0.2.1. |
Hopefully we can get this fix merged soonish, this is the 3rd PR regarding this.
The testing code changes are copied from PR #47, I hope @jamiepratt does not mind.
Requires Java 8 due to use of java.time.Instant in code for clarity