Skip to content

Commit fe722ce

Browse files
committed
Update fromKeyStoreFile to take a Path and improve error message from fromKeyStoreResource
1 parent cf74c2d commit fe722ce

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

build.sbt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,13 @@ ThisBuild / mimaBinaryIssueFilters ++= Seq(
355355
"fs2.io.net.DatagramSocketOption.multicastInterface"
356356
),
357357
ProblemFilters.exclude[ReversedMissingMethodProblem]("fs2.io.net.Network.dns"),
358-
ProblemFilters.exclude[ReversedMissingMethodProblem]("fs2.io.net.Network.interfaces")
358+
ProblemFilters.exclude[ReversedMissingMethodProblem]("fs2.io.net.Network.interfaces"),
359+
ProblemFilters.exclude[InheritedNewAbstractMethodProblem](
360+
"fs2.io.net.tls.TLSContext#Builder.fromKeyStoreFile"
361+
),
362+
ProblemFilters.exclude[InheritedNewAbstractMethodProblem](
363+
"fs2.io.net.tls.TLSContext#Builder.fs2$io$net$tls$TLSContextCompanionPlatform$BuilderPlatform$$$outer"
364+
)
359365
)
360366

361367
lazy val root = tlCrossRootProject

io/jvm/src/main/scala/fs2/io/net/tls/TLSContextPlatform.scala

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ import cats.syntax.all._
4040
import com.comcast.ip4s.{IpAddress, SocketAddress}
4141

4242
import java.util.function.BiFunction
43-
import java.nio.file.Path
43+
import java.nio.file.{Path => JPath}
44+
45+
import fs2.io.file.Path
4446

4547
private[tls] trait TLSContextPlatform[F[_]] {
4648

@@ -104,6 +106,14 @@ private[tls] trait TLSContextCompanionPlatform { self: TLSContext.type =>
104106
def insecure: F[TLSContext[F]]
105107

106108
/** Creates a `TLSContext` from the specified key store file. */
109+
@deprecated("Use overload that takes an fs2.io.file.Path instead", "3.13.0")
110+
def fromKeyStoreFile(
111+
file: JPath,
112+
storePassword: Array[Char],
113+
keyPassword: Array[Char]
114+
): F[TLSContext[F]] =
115+
fromKeyStoreFile(Path.fromNioPath(file), storePassword, keyPassword)
116+
107117
def fromKeyStoreFile(
108118
file: Path,
109119
storePassword: Array[Char],
@@ -275,7 +285,7 @@ private[tls] trait TLSContextCompanionPlatform { self: TLSContext.type =>
275285
storePassword: Array[Char],
276286
keyPassword: Array[Char]
277287
): F[TLSContext[F]] = {
278-
val load = Async[F].blocking(new FileInputStream(file.toFile): InputStream)
288+
val load = Async[F].blocking(new FileInputStream(file.toNioPath.toFile): InputStream)
279289
val stream = Resource.make(load)(s => Async[F].blocking(s.close))
280290
fromKeyStoreStream(stream, storePassword, keyPassword)
281291
}
@@ -285,7 +295,11 @@ private[tls] trait TLSContextCompanionPlatform { self: TLSContext.type =>
285295
storePassword: Array[Char],
286296
keyPassword: Array[Char]
287297
): F[TLSContext[F]] = {
288-
val load = Async[F].blocking(getClass.getClassLoader.getResourceAsStream(resource))
298+
val load = Async[F].blocking {
299+
val s = getClass.getClassLoader.getResourceAsStream(resource)
300+
if (s eq null) throw new IOException(s"Classpath resource not found [$resource]")
301+
else s
302+
}
289303
val stream = Resource.make(load)(s => Async[F].blocking(s.close))
290304
fromKeyStoreStream(stream, storePassword, keyPassword)
291305
}

io/jvm/src/test/scala/fs2/io/net/tls/TLSSocketSuite.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ import cats.effect.{IO, Resource}
3232
import cats.syntax.all._
3333

3434
import com.comcast.ip4s._
35+
import java.io.FileNotFoundException
3536
import java.security.Security
3637
import javax.net.ssl.SSLHandshakeException
3738

39+
import fs2.io.file.Path
40+
3841
class TLSSocketSuite extends TLSSuite {
3942
val size = 8192
4043

@@ -217,4 +220,18 @@ class TLSSocketSuite extends TLSSuite {
217220
.assertEquals(msg)
218221
}
219222
}
223+
224+
group("TLSContextBuilder") {
225+
test("fromKeyStoreResource - not found") {
226+
Network[IO].tlsContext
227+
.fromKeyStoreResource("does-not-exist.jks", Array.empty, Array.empty)
228+
.intercept[IOException]
229+
}
230+
231+
test("fromKeyStoreFile - not found") {
232+
Network[IO].tlsContext
233+
.fromKeyStoreFile(Path("does-not-exist.jks"), Array.empty, Array.empty)
234+
.intercept[FileNotFoundException]
235+
}
236+
}
220237
}

0 commit comments

Comments
 (0)