Skip to content

Commit

Permalink
Merge pull request #708 from armanbilge/feature/cross-platform-trusted
Browse files Browse the repository at this point in the history
Cross-platform `SSL.Trusted`
  • Loading branch information
mpilquist authored Sep 22, 2022
2 parents e45a079 + d79b7ef commit 5e3d234
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 64 deletions.
6 changes: 0 additions & 6 deletions modules/core/jvm/src/main/scala/SSLPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ import fs2.io.net.Network
import fs2.io.net.tls.TLSContext

private[skunk] trait SSLCompanionPlatform { this: SSL.type =>

/** `SSL` which trusts all certificates. */
object Trusted extends SSL {
def tlsContext[F[_]: Network](implicit ev: ApplicativeError[F, Throwable]): F[TLSContext[F]] =
Network[F].tlsContext.insecure
}

/** Creates a `SSL` from an `SSLContext`. */
def fromSSLContext(ctx: SSLContext): SSL =
Expand Down
6 changes: 6 additions & 0 deletions modules/core/shared/src/main/scala/SSL.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ object SSL extends SSLCompanionPlatform {
override def withTLSParameters(tlsParameters: TLSParameters): SSL = this
}

/** `SSL` which trusts all certificates. */
object Trusted extends SSL {
def tlsContext[F[_]: Network](implicit ev: ApplicativeError[F, Throwable]): F[TLSContext[F]] =
Network[F].tlsContext.insecure
}

/** `SSL` from the system default `SSLContext`. */
object System extends SSL {
def tlsContext[F[_]: Network](implicit ev: ApplicativeError[F, Throwable]): F[TLSContext[F]] =
Expand Down
7 changes: 0 additions & 7 deletions modules/tests/js/src/test/scala/SslTestPlatform.scala

This file was deleted.

43 changes: 0 additions & 43 deletions modules/tests/jvm/src/test/scala/SslTestPlatform.scala

This file was deleted.

39 changes: 31 additions & 8 deletions modules/tests/shared/src/test/scala/SslTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,28 @@
package tests

import cats.effect._
import cats.syntax.all._
import fs2.io.net.tls.SSLException
import natchez.Trace.Implicits.noop
import skunk._
import fs2.CompositeFailure

class SslTest extends ffstest.FTest with SslTestPlatform {
class SslTest extends ffstest.FTest {

object Port {
val Invalid = 5431
val MD5 = 5432
val Trust = 5433
}

test("successful login with SSL.Trusted (ssl available)") {
Session.single[IO](
host = "localhost",
user = "jimmy",
database = "world",
password = Some("banana"),
ssl = SSL.Trusted,
).use(_ => IO.unit)
}

test("successful login with SSL.None (ssl available)") {
Session.single[IO](
host = "localhost",
Expand All @@ -36,12 +44,27 @@ class SslTest extends ffstest.FTest with SslTestPlatform {
database = "world",
password = Some("banana"),
ssl = SSL.System,
).use(_ => IO.unit).assertFailsWith[SSLException].as("sigh") // TODO! Better failure!
}

test("failed login with SSL.Trusted (ssl not available)") {
Session.single[IO](
host = "localhost",
user = "postgres",
database = "world",
ssl = SSL.Trusted,
port = Port.Trust
).use(_ => IO.unit).assertFailsWith[Exception].as("ok") // TODO! Better failure!
}

test("successful login with SSL.Trusted.withFallback(true) (ssl not available)") {
Session.single[IO](
host = "localhost",
user = "postgres",
database = "world",
ssl = SSL.Trusted.withFallback(true),
port = Port.Trust
).use(_ => IO.unit)
.adaptError {
case ex @ CompositeFailure(head, tail) =>
tail.prepend(head).collectFirst({ case ex: SSLException => ex }).getOrElse(ex)
}
.assertFailsWith[SSLException].as("sigh") // TODO! Better failure!
}

test("successful login with SSL.None (ssl not available)") {
Expand Down

0 comments on commit 5e3d234

Please sign in to comment.