diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index c700956..6aa376a 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -9,3 +9,6 @@ ecfbaf459af23ed5981aa3b030425f67dece7f9e # Scala Steward: Reformat with scalafmt 3.9.7 cb2021ce0648edfbf4bb45f2962562820c7b677b + +# Scala Steward: Reformat with scalafmt 3.11.0 +f17d63754ce806a77e5a57c99dcc7b7cc7f1a5ca diff --git a/.scalafmt.conf b/.scalafmt.conf index a2b6dfd..388e70e 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,3 +1,3 @@ -version="3.10.7" +version="3.11.0" maxColumn = 120 runner.dialect = scala3 diff --git a/src/main/scala/lc/captchas/CrumpledTextCaptcha.scala b/src/main/scala/lc/captchas/CrumpledTextCaptcha.scala index 5e74151..59f97f4 100644 --- a/src/main/scala/lc/captchas/CrumpledTextCaptcha.scala +++ b/src/main/scala/lc/captchas/CrumpledTextCaptcha.scala @@ -35,10 +35,10 @@ class CrumpledTextCaptcha extends ChallengeProvider { def returnChallenge(level: String, size: String): Challenge = { val r = new scala.util.Random val n = level match { - case "easy" => 5 + case "easy" => 5 case "medium" => 6 - case "hard" => 7 - case _ => 6 + case "hard" => 7 + case _ => 6 } val characters = if (level == "hard") HelperFunctions.safeCharacters else HelperFunctions.safeAlphaNum val secret = LazyList.continually(r.nextInt(characters.size)).map(characters).take(n).mkString @@ -71,13 +71,13 @@ class CrumpledTextCaptcha extends ChallengeProvider { var img = canvas val numFolds = level match { - case "easy" => 7 - case "medium" => 14 - case "hard" => 19 - case _ => 14 + case "easy" => 7 + case "medium" => 14 + case "hard" => 19 + case _ => 14 } for (_ <- 0 until numFolds) { - img = applyFold(img, r) + img = applyFold(img, r) } val baos = new ByteArrayOutputStream() @@ -126,27 +126,27 @@ class CrumpledTextCaptcha extends ChallengeProvider { val rgb01 = img.getRGB(xf, yf + 1) val rgb11 = img.getRGB(xf + 1, yf + 1) - val r00 = (rgb00 >> 16) & 0xFF - val g00 = (rgb00 >> 8) & 0xFF - val b00 = rgb00 & 0xFF - val r10 = (rgb10 >> 16) & 0xFF - val g10 = (rgb10 >> 8) & 0xFF - val b10 = rgb10 & 0xFF - val r01 = (rgb01 >> 16) & 0xFF - val g01 = (rgb01 >> 8) & 0xFF - val b01 = rgb01 & 0xFF - val r11 = (rgb11 >> 16) & 0xFF - val g11 = (rgb11 >> 8) & 0xFF - val b11 = rgb11 & 0xFF + val r00 = (rgb00 >> 16) & 0xff + val g00 = (rgb00 >> 8) & 0xff + val b00 = rgb00 & 0xff + val r10 = (rgb10 >> 16) & 0xff + val g10 = (rgb10 >> 8) & 0xff + val b10 = rgb10 & 0xff + val r01 = (rgb01 >> 16) & 0xff + val g01 = (rgb01 >> 8) & 0xff + val b01 = rgb01 & 0xff + val r11 = (rgb11 >> 16) & 0xff + val g11 = (rgb11 >> 8) & 0xff + val b11 = rgb11 & 0xff val rInterp = (r00 * (1 - xt) * (1 - yt) + r10 * xt * (1 - yt) + r01 * (1 - xt) * yt + r11 * xt * yt).toInt val gInterp = (g00 * (1 - xt) * (1 - yt) + g10 * xt * (1 - yt) + g01 * (1 - xt) * yt + g11 * xt * yt).toInt val bInterp = (b00 * (1 - xt) * (1 - yt) + b10 * xt * (1 - yt) + b01 * (1 - xt) * yt + b11 * xt * yt).toInt - val rgb = (0xFF << 24) | (rInterp << 16) | (gInterp << 8) | bInterp + val rgb = (0xff << 24) | (rInterp << 16) | (gInterp << 8) | bInterp newImg.setRGB(x, y, rgb) } else { - newImg.setRGB(x, y, 0xFFFFFFFF) + newImg.setRGB(x, y, 0xffffffff) } } else { newImg.setRGB(x, y, img.getRGB(x, y)) diff --git a/src/main/scala/lc/core/config.scala b/src/main/scala/lc/core/config.scala index b254cc2..5cabb35 100644 --- a/src/main/scala/lc/core/config.scala +++ b/src/main/scala/lc/core/config.scala @@ -38,7 +38,7 @@ class Config(configFilePath: String) { private val appConfigEither = AppConfig.codec.decode(ByteBuffer.wrap(configString.getBytes("UTF-8"))) private val appConfig = appConfigEither match { case Right(conf) => conf - case Left(err) => throw new Exception(err.toString) + case Left(err) => throw new Exception(err.toString) } private val configFields: ConfigField = appConfig.toConfigField @@ -121,5 +121,4 @@ class Config(configFilePath: String) { } -object Config { -} +object Config {} diff --git a/src/main/scala/lc/core/models.scala b/src/main/scala/lc/core/models.scala index 4771287..dac6721 100644 --- a/src/main/scala/lc/core/models.scala +++ b/src/main/scala/lc/core/models.scala @@ -99,8 +99,16 @@ case class AppConfig( captchas: List[CaptchaConfig] = List.empty ) { def toConfigField: ConfigField = ConfigField( - port, address, bufferCount, seed, captchaExpiryTimeLimit, - threadDelay, playgroundEnabled, corsHeader, maxAttemptsRatio, authRequired + port, + address, + bufferCount, + seed, + captchaExpiryTimeLimit, + threadDelay, + playgroundEnabled, + corsHeader, + maxAttemptsRatio, + authRequired ) } object AppConfig { diff --git a/src/test/scala/lc/ServerAuthSpec.scala b/src/test/scala/lc/ServerAuthSpec.scala index c25aec1..56c7817 100644 --- a/src/test/scala/lc/ServerAuthSpec.scala +++ b/src/test/scala/lc/ServerAuthSpec.scala @@ -19,40 +19,40 @@ class ServerAuthSpec extends AnyFunSuite { val url = new URL("http://localhost:8889/v2/captcha") // 1. Test without auth header - val connection1 = url.openConnection().asInstanceOf[HttpURLConnection] - connection1.setRequestMethod("POST") - connection1.setRequestProperty("Content-Type", "application/json") - connection1.setDoOutput(true) - val payload = """{"level":"debug","media":"image/png","input_type":"text","size":"350x100"}""" - val out1 = new OutputStreamWriter(connection1.getOutputStream) - out1.write(payload) - out1.close() + val connection1 = url.openConnection().asInstanceOf[HttpURLConnection] + connection1.setRequestMethod("POST") + connection1.setRequestProperty("Content-Type", "application/json") + connection1.setDoOutput(true) + val payload = """{"level":"debug","media":"image/png","input_type":"text","size":"350x100"}""" + val out1 = new OutputStreamWriter(connection1.getOutputStream) + out1.write(payload) + out1.close() - var responseCode = connection1.getResponseCode - assert(responseCode == 401, s"Expected 401 but got $responseCode") + var responseCode = connection1.getResponseCode + assert(responseCode == 401, s"Expected 401 but got $responseCode") - // 2. Test with invalid auth header - val connection2 = url.openConnection().asInstanceOf[HttpURLConnection] - connection2.setRequestMethod("POST") - connection2.setRequestProperty("Content-Type", "application/json") - connection2.setRequestProperty("Auth", "wrongsecret") - connection2.setDoOutput(true) - val out2 = new OutputStreamWriter(connection2.getOutputStream) - out2.write(payload) - out2.close() + // 2. Test with invalid auth header + val connection2 = url.openConnection().asInstanceOf[HttpURLConnection] + connection2.setRequestMethod("POST") + connection2.setRequestProperty("Content-Type", "application/json") + connection2.setRequestProperty("Auth", "wrongsecret") + connection2.setDoOutput(true) + val out2 = new OutputStreamWriter(connection2.getOutputStream) + out2.write(payload) + out2.close() - responseCode = connection2.getResponseCode - assert(responseCode == 401, s"Expected 401 but got $responseCode") + responseCode = connection2.getResponseCode + assert(responseCode == 401, s"Expected 401 but got $responseCode") - // 3. Test with valid auth header - val connection3 = url.openConnection().asInstanceOf[HttpURLConnection] - connection3.setRequestMethod("POST") - connection3.setRequestProperty("Content-Type", "application/json") - connection3.setRequestProperty("Auth", "secret123") - connection3.setDoOutput(true) - val out3 = new OutputStreamWriter(connection3.getOutputStream) - out3.write(payload) - out3.close() + // 3. Test with valid auth header + val connection3 = url.openConnection().asInstanceOf[HttpURLConnection] + connection3.setRequestMethod("POST") + connection3.setRequestProperty("Content-Type", "application/json") + connection3.setRequestProperty("Auth", "secret123") + connection3.setDoOutput(true) + val out3 = new OutputStreamWriter(connection3.getOutputStream) + out3.write(payload) + out3.close() responseCode = connection3.getResponseCode assert(responseCode == 200, s"Expected 200 but got $responseCode")