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: 404 when getting client domain crl [WPB-11243] #3026

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ class CheckCrlRevocationListUseCase internal constructor(
}
}
}
}
} ?: logger.w("No CRLs found.")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import io.ktor.client.request.setBody
import io.ktor.client.statement.HttpResponse
import io.ktor.http.ContentType
import io.ktor.http.URLBuilder
import io.ktor.http.URLProtocol
import io.ktor.http.Url
import io.ktor.http.contentType
import io.ktor.http.isSuccess
Expand Down Expand Up @@ -262,8 +261,11 @@ class ACMEApiImpl internal constructor(
}

return wrapKaliumResponse {
val httpUrl = if (proxyUrl.isNullOrEmpty()) URLBuilder(url).apply { this.protocol = URLProtocol.HTTP }.build()
else URLBuilder(proxyUrl).apply { this.pathSegments = this.pathSegments.plus(url) }.build()
val crlUrlBuilder: URLBuilder = URLBuilder(url)
val proxyUrlBuilder: URLBuilder? = if (proxyUrl.isNullOrEmpty()) null else URLBuilder(proxyUrl)

val httpUrl = proxyUrlBuilder?.apply { this.pathSegments += crlUrlBuilder.host }?.build()
?: crlUrlBuilder.build()

clearTextTrafficHttpClient.get(httpUrl)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,49 @@ internal class ACMEApiTest : ApiTest() {
}
}

@Test
fun givenProxyAndCrl_whenGettingClientDomainCRL_thenUseProxyUrlWithCRLHostAddedToPath() = runTest {
val crlUrl = "https://crl.wire.com/crl"
val proxyUrl = "https://proxy.wire:9000/proxy"
val expected = "$proxyUrl/crl.wire.com"
val networkClient = mockUnboundNetworkClient(
"",
statusCode = HttpStatusCode.OK,
assertion = {
assertJson()
assertUrlEqual(expected)
assertGet()
assertNoQueryParams()
}
)
val acmeApi: ACMEApi = ACMEApiImpl(networkClient, networkClient)

acmeApi.getClientDomainCRL(url = crlUrl, proxyUrl = proxyUrl).also { actual ->
assertIs<NetworkResponse.Success<CertificateChain>>(actual)
}
}

@Test
fun givenCRLWithHttpsProtocol_whenGettingClientDomainCRL_thenItShouldNotBeChanged() = runTest {
val crlUrl = "https://crl.wire.com/crl"
val expected = crlUrl
val networkClient = mockUnboundNetworkClient(
"",
statusCode = HttpStatusCode.OK,
assertion = {
assertJson()
assertUrlEqual(expected)
assertGet()
assertNoQueryParams()
}
)
val acmeApi: ACMEApi = ACMEApiImpl(networkClient, networkClient)

acmeApi.getClientDomainCRL(url = crlUrl, proxyUrl = null).also { actual ->
assertIs<NetworkResponse.Success<CertificateChain>>(actual)
}
}

companion object {
private const val ACME_DISCOVERY_URL = "https://balderdash.hogwash.work:9000/acme/google-android/directory"
private const val ACME_DIRECTORIES_PATH = "https://balderdash.hogwash.work:9000/acme/google-android/directory"
Expand Down
Loading