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

Support changing Clock to control time in testing with embedded server #581

Closed
xuan-dai-nguyen-db opened this issue Nov 1, 2023 · 7 comments · Fixed by #668
Closed

Support changing Clock to control time in testing with embedded server #581

xuan-dai-nguyen-db opened this issue Nov 1, 2023 · 7 comments · Fixed by #668
Labels
enhancement New feature or request

Comments

@xuan-dai-nguyen-db
Copy link

xuan-dai-nguyen-db commented Nov 1, 2023

Currently the library uses system clock to calculate time related fields when issue/validate token.
It would be nice if use-site could set the java.time.Clock instance to control timing behaviours of mock-oauth2-server in tests.

@ybelMekk ybelMekk added the enhancement New feature or request label Nov 3, 2023
@xuan-dai-nguyen-db
Copy link
Author

xuan-dai-nguyen-db commented Dec 13, 2023

Hi, is there any update on this.

I think this is quite a blocker in testing.
Manipulating clock is required very often in testing, but this will make integration tests fail just because of invalid token, which is irrelevant to the content of the tests.

For example, we have a spring boot application.
In the system, we have a clock bean (default system clock), which can be replaced by another clock bean in tests.
The whole application always injects the clock bean and never use system clock directly, including OAuth2 Jwt verification.

Now in integration tests, we change time of clock bean to a fixed time 10 years ago, for example.
The spring security configuration will block the token generated by mock-oauth2-server.

@kvokacka
Copy link
Contributor

kvokacka commented Feb 9, 2024

Hello,
is anybody working on this?
Can we also add HTTP endpoint to be able to set clock when running mock-oauth2-server as docker container please?

Copy link

github-actions bot commented Apr 9, 2024

This issue is stale because it has been open for 60 days with no activity.

@github-actions github-actions bot added the stale label Apr 9, 2024
@ybelMekk ybelMekk removed the stale label Apr 12, 2024
@ybelMekk
Copy link
Contributor

Hei, nothing planned.. can have a look :)

@tommytroen
Copy link
Collaborator

@xuan-dai-nguyen-db you should be able to override the issue time in the token by setting the time in the OAuth2TokenProvider in #668, see README for an example.

@kvokacka #668 lets you configure the system time with JSON config for the docker container.

@xuan-dai-nguyen-db
Copy link
Author

Amazing! Thanks @tommytroen!

@xuan-dai-nguyen-db
Copy link
Author

xuan-dai-nguyen-db commented Apr 30, 2024

@tommytroen with this change, is it possible to set time after running the embedded server?
For example, I would like to use system clock to start the embedded server when Spring App starts.
For test A, I want to issue a token with running system time.
For test B, I want to issue a token with a fixed time in 01.01.2000.
For test C, I want to issue a token with a fixed time in 01.01.2020.

Do I need to create a custom OAuth2TokenProvider in this case? If yes, do you have any suggestion for the implementation of custom OAuth2TokenProvider?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants