Upgrade OkHttp to 4.12.

Addresses #13491
This commit is contained in:
Nicholas Tinsley 2024-06-17 17:51:19 -04:00 committed by Greyson Parrelli
parent 9824cc2cbe
commit 8ba57a2733
11 changed files with 68 additions and 62 deletions

View file

@ -58,18 +58,21 @@ class InstrumentationApplicationDependencyProvider(val application: Application,
Get("/v1/websocket/?login=") {
MockResponse().success().withWebSocketUpgrade(mockIdentifiedWebSocket)
},
Get("/v1/websocket", { !it.path.contains("login") }) {
Get("/v1/websocket", {
val path = it.path
return@Get path == null || !path.contains("login")
}) {
MockResponse().success().withWebSocketUpgrade(object : WebSocketListener() {})
}
)
}
webServer.setDispatcher(object : Dispatcher() {
webServer.dispatcher = object : Dispatcher() {
override fun dispatch(request: RecordedRequest): MockResponse {
val handler = handlers.firstOrNull { it.requestPredicate(request) }
return handler?.responseFactory?.invoke(request) ?: MockResponse().setResponseCode(500)
}
})
}
serviceTrustStore = SignalServiceTrustStore(application)
uncensoredConfiguration = SignalServiceConfiguration(

View file

@ -55,5 +55,5 @@ inline fun <reified T> RecordedRequest.parsedRequestBody(): T {
}
private fun defaultRequestPredicate(verb: String, path: String, predicate: RequestPredicate = { true }): RequestPredicate = { request ->
request.method == verb && request.path.startsWith("/$path") && predicate(request)
request.method == verb && request.path?.startsWith("/$path") == true && predicate(request)
}

View file

@ -67,10 +67,10 @@ class ApkUpdateJob private constructor(parameters: Parameters) : BaseJob(paramet
val request = Request.Builder().url(BuildConfig.APK_UPDATE_MANIFEST_URL).build()
val rawUpdateDescriptor: String = client.newCall(request).execute().use { response ->
if (!response.isSuccessful || response.body() == null) {
if (!response.isSuccessful || response.body == null) {
throw IOException("Failed to read update descriptor")
}
response.body()!!.string()
response.body!!.string()
}
val updateDescriptor: UpdateDescriptor = JsonUtils.fromJson(rawUpdateDescriptor, UpdateDescriptor::class.java)

View file

@ -400,7 +400,7 @@ class AttachmentDownloadJob private constructor(
) {
try {
S3.getObject(attachment.fileName!!).use { response ->
val body = response.body()
val body = response.body
if (body != null) {
if (body.contentLength() > RemoteConfig.maxAttachmentReceiveSizeBytes) {
throw MmsException("Attachment too large, failing download")

View file

@ -42,7 +42,7 @@ class FetchRemoteMegaphoneImageJob(parameters: Parameters, private val uuid: Str
override fun onRun() {
try {
S3.getObject(imageUrl).use { response ->
val body: ResponseBody? = response.body()
val body: ResponseBody? = response.body
if (body != null) {
val uri = BlobProvider.getInstance()
.forData(body.byteStream(), body.contentLength())

View file

@ -53,10 +53,10 @@ object S3 {
fun getString(endpoint: String): String {
getObject(endpoint).use { response ->
if (!response.isSuccessful) {
throw NonSuccessfulResponseCodeException(response.code())
throw NonSuccessfulResponseCodeException(response.code)
}
return response.body()?.string()?.trim() ?: throw IOException()
return response.body?.string()?.trim() ?: throw IOException()
}
}
@ -110,13 +110,13 @@ object S3 {
getObject(endpoint).use { response ->
if (!response.isSuccessful) {
return ServiceResponse.forApplicationError(
DefaultErrorMapper.getDefault().parseError(response.code()),
response.code(),
DefaultErrorMapper.getDefault().parseError(response.code),
response.code,
""
)
}
val source = response.body()?.source()
val source = response.body?.source()
val outputStream = ByteArrayOutputStream()
@ -166,7 +166,7 @@ object S3 {
}
getObject(objectPathOnNetwork).use { response ->
val source = response.body()?.source()
val source = response.body?.source()
val outputStream: OutputStream = if (doNotEncrypt) {
FileOutputStream(objectFileOnDisk)

View file

@ -1,6 +1,6 @@
package org.thoughtcrime.securesms.util
import okhttp3.HttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import org.thoughtcrime.securesms.stickers.StickerUrl
import java.net.URI
import java.net.URISyntaxException
@ -43,7 +43,7 @@ object LinkUtil {
return false
}
return HttpUrl.parse(linkUrl)?.scheme() == "https"
return linkUrl.toHttpUrlOrNull()?.scheme == "https"
}
/**

View file

@ -129,8 +129,8 @@ dependencyResolutionManagement {
library("greenrobot-eventbus", "org.greenrobot:eventbus:3.0.0")
library("jackson-core", "com.fasterxml.jackson.core:jackson-databind:2.9.9.2")
library("jackson-module-kotlin", "com.fasterxml.jackson.module:jackson-module-kotlin:2.12.0")
library("square-okhttp3", "com.squareup.okhttp3:okhttp:3.12.13")
library("square-okio", "com.squareup.okio:okio:3.0.0")
library("square-okhttp3", "com.squareup.okhttp3:okhttp:4.12.0")
library("square-okio", "com.squareup.okio:okio:3.6.0")
library("square-leakcanary", "com.squareup.leakcanary:leakcanary-android:2.7")
library("rxjava3-rxjava", "io.reactivex.rxjava3:rxjava:3.0.13")
library("rxjava3-rxandroid", "io.reactivex.rxjava3:rxandroid:3.0.0")
@ -199,7 +199,7 @@ dependencyResolutionManagement {
library("bouncycastle-bcpkix-jdk15on", "org.bouncycastle:bcpkix-jdk15on:1.70")
library("hamcrest-hamcrest", "org.hamcrest:hamcrest:2.2")
library("assertj-core", "org.assertj:assertj-core:3.11.1")
library("square-okhttp-mockserver", "com.squareup.okhttp3:mockwebserver:3.12.13")
library("square-okhttp-mockserver", "com.squareup.okhttp3:mockwebserver:4.12.0")
library("mockk", "io.mockk:mockk:1.13.2")
library("mockk-android", "io.mockk:mockk-android:1.13.2")

View file

@ -146,7 +146,7 @@ class StripeApi(
fun getSetupIntent(stripeIntentAccessor: StripeIntentAccessor): StripeSetupIntent {
return when (stripeIntentAccessor.objectType) {
StripeIntentAccessor.ObjectType.SETUP_INTENT -> get("setup_intents/${stripeIntentAccessor.intentId}?client_secret=${stripeIntentAccessor.intentClientSecret}&expand[0]=latest_attempt").use {
val body = it.body()?.string()
val body = it.body?.string()
try {
objectMapper.readValue(body!!)
} catch (e: InvalidDefinitionException) {
@ -168,7 +168,7 @@ class StripeApi(
fun getPaymentIntent(stripeIntentAccessor: StripeIntentAccessor): StripePaymentIntent {
return when (stripeIntentAccessor.objectType) {
StripeIntentAccessor.ObjectType.PAYMENT_INTENT -> get("payment_intents/${stripeIntentAccessor.intentId}?client_secret=${stripeIntentAccessor.intentClientSecret}").use {
val body = it.body()?.string()
val body = it.body?.string()
try {
Log.d(TAG, "Reading StripePaymentIntent from JSON")
objectMapper.readValue(body!!)
@ -186,7 +186,7 @@ class StripeApi(
}
private fun getNextAction(response: Response): Pair<Uri, Uri> {
val responseBody = response.body()?.string()
val responseBody = response.body?.string()
val bodyJson = responseBody?.let { JSONObject(it) }
return if (bodyJson?.has("next_action") == true && !bodyJson.isNull("next_action")) {
val nextAction = bodyJson.getJSONObject("next_action")
@ -230,12 +230,8 @@ class StripeApi(
)
postForm("tokens", parameters).use { response ->
val body = response.body()
if (body != null) {
return CreditCardPaymentSource(JSONObject(body.string()))
} else {
throw StripeError.FailedToCreatePaymentSourceFromCardData
}
val body = response.body ?: throw StripeError.FailedToCreatePaymentSourceFromCardData
return CreditCardPaymentSource(JSONObject(body.string()))
}
}
@ -247,13 +243,9 @@ class StripeApi(
}
return paymentMethodResponse.use { response ->
val body = response.body()
if (body != null) {
val paymentMethodObject = body.string().replace("\n", "").let { JSONObject(it) }
paymentMethodObject.getString("id")
} else {
throw StripeError.FailedToParsePaymentMethodResponseError
}
val body = response.body ?: throw StripeError.FailedToParsePaymentMethodResponseError
val paymentMethodObject = body.string().replace("\n", "").let { JSONObject(it) }
paymentMethodObject.getString("id")
}
}
@ -320,18 +312,18 @@ class StripeApi(
if (response.isSuccessful) {
return response
} else {
val body = response.body()?.string()
val body = response.body?.string()
val errorCode = parseErrorCode(body)
val declineCode = parseDeclineCode(body) ?: StripeDeclineCode.getFromCode(errorCode)
val failureCode = parseFailureCode(body) ?: StripeFailureCode.getFromCode(errorCode)
if (failureCode is StripeFailureCode.Known) {
throw StripeError.PostError.Failed(response.code(), failureCode)
throw StripeError.PostError.Failed(response.code, failureCode)
} else if (declineCode is StripeDeclineCode.Known) {
throw StripeError.PostError.Declined(response.code(), declineCode)
throw StripeError.PostError.Declined(response.code, declineCode)
} else {
throw StripeError.PostError.Generic(response.code(), errorCode)
throw StripeError.PostError.Generic(response.code, errorCode)
}
}
}

View file

@ -5741,24 +5741,20 @@ https://docs.gradle.org/current/userguide/dependency_verification.html
<sha256 value="676eb608f56199dff11c9c9d68e078e7768c54e60080e7ae12db8ec8e120675b" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.squareup.okhttp" name="okhttp" version="2.5.0">
<artifact name="okhttp-2.5.0.jar">
<sha256 value="1cc716e29539adcda677949508162796daffedb4794cbf947a6f65e696f0381c" origin="Generated by Gradle"/>
<component group="com.squareup.okhttp3" name="mockwebserver" version="4.12.0">
<artifact name="mockwebserver-4.12.0.jar">
<sha256 value="6784673687f4ac8f21679b9d4bc7cdb46e1a1ce1be9d3133b36bede59a741561" origin="Generated by Gradle"/>
</artifact>
<artifact name="mockwebserver-4.12.0.module">
<sha256 value="93e4696552118b6425462aed936edfd320c9fcedef0a82d5741c0a7d53c0cf74" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.squareup.okhttp" name="okhttp-urlconnection" version="2.5.0">
<artifact name="okhttp-urlconnection-2.5.0.jar">
<sha256 value="79ec6f4e79e683105e87fe83278a531c693e538d30e3b9237000ce7c94fcb2cf" origin="Generated by Gradle"/>
<component group="com.squareup.okhttp3" name="okhttp" version="4.12.0">
<artifact name="okhttp-4.12.0.jar">
<sha256 value="b1050081b14bb7a3a7e55a4d3ef01b5dcfabc453b4573a4fc019767191d5f4e0" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.squareup.okhttp3" name="mockwebserver" version="3.12.13">
<artifact name="mockwebserver-3.12.13.jar">
<sha256 value="ec92604c885f37eede54cd8504c871a5163616d94074f34ce27184845e7cfd4c" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.squareup.okhttp3" name="okhttp" version="3.12.13">
<artifact name="okhttp-3.12.13.jar">
<sha256 value="508234e024ef7e270ab1a6d5b356f5b98e786511239ca986d684fd1e2cf7bc82" origin="Generated by Gradle"/>
<artifact name="okhttp-4.12.0.module">
<sha256 value="607e220ff8215b929d829bbf54f332894f1459b4d795979aeafcbcc1cea54cf3" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.squareup.okio" name="okio" version="1.15.0">
@ -5766,11 +5762,6 @@ https://docs.gradle.org/current/userguide/dependency_verification.html
<sha256 value="693fa319a7e8843300602b204023b7674f106ebcb577f2dd5807212b66118bd2" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.squareup.okio" name="okio" version="1.6.0">
<artifact name="okio-1.6.0.jar">
<sha256 value="114bdc1f47338a68bcbc95abf2f5cdc72beeec91812f2fcd7b521c1937876266" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.squareup.okio" name="okio" version="2.8.0">
<artifact name="okio-2.8.0.module">
<sha256 value="17baab7270389a5fa63ab12811864d0a00f381611bc4eb042fa1bd5918ed0965" origin="Generated by Gradle"/>
@ -5787,6 +5778,14 @@ https://docs.gradle.org/current/userguide/dependency_verification.html
<sha256 value="dcbe63ed43b2c90c325e9e6a0863e2e7605980bff5e728c6de1088be5574979e" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.squareup.okio" name="okio" version="3.6.0">
<artifact name="okio-3.6.0.module">
<sha256 value="6a47ac50364e6598459401fb86f9b6cfcdf637b9b3a3045b1cc33cbf4c408218" origin="Generated by Gradle"/>
</artifact>
<artifact name="okio-metadata-3.6.0-all.jar">
<sha256 value="2bbd3f0645a3ada7e6532b2e6db471af4861464e1a140f95f807dfd16aa049e3" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.squareup.okio" name="okio-bom" version="3.0.0">
<artifact name="okio-bom-3.0.0.module">
<sha256 value="fb5d398df7754d9a95279ff09f1292ebf8dc145008f046a2710c07637aff0e69" origin="Generated by Gradle"/>
@ -5800,6 +5799,14 @@ https://docs.gradle.org/current/userguide/dependency_verification.html
<sha256 value="17f48d41775bd84dea78e9dfed8dfbcc66af80567a5c9ec9d9608785ec820cde" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.squareup.okio" name="okio-jvm" version="3.6.0">
<artifact name="okio-jvm-3.6.0.jar">
<sha256 value="67543f0736fc422ae927ed0e504b98bc5e269fda0d3500579337cb713da28412" origin="Generated by Gradle"/>
</artifact>
<artifact name="okio-jvm-3.6.0.module">
<sha256 value="b1c2199e1c0cc969ef61cbbe4af2ecaf9b06411bdde01cbaf6fc9134dfe04e8a" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.squareup.okio" name="okio-multiplatform" version="2.8.0">
<artifact name="okio-multiplatform-2.8.0.module">
<sha256 value="87c4327538ba166a914171631470a6e9db2b007125bae164af6b0d47aefd34d7" origin="Generated by Gradle"/>

View file

@ -1,8 +1,8 @@
package org.whispersystems.signalservice.internal.push.http
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody
import okhttp3.internal.http.UnrepeatableRequestBody
import okio.BufferedSink
import org.signal.libsignal.protocol.incrementalmac.ChunkSizeChoice
import org.signal.libsignal.protocol.logging.Log
@ -26,7 +26,7 @@ class DigestingRequestBody(
private val progressListener: SignalServiceAttachment.ProgressListener?,
private val cancelationSignal: CancelationSignal?,
private val contentStart: Long
) : RequestBody(), UnrepeatableRequestBody {
) : RequestBody() {
var attachmentDigest: AttachmentDigest? = null
init {
@ -35,7 +35,7 @@ class DigestingRequestBody(
}
override fun contentType(): MediaType? {
return MediaType.parse(contentType)
return contentType.toMediaTypeOrNull()
}
@Throws(IOException::class)
@ -85,6 +85,10 @@ class DigestingRequestBody(
return if (contentLength > 0) contentLength - contentStart else -1
}
override fun isOneShot(): Boolean {
return true
}
private fun logMessage(actual: Long, expected: Long): String {
val difference = actual - expected
return if (difference > 0) {