1
0
mirror of https://github.com/square/okhttp.git synced 2025-11-23 06:42:24 +03:00

Avoid InetAddress.getCanonicalHostName(). (#7607)

Just hard-coding 'localhost' is simpler and avoids problems where
the host machine's IP address has additional DNS registrations.

Closes: https://github.com/square/okhttp/issues/7603
This commit is contained in:
Jesse Wilson
2023-01-02 09:04:37 -05:00
committed by GitHub
parent eba89ae4a0
commit 847b5af240
7 changed files with 10 additions and 15 deletions

View File

@@ -45,13 +45,11 @@ import org.opentest4j.TestAbortedException
*/
@ExtendWith(MockWebServerExtension::class)
class AndroidAsyncDnsTest {
private val localhostName: String = InetAddress.getByName("localhost").canonicalHostName
private val localhost: HandshakeCertificates by lazy {
// Generate a self-signed cert for the server to serve and the client to trust.
val heldCertificate = HeldCertificate.Builder()
.commonName("localhost")
.addSubjectAlternativeName(localhostName)
.addSubjectAlternativeName("localhost")
.build()
return@lazy HandshakeCertificates.Builder()
.addPlatformTrustedCertificates()
@@ -111,7 +109,7 @@ class AndroidAsyncDnsTest {
@Test
@Disabled("No results on CI for localhost")
fun testDnsRequest() {
val (allAddresses, exception) = dnsQuery(localhostName)
val (allAddresses, exception) = dnsQuery("localhost")
assertThat(exception).isNull()
assertThat(allAddresses).isNotEmpty