fix: properly return an error and use cache for public keys if possible #10590
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Return an error properly if we can't get the public keys.
In addition, ensure the new keys are cached to prevent unneeded hits to the "/hosting/discovery" endpoint, and log when we're requesting new keys.
Steps to reproduce the original issue seems unclear. WOPI requests are expected to come from the WOPI app (OnlyOffice in this case), and those should be the only ones triggering the issue, so it shouldn't be possible that a request to the discovery endpoint fails when the service is making a request. There might be some race condition, but it seems weird.
Related Issue
#10588
Motivation and Context
Wrong error value was causing a panic because we assume we got the keys although it wasn't true.
How Has This Been Tested?
Note that you can adjust the cache time of the public keys with
COLLABORATION_APP_PROOF_DURATION
test 1
-> Only one "requesting new public keys" message is shown (at debug level). Step 2 won't trigger that message assuming the keys are still valid in the cache.
test 2
COLLABORATION_APP_PROOF_DURATION
goes by-> "requesting new public keys" message (at debug level) will show twice
Screenshots (if appropriate):
Types of changes
Checklist: