Skip to content

Commit

Permalink
chore: bump scala from 3.3.3 to 3.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshinorin committed Mar 2, 2024
1 parent 1005acb commit fb62001
Show file tree
Hide file tree
Showing 25 changed files with 69 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
matrix:
os: [ubuntu-latest]
java: [21]
scala: [3.3.3]
scala: [3.4.0]
fail-fast: false
steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ An example of architecture.
## Requirements

* sbt 1.9.x
* Scala 3.3.x
* Scala 3.4.x
* Java 21.x, 17.x (Perhaps works with 11.x)
* MariaDB 10.11.x
* docker & docker-compose 3.x (for test)
Expand Down
5 changes: 3 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import LocalProcesses.*
organization := "net.yoshinorin"
name := "qualtet"
version := "v2.11.0"
scalaVersion := "3.3.3"
scalaVersion := "3.4.0"
val repository = "/~https://github.com/yoshinorin/qualtet"

scalacOptions ++= Seq(
Expand All @@ -21,7 +21,8 @@ scalacOptions ++= Seq(
"-Wunused:imports",
"-Wunused:locals",
"-Wunused:params",
"-Wunused:privates"
"-Wunused:privates",
"-rewrite -source 3.4-migration"
)

// /~https://github.com/rtimush/sbt-updates
Expand Down
2 changes: 1 addition & 1 deletion docs/rest-api/components/schemas/applicationInfo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ properties:
example: "/~https://github.com/yoshinorin/qualtet/commit/237856f"
scalaVersion:
type: string
example: "3.3.3"
example: "3.4.0"
sbtVersion:
type: string
example: "1.9.9"
6 changes: 3 additions & 3 deletions src/main/scala/net/yoshinorin/qualtet/ApplicationInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ lazy val commitHash = BuildInfo.commitHash match {
lazy val runtime = Runtime()
lazy val build = Build()

private[this] final case class Runtime(
private final case class Runtime(
name: String = "Java",
vendor: String = jvmVendor,
version: String = runtimeVersion
)

private[this] final case class Build(
private final case class Build(
commit: String = commitHash,
url: String = s"${BuildInfo.repository}/commit/${commitHash}",
scalaVersion: String = BuildInfo.scalaVersion,
sbtVersion: String = BuildInfo.sbtVersion
)

private[this] final case class ApplicationInfo(
private final case class ApplicationInfo(
name: String = BuildInfo.name,
version: String = BuildInfo.version,
repository: String = BuildInfo.repository,
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/net/yoshinorin/qualtet/BootStrap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ object BootStrap extends IOApp {
tagRouteV1
)

private[this] def server(host: Ipv4Address, port: Port, httpApp: HttpApp[IO]): Resource[IO, Server] = {
private def server(host: Ipv4Address, port: Port, httpApp: HttpApp[IO]): Resource[IO, Server] = {
EmberServerBuilder
.default[IO]
.withHost(host)
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/net/yoshinorin/qualtet/auth/AuthService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import org.slf4j.LoggerFactory

class AuthService[F[_]: Monad](authorService: AuthorService[F], jwt: Jwt) {

private[this] val logger = LoggerFactory.getLogger(this.getClass)
private[this] val bcryptPasswordEncoder = new BCryptPasswordEncoder()
private val logger = LoggerFactory.getLogger(this.getClass)
private val bcryptPasswordEncoder = new BCryptPasswordEncoder()

def generateToken(tokenRequest: RequestToken): IO[ResponseToken] = {

Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/net/yoshinorin/qualtet/auth/Jwt.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Jwt(config: JwtConfig, algorithm: JwtAsymmetricAlgorithm, keyPair: KeyPair

import JwtClaim.*

private[this] val logger = LoggerFactory.getLogger(this.getClass)
private val logger = LoggerFactory.getLogger(this.getClass)

/**
* create JWT with authorId. authorId uses claim names in JWT.
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/net/yoshinorin/qualtet/auth/KeyPair.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import java.security.{KeyPairGenerator, PrivateKey, PublicKey, SecureRandom}

class KeyPair(algorithm: String, length: Int, secureRandom: SecureRandom) {

private[this] val logger = LoggerFactory.getLogger(this.getClass)
private[this] val keyPairGenerator = KeyPairGenerator.getInstance(algorithm)
private val logger = LoggerFactory.getLogger(this.getClass)
private val keyPairGenerator = KeyPairGenerator.getInstance(algorithm)

keyPairGenerator.initialize(length, secureRandom)

Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/net/yoshinorin/qualtet/auth/Signature.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import java.security.{PrivateKey, Signature => JavaSignature}

class Signature(algorithm: String, message: Array[Byte], key: KeyPair) {

private[this] val logger = LoggerFactory.getLogger(this.getClass)
private[this] val signature = JavaSignature.getInstance(algorithm)
private val logger = LoggerFactory.getLogger(this.getClass)
private val signature = JavaSignature.getInstance(algorithm)

signature.initSign(key.privateKey)
signature.update(message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CacheService[F[_]: Monad](
feedService: FeedService[F]
) {

private[this] val logger = LoggerFactory.getLogger(this.getClass)
private val logger = LoggerFactory.getLogger(this.getClass)

def invalidateAll(): IO[Unit] = {
for {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final case class ApplicationConfig(

object ApplicationConfig {

private[this] val config: TypeSafeConfig = ConfigFactory.load
private val config: TypeSafeConfig = ConfigFactory.load

private val dbUrl: String = config.getString("db.ctx.dataSource.url")
private val dbUser: String = config.getString("db.ctx.dataSource.user")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import net.yoshinorin.qualtet.syntax.*
class AuthProvider[F[_]: Monad](
authService: AuthService[F]
) {
private[this] val logger = LoggerFactory.getLogger(this.getClass)
private val logger = LoggerFactory.getLogger(this.getClass)

// TODO: cleanup messy code
private def authUser: Kleisli[IO, Request[IO], Either[Fail, (ResponseAuthor, String)]] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.http4s.headers.Allow
import org.http4s.dsl.io.*

trait MethodNotAllowedSupport[F[_]: Monad] {
private[this] val logger = LoggerFactory.getLogger(this.getClass)
private val logger = LoggerFactory.getLogger(this.getClass)

private[http] def methodNotAllowed(request: Request[F], allow: Allow) = {
logger.error(s"method not allowed: ${request}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import scala.util.control.NonFatal

trait RequestDecoder {

private[this] val logger = LoggerFactory.getLogger(this.getClass)
private val logger = LoggerFactory.getLogger(this.getClass)

def decode[T <: Request[T]](maybeJsonString: String): JsonValueCodec[T] ?=> Either[Fail, T] = {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import net.yoshinorin.qualtet.syntax.*
object ResponseTranslator {

// NOTE: can't use `ContextFunctions`.
private[this] def failToResponse(f: Fail)(using req: Request[IO]): IO[Response[IO]] = {
private def failToResponse(f: Fail)(using req: Request[IO]): IO[Response[IO]] = {
f match {
case e: Fail.NotFound =>
NotFound(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ContentRoute[F[_]: Monad](
) extends RequestDecoder
with MethodNotAllowedSupport[IO] {

private[this] val logger = LoggerFactory.getLogger(this.getClass)
private val logger = LoggerFactory.getLogger(this.getClass)

// NOTE: must be compose `auth route` after `Non auth route`.
private[http] def index: HttpRoutes[IO] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SearchRoute[F[_]: Monad](
searchService: SearchService[F]
) extends MethodNotAllowedSupport[IO] {

private[this] val logger = LoggerFactory.getLogger(this.getClass)
private val logger = LoggerFactory.getLogger(this.getClass)

private[http] def index: HttpRoutes[IO] = HttpRoutes.of[IO] { implicit r =>
(r match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TagRoute[F[_]: Monad](
articleService: ArticleService[F]
) extends MethodNotAllowedSupport[IO] {

private[this] val logger = LoggerFactory.getLogger(this.getClass)
private val logger = LoggerFactory.getLogger(this.getClass)

private[http] def index: HttpRoutes[IO] =
tagsWithoutAuth <+>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import org.flywaydb.core.api.configuration.FluentConfiguration

class Migrator(config: DBConfig) {

private[this] val flywayConfig: FluentConfiguration = Flyway.configure().dataSource(config.url, config.user, config.password)
private[this] val flyway: Flyway = new Flyway(flywayConfig)
private val flywayConfig: FluentConfiguration = Flyway.configure().dataSource(config.url, config.user, config.password)
private val flyway: Flyway = new Flyway(flywayConfig)

/**
* Do migration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.slf4j.LoggerFactory

trait throwable {

private[this] val logger = LoggerFactory.getLogger(this.getClass)
private val logger = LoggerFactory.getLogger(this.getClass)

extension (e: Throwable) {
def withLog[F[_]: Monad]: F[Throwable] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import cats.effect.unsafe.implicits.global

object CreateAuthor {

private[this] val logger = LoggerFactory.getLogger(this.getClass)
private val logger = LoggerFactory.getLogger(this.getClass)

given dbContext: DoobieTransactor = new DoobieTransactor(config.db)
val authorRepository: AuthorRepository[ConnectionIO] = summon[AuthorRepository[ConnectionIO]]
Expand Down
30 changes: 15 additions & 15 deletions src/test/scala/net/yoshinorin/qualtet/auth/JwtSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,42 +62,42 @@ class JwtSpec extends AnyWordSpec {
}

"be return Right if JWT is correct" in {
assert(Validator.validate(jc)(x => x.aud === config.jwt.aud)(Unauthorized())(ioInstance).value.unsafeRunSync().isRight)
assert(Validator.validate(jc)(x => x.iss === config.jwt.iss)(Unauthorized())(ioInstance).value.unsafeRunSync().isRight)
assert(Validator.validate(jc)(x => x.exp > Instant.now.getEpochSecond - 1000)(Unauthorized())(ioInstance).value.unsafeRunSync().isRight)
assert(Validator.validate(jc)(x => x.aud === config.jwt.aud)(Unauthorized())(using ioInstance).value.unsafeRunSync().isRight)
assert(Validator.validate(jc)(x => x.iss === config.jwt.iss)(Unauthorized())(using ioInstance).value.unsafeRunSync().isRight)
assert(Validator.validate(jc)(x => x.exp > Instant.now.getEpochSecond - 1000)(Unauthorized())(using ioInstance).value.unsafeRunSync().isRight)
}

"be return Left if JWT is incorrect" in {
assert(Validator.validate(jc)(x => x.aud === "incorrect aud")(Unauthorized())(ioInstance).value.unsafeRunSync().isLeft)
assert(Validator.validate(jc)(x => x.iss === "incorrect iss")(Unauthorized())(ioInstance).value.unsafeRunSync().isLeft)
assert(Validator.validate(jc)(x => x.exp > x.exp + 1)(Unauthorized())(ioInstance).value.unsafeRunSync().isLeft)
assert(Validator.validate(jc)(x => x.aud === "incorrect aud")(Unauthorized())(using ioInstance).value.unsafeRunSync().isLeft)
assert(Validator.validate(jc)(x => x.iss === "incorrect iss")(Unauthorized())(using ioInstance).value.unsafeRunSync().isLeft)
assert(Validator.validate(jc)(x => x.exp > x.exp + 1)(Unauthorized())(using ioInstance).value.unsafeRunSync().isLeft)
}

"be return Left if JWT is incorrect in for-comprehension: pattern-one" in {
val r = for {
_ <- Validator.validate(jc)(x => x.aud === config.jwt.aud)(Unauthorized())(ioInstance)
_ <- Validator.validate(jc)(x => x.iss === config.jwt.iss)(Unauthorized())(ioInstance)
result <- Validator.validate(jc)(x => x.exp > (x.exp + config.jwt.expiration + 1))(Unauthorized())(ioInstance)
_ <- Validator.validate(jc)(x => x.aud === config.jwt.aud)(Unauthorized())(using ioInstance)
_ <- Validator.validate(jc)(x => x.iss === config.jwt.iss)(Unauthorized())(using ioInstance)
result <- Validator.validate(jc)(x => x.exp > (x.exp + config.jwt.expiration + 1))(Unauthorized())(using ioInstance)
} yield result

assert(r.value.unsafeRunSync().isLeft)
}

"be return Left if JWT is incorrect in for-comprehension: pattern-two" in {
val r = for {
_ <- Validator.validate(jc)(x => x.aud === config.jwt.aud)(Unauthorized())(ioInstance)
_ <- Validator.validate(jc)(x => x.iss === "incorrect iss")(Unauthorized())(ioInstance)
result <- Validator.validate(jc)(x => x.exp > Instant.now.getEpochSecond)(Unauthorized())(ioInstance)
_ <- Validator.validate(jc)(x => x.aud === config.jwt.aud)(Unauthorized())(using ioInstance)
_ <- Validator.validate(jc)(x => x.iss === "incorrect iss")(Unauthorized())(using ioInstance)
result <- Validator.validate(jc)(x => x.exp > Instant.now.getEpochSecond)(Unauthorized())(using ioInstance)
} yield result

assert(r.value.unsafeRunSync().isLeft)
}

"be return Left if JWT is incorrect in for-comprehension: pattern-three" in {
val r = for {
_ <- Validator.validate(jc)(x => x.aud === "incorrect aud")(Unauthorized())(ioInstance)
_ <- Validator.validate(jc)(x => x.iss === config.jwt.iss)(Unauthorized())(ioInstance)
result <- Validator.validate(jc)(x => x.exp > Instant.now.getEpochSecond)(Unauthorized())(ioInstance)
_ <- Validator.validate(jc)(x => x.aud === "incorrect aud")(Unauthorized())(using ioInstance)
_ <- Validator.validate(jc)(x => x.iss === config.jwt.iss)(Unauthorized())(using ioInstance)
result <- Validator.validate(jc)(x => x.exp > Instant.now.getEpochSecond)(Unauthorized())(using ioInstance)
} yield result

assert(r.value.unsafeRunSync().isLeft)
Expand Down
16 changes: 8 additions & 8 deletions src/test/scala/net/yoshinorin/qualtet/syntax/validatorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@ class ValidatorSpec extends AnyWordSpec {
"be return right" in {

// NOTE: Workaround avoid compile error when use `===`. So, use `eqv` instead of it.
assert("a".toEitherF(x => x eqv "a")(UnprocessableEntity(detail = "unprocessable!!"))(ioInstance).value.unsafeRunSync().isRight)
assert(1.toEitherF(x => x eqv 1)(UnprocessableEntity(detail = "unprocessable!!"))(ioInstance).value.unsafeRunSync().isRight)
assert("a".toEitherF(x => x eqv "a")(UnprocessableEntity(detail = "unprocessable!!"))(using ioInstance).value.unsafeRunSync().isRight)
assert(1.toEitherF(x => x eqv 1)(UnprocessableEntity(detail = "unprocessable!!"))(using ioInstance).value.unsafeRunSync().isRight)
}

"not be throw if isRight" in {
val s = "a".toEitherF(x => x eqv "a")(UnprocessableEntity(detail = "unprocessable!!"))(ioInstance).andThrow.unsafeRunSync()
val s = "a".toEitherF(x => x eqv "a")(UnprocessableEntity(detail = "unprocessable!!"))(using ioInstance).andThrow.unsafeRunSync()
assert(s eqv "a")
val i = 1.toEitherF(x => x eqv 1)(UnprocessableEntity(detail = "unprocessable!!"))(ioInstance).andThrow.unsafeRunSync()
val i = 1.toEitherF(x => x eqv 1)(UnprocessableEntity(detail = "unprocessable!!"))(using ioInstance).andThrow.unsafeRunSync()
assert(i eqv 1)
}

"be return left" in {
assert("a".toEitherF(x => x =!= "a")(Unauthorized())(ioInstance).value.unsafeRunSync().isLeft)
assert(1.toEitherF(x => x =!= 1)(UnprocessableEntity(detail = "unprocessable!!"))(ioInstance).value.unsafeRunSync().isLeft)
assert("a".toEitherF(x => x =!= "a")(Unauthorized())(using ioInstance).value.unsafeRunSync().isLeft)
assert(1.toEitherF(x => x =!= 1)(UnprocessableEntity(detail = "unprocessable!!"))(using ioInstance).value.unsafeRunSync().isLeft)
}

"be throw if isLeft" in {
assertThrows[Unauthorized] {
"a".toEitherF(x => x =!= "a")(Unauthorized())(ioInstance).andThrow.unsafeRunSync()
"a".toEitherF(x => x =!= "a")(Unauthorized())(using ioInstance).andThrow.unsafeRunSync()
}

assertThrows[UnprocessableEntity] {
1.toEitherF(x => x =!= 1)(UnprocessableEntity(detail = "unprocessable!!"))(ioInstance).andThrow.unsafeRunSync()
1.toEitherF(x => x =!= 1)(UnprocessableEntity(detail = "unprocessable!!"))(using ioInstance).andThrow.unsafeRunSync()
}
}
}
Expand Down
Loading

0 comments on commit fb62001

Please sign in to comment.