-
Notifications
You must be signed in to change notification settings - Fork 11
Add timeout for retrieving certificates in test #84
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
Conversation
rfc2822
left a comment
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.
A timeout looks like a good idea, but a socket should have reasonable default timeouts (not infinite). Is this really the cause of the problem?
I see that in #82 the conn.inputStream.read() (which guarantees that the connection is established) of the HttpUrlConnection was replaced by sslSocket.startHandshake(). Do we need this change and can it be related? In the original code, we didn't have to create a socket manually.
Or in other words: can we change it back to conn.inputStream.read() and it works again?
Yes, that should also work. I just wanted to get rid of the deprecations while at it. I think it should work like this, but would you like me to change it back? |
It just looks like a much easier solution that doesn't cause extra work (like thinking about sockets and timeouts), so instead of adding more code, yes, I'd prefer the single-line solution, especially because it's only a helper for testing. For production code I'd avoid There shouldn't be a deprecation of read? Or do you mean the whole |
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.
Pull Request Overview
This PR addresses an infinite runtime issue in CI caused by a previous change to getSiteCertificates. The fix involves adding connect and read timeouts to certificate retrieval and refactoring the test code structure.
- Extracts
TestCertStoreclass into a separate test file for better organization - Replaces the SSLSocket-based certificate retrieval with HttpsURLConnection that includes 5-second timeouts
- Simplifies certificate retrieval logic while maintaining test functionality
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| TestCertStore.kt | New file containing the extracted TestCertStore test implementation, previously embedded in CustomCertManagerTest.kt |
| CustomCertManagerTest.kt | Refactored getSiteCertificates method to use HttpsURLConnection with timeouts instead of raw SSLSocket; removed TestCertStore class and unused imports |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
lib/src/test/java/at/bitfire/cert4android/CustomCertManagerTest.kt
Outdated
Show resolved
Hide resolved
|
Tests are failing, resetting to draft |
b0863be to
9f59985
Compare
|
Sorry about that. I think calling |
rfc2822
left a comment
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.
Minor suggestions
lib/src/test/java/at/bitfire/cert4android/CustomCertManagerTest.kt
Outdated
Show resolved
Hide resolved
lib/src/test/java/at/bitfire/cert4android/CustomCertManagerTest.kt
Outdated
Show resolved
Hide resolved
lib/src/test/java/at/bitfire/cert4android/CustomCertManagerTest.kt
Outdated
Show resolved
Hide resolved
rfc2822
left a comment
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.
Nice 👍🏻
#82 changed the implementation of
getSiteCertificates.The new
getSiteCertificatesimplementation (now in the unit test) creates an SSLSocket and callsstartHandshake()with no connect/read timeouts, so we get infinite run time in CI.To fix this, this PR