<commit_before>package lila.user

import org.specs2.mutable.Specification
import java.util.Base64
import Authenticator.AuthData
import User.{ ClearPassword => P }
import lila.common.config.Secret

class AuthTest extends Specification {

  val secret = Secret(Array.fill(32)(1.toByte).toBase64)
  final def getAuth(passHasher: PasswordHasher) = new Authenticator(
    passHasher = passHasher,
    userRepo = null
  )

  val auth = getAuth(new PasswordHasher(secret, 2))

  "bcrypt checks" in {
    val bCryptUser = AuthData(
      "",
      bpass = HashedPassword(
        Base64.getDecoder.decode(
          <KEY>"
        )
      )
    )
    "correct" >> auth.compare(bCryptUser, P("password"))
    "wrong pass" >> !auth.compare(bCryptUser, P(""))

    // sanity check of aes encryption
    "wrong secret" >> ! {
      getAuth(new PasswordHasher(Secret((new Array[Byte](32)).toBase64), 2)).compare(
        bCryptUser,<commit_msg>use global execution context in test<commit_after>package lila.user

import org.specs2.mutable.Specification
import java.util.Base64
import Authenticator.AuthData
import User.{ ClearPassword => P }
import lila.common.config.Secret
import scala.concurrent.ExecutionContext.Implicits.global

class AuthTest extends Specification {

  val secret = Secret(Array.fill(32)(1.toByte).toBase64)
  final def getAuth(passHasher: PasswordHasher) = new Authenticator(
    passHasher = passHasher,
    userRepo = null
  )

  val auth = getAuth(new PasswordHasher(secret, 2))

  "bcrypt checks" in {
    val bCryptUser = AuthData(
      "",
      bpass = HashedPassword(
        Base64.getDecoder.decode(
          <KEY>"
        )
      )
    )
    "correct" >> auth.compare(bCryptUser, P("password"))
    "wrong pass" >> !auth.compare(bCryptUser, P(""))

    // sanity check of aes encryption
    "wrong secret" >> ! {
      getAuth(new PasswordHasher(Secret((new Array[Byte](32)).toBase64), 2)).compare(
        bCryptUser,
{'fraction_non_alphanumeric': 0.11837364899639732, 'fraction_numerical': 0.016469377251672673, 'mean_word_length': 3.418181818181818, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6870865', 'n_tokens_mistral': 650, 'n_tokens_neox': 612, 'n_words': 136}