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 #27 by using java.util.Date for storing expiration time #50

Merged
merged 1 commit into from
Aug 31, 2023

Conversation

gerdint
Copy link
Contributor

@gerdint gerdint commented Aug 15, 2023

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

Copy link
Owner

@weavejester weavejester left a 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.

Comment on lines 8 to 9
(:import (java.time Instant)
(java.util Date)))
Copy link
Owner

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])

Comment on lines 47 to 50
(defn seconds-from-now-to-date [secs]
(-> (Instant/now)
(.plusSeconds secs)
(Date/from)))
Copy link
Owner

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)))

@@ -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)]
Copy link
Owner

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)]

@@ -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)]
Copy link
Owner

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.

@gerdint
Copy link
Contributor Author

gerdint commented Aug 16, 2023

@weavejester I amended the commit with the requested changes

Copy link
Owner

@weavejester weavejester left a 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.

@@ -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)]
Copy link
Owner

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))

Copy link
Contributor Author

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?

Copy link
Owner

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.

Copy link
Contributor Author

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.

Copy link
Owner

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?

Copy link
Contributor Author

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.

Copy link
Owner

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?

Copy link
Contributor Author

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.

Copy link
Owner

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.

@jamiepratt
Copy link

jamiepratt commented Aug 16, 2023 via email

@weavejester
Copy link
Owner

Looks good! Can you squash your commits, and it should be ready to merge.

@gerdint
Copy link
Contributor Author

gerdint commented Aug 28, 2023

Squashed

@weavejester
Copy link
Owner

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.
@gerdint
Copy link
Contributor Author

gerdint commented Aug 29, 2023

Oh sorry, I thought I had removed that. Fixed now.

@gerdint
Copy link
Contributor Author

gerdint commented Aug 31, 2023

@weavejester Anything else?

@weavejester weavejester merged commit f8727c3 into weavejester:master Aug 31, 2023
1 check passed
@weavejester
Copy link
Owner

Nope! That's all good. Thanks for your work on this.

@gerdint
Copy link
Contributor Author

gerdint commented Sep 1, 2023

@weavejester Good. Perhaps it would be worth making a 0.2.1 release with this fix since it seemed like a highly anticipated change.

@gerdint gerdint deleted the feature/java-time-date branch September 1, 2023 11:11
@weavejester
Copy link
Owner

Released 0.2.1.

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.

3 participants