Skip to content
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 @@ -248,9 +248,11 @@ class OkHttpTest {
// Conscrypt 2.5+ defaults to SSLEngine-based SSLSocket
assertEquals("org.conscrypt.Java8EngineSocket", socketClass)
}

Build.VERSION.SDK_INT < 22 -> {
assertEquals("org.conscrypt.KitKatPlatformOpenSSLSocketImplAdapter", socketClass)
}

else -> {
assertEquals("org.conscrypt.ConscryptFileDescriptorSocket", socketClass)
}
Expand Down Expand Up @@ -856,6 +858,7 @@ class OkHttpTest {
is IllegalArgumentException -> {
assertEquals("Android internal error", ioe.message)
}

is CertificateException -> {
assertTrue(ioe.cause?.cause is IllegalArgumentException)
assertEquals(
Expand All @@ -866,7 +869,10 @@ class OkHttpTest {
?.startsWith("Invalid input to toASCII"),
)
}
else -> throw ioe

else -> {
throw ioe
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ configure<SpotlessExtension> {
kotlin {
target("**/*.kt")
targetExclude("**/kotlinTemplates/**/*.kt")
targetExclude("**/generated-sources/**/*.kt")
ktlint()
suppressLintsFor {
step = "ktlint"
shortCode = "standard:mixed-condition-operators"
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ gradlePlugin-mavenPublish = "com.vanniktech:gradle-maven-publish-plugin:0.36.0"
gradlePlugin-mavenSympathy = "io.github.usefulness.maven-sympathy:io.github.usefulness.maven-sympathy.gradle.plugin:0.3.0"
gradlePlugin-mrjar = "me.champeau.mrjar:me.champeau.mrjar.gradle.plugin:0.1.1"
gradlePlugin-shadow = "com.gradleup.shadow:shadow-gradle-plugin:9.3.1"
gradlePlugin-spotless = "com.diffplug.spotless:spotless-plugin-gradle:8.1.0"
gradlePlugin-spotless = "com.diffplug.spotless:spotless-plugin-gradle:8.2.0"
hamcrestLibrary = "org.hamcrest:hamcrest-library:3.0"
httpClient5 = "org.apache.httpcomponents.client5:httpclient5:5.5.2"
#noinspection NewerVersionAvailable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,34 +58,79 @@ internal fun MockResponse.wrap(): mockwebserver3.MockResponse {
result.trailers(trailers)

when (socketPolicy) {
SocketPolicy.EXPECT_CONTINUE, SocketPolicy.CONTINUE_ALWAYS -> result.add100Continue()
SocketPolicy.UPGRADE_TO_SSL_AT_END -> result.inTunnel()
SocketPolicy.SHUTDOWN_SERVER_AFTER_RESPONSE -> result.shutdownServer(true)
SocketPolicy.KEEP_OPEN -> Unit
SocketPolicy.DISCONNECT_AT_END -> result.onResponseEnd(ShutdownConnection)
SocketPolicy.DISCONNECT_AT_START -> result.onRequestStart(CloseSocket())
SocketPolicy.DISCONNECT_AFTER_REQUEST -> result.onResponseStart(CloseSocket())
SocketPolicy.DISCONNECT_DURING_REQUEST_BODY -> result.onRequestBody(CloseSocket())
SocketPolicy.DISCONNECT_DURING_RESPONSE_BODY -> result.onResponseBody(CloseSocket())
SocketPolicy.DO_NOT_READ_REQUEST_BODY -> result.doNotReadRequestBody()
SocketPolicy.FAIL_HANDSHAKE -> result.failHandshake()
SocketPolicy.SHUTDOWN_INPUT_AT_END ->
SocketPolicy.EXPECT_CONTINUE, SocketPolicy.CONTINUE_ALWAYS -> {
result.add100Continue()
}

SocketPolicy.UPGRADE_TO_SSL_AT_END -> {
result.inTunnel()
}

SocketPolicy.SHUTDOWN_SERVER_AFTER_RESPONSE -> {
result.shutdownServer(true)
}

SocketPolicy.KEEP_OPEN -> {
Unit
}

SocketPolicy.DISCONNECT_AT_END -> {
result.onResponseEnd(ShutdownConnection)
}

SocketPolicy.DISCONNECT_AT_START -> {
result.onRequestStart(CloseSocket())
}

SocketPolicy.DISCONNECT_AFTER_REQUEST -> {
result.onResponseStart(CloseSocket())
}

SocketPolicy.DISCONNECT_DURING_REQUEST_BODY -> {
result.onRequestBody(CloseSocket())
}

SocketPolicy.DISCONNECT_DURING_RESPONSE_BODY -> {
result.onResponseBody(CloseSocket())
}

SocketPolicy.DO_NOT_READ_REQUEST_BODY -> {
result.doNotReadRequestBody()
}

SocketPolicy.FAIL_HANDSHAKE -> {
result.failHandshake()
}

SocketPolicy.SHUTDOWN_INPUT_AT_END -> {
result.onResponseEnd(
CloseSocket(
closeSocket = false,
shutdownInput = true,
),
)
SocketPolicy.SHUTDOWN_OUTPUT_AT_END ->
}

SocketPolicy.SHUTDOWN_OUTPUT_AT_END -> {
result.onResponseEnd(
CloseSocket(
closeSocket = false,
shutdownOutput = true,
),
)
SocketPolicy.STALL_SOCKET_AT_START -> result.onRequestStart(SocketEffect.Stall)
SocketPolicy.NO_RESPONSE -> result.onResponseStart(SocketEffect.Stall)
SocketPolicy.RESET_STREAM_AT_START -> result.onRequestStart(CloseStream(http2ErrorCode))
}

SocketPolicy.STALL_SOCKET_AT_START -> {
result.onRequestStart(SocketEffect.Stall)
}

SocketPolicy.NO_RESPONSE -> {
result.onResponseStart(SocketEffect.Stall)
}

SocketPolicy.RESET_STREAM_AT_START -> {
result.onRequestStart(CloseStream(http2ErrorCode))
}
}

result.throttleBody(throttleBytesPerPeriod, getThrottlePeriod(MILLISECONDS), MILLISECONDS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ public class MockWebServer : Closeable {
}
openClientSockets.remove(raw)
}

else -> {
protocol =
when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,25 @@ fun buildIdnaMappingTableData(table: SimpleIdnaMappingTable): IdnaMappingTableDa
rangesBuffer.writeByte('-'.code)
rangesBuffer.writeByte('-'.code)
}

is MappedRange.Inline1 -> {
rangesBuffer.writeByte(range.b1)
rangesBuffer.writeByte(range.b2)
rangesBuffer.writeByte('-'.code)
}

is MappedRange.Inline2 -> {
rangesBuffer.writeByte(range.b1)
rangesBuffer.writeByte(range.b2)
rangesBuffer.writeByte(range.b3)
}

is MappedRange.InlineDelta -> {
rangesBuffer.writeByte(range.b1)
rangesBuffer.writeByte(range.b2)
rangesBuffer.writeByte(range.b3)
}

is MappedRange.External -> {
// Write the mapping.
val mappingOffset: Int
Expand Down Expand Up @@ -141,7 +145,7 @@ internal fun sections(mappings: List<Mapping>): Map<Int, List<MappedRange>> {

sectionList +=
when (mapping.type) {
TYPE_MAPPED ->
TYPE_MAPPED -> {
run {
val deltaMapping = inlineDeltaOrNull(mapping)
if (deltaMapping != null) {
Expand All @@ -154,12 +158,15 @@ internal fun sections(mappings: List<Mapping>): Map<Int, List<MappedRange>> {
else -> MappedRange.External(rangeStart, mapping.mappedTo)
}
}
}

TYPE_IGNORED, TYPE_VALID, TYPE_DISALLOWED -> {
MappedRange.Constant(rangeStart, mapping.type)
}

else -> error("unexpected mapping type: ${mapping.type}")
else -> {
error("unexpected mapping type: ${mapping.type}")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ class SimpleIdnaMappingTable internal constructor(
var result = true

when (mapping.type) {
TYPE_IGNORED -> Unit
TYPE_IGNORED -> {
Unit
}

TYPE_MAPPED, TYPE_DISALLOWED_STD3_MAPPED -> {
sink.write(mapping.mappedTo)
}
Expand Down Expand Up @@ -142,7 +145,9 @@ private fun BufferedSource.skipWhitespace() {

private fun BufferedSource.skipRestOfLine() {
when (val newline = indexOf('\n'.code.toByte())) {
-1L -> skip(buffer.size) // Exhaust this source.
-1L -> skip(buffer.size)

// Exhaust this source.
else -> skip(newline + 1)
}
}
Expand Down Expand Up @@ -195,7 +200,9 @@ fun BufferedSource.readPlainTextIdnaMappingTable(): SimpleIdnaMappingTable {
readHexadecimalUnsignedLong()
}

else -> sourceCodePoint0
else -> {
sourceCodePoint0
}
}

skipWhitespace()
Expand Down Expand Up @@ -228,9 +235,13 @@ fun BufferedSource.readPlainTextIdnaMappingTable(): SimpleIdnaMappingTable {
}
}

TYPE_DISALLOWED, TYPE_DISALLOWED_STD3_VALID, TYPE_IGNORED, TYPE_VALID -> Unit
TYPE_DISALLOWED, TYPE_DISALLOWED_STD3_VALID, TYPE_IGNORED, TYPE_VALID -> {
Unit
}

else -> throw IOException("unexpected type")
else -> {
throw IOException("unexpected type")
}
}

skipRestOfLine()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ class ServerSentEventReader(
}
}

else -> throw AssertionError()
else -> {
throw AssertionError()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,12 @@ open class EventRecorder(
} else {
eventsForMatching.forEach loop@{
when (e.closes(it)) {
null -> return // no open event
true -> return // found open event
null -> return

// no open event
true -> return

// found open event
false -> return@loop // this is not the open event so continue
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ object JsseDebugLogging {
JsseDebugMessage.Type.Setup, JsseDebugMessage.Type.Encrypted, JsseDebugMessage.Type.Plaintext -> {
println(message.message + " (skipped output)")
}
else -> println(message)

else -> {
println(message)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,12 @@ internal open class RecordingConnectionListener(
} else {
eventSequence.forEach loop@{
when (e.closes(it)) {
null -> return // no open event
true -> return // found open event
null -> return

// no open event
true -> return

// found open event
false -> return@loop // this is not the open event so continue
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/
package okhttp3.testing

@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
/**
* Annotation marking a test as flaky, and requires extra logging and linking against
* a known github issue. This does not ignore the failure.
*/
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class Flaky
Original file line number Diff line number Diff line change
Expand Up @@ -442,13 +442,25 @@ open class PlatformRule
if (property == null) {
property =
when (Platform.get()) {
is ConscryptPlatform -> CONSCRYPT_PROPERTY
is OpenJSSEPlatform -> OPENJSSE_PROPERTY
is Jdk8WithJettyBootPlatform -> CONSCRYPT_PROPERTY
is ConscryptPlatform -> {
CONSCRYPT_PROPERTY
}

is OpenJSSEPlatform -> {
OPENJSSE_PROPERTY
}

is Jdk8WithJettyBootPlatform -> {
CONSCRYPT_PROPERTY
}

is Jdk9Platform -> {
if (isCorrettoInstalled) CORRETTO_PROPERTY else JDK9_PROPERTY
}
else -> JDK8_PROPERTY

else -> {
JDK8_PROPERTY
}
}
}

Expand Down
10 changes: 8 additions & 2 deletions okhttp-tls/src/main/kotlin/okhttp3/tls/HeldCertificate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ class HeldCertificate(
it.canParseAsIpAddress() -> {
generalNameIpAddress to InetAddress.getByName(it).address.toByteString()
}

else -> {
generalNameDnsName to it
}
Expand All @@ -480,16 +481,19 @@ class HeldCertificate(

private fun signatureAlgorithm(signedByKeyPair: KeyPair): AlgorithmIdentifier =
when (signedByKeyPair.private) {
is RSAPrivateKey ->
is RSAPrivateKey -> {
AlgorithmIdentifier(
algorithm = SHA256_WITH_RSA_ENCRYPTION,
parameters = null,
)
else ->
}

else -> {
AlgorithmIdentifier(
algorithm = SHA256_WITH_ECDSA,
parameters = ByteString.EMPTY,
)
}
}

private fun generateKeyPair(): KeyPair =
Expand Down Expand Up @@ -548,10 +552,12 @@ class HeldCertificate(
require(certificatePem == null) { "string includes multiple certificates" }
certificatePem = match.groups[0]!!.value // Keep --BEGIN-- and --END-- for certificates.
}

"PRIVATE KEY" -> {
require(pkcs8Base64 == null) { "string includes multiple private keys" }
pkcs8Base64 = match.groups[2]!!.value // Include the contents only for PKCS8.
}

else -> {
throw IllegalArgumentException("unexpected type: $label")
}
Expand Down
Loading
Loading