From a3065f64af64193af4f0a7c92081f454e17c784a Mon Sep 17 00:00:00 2001 From: Override-6 Date: Sun, 29 Jan 2023 21:20:36 +0100 Subject: [PATCH] fixed tests --- Core/src/org/tbasket/auth/Authenticator.scala | 4 +-- target/test-reports-zio/output.json | 32 ++++++++++++------- .../test/pages/LoginPageHandlerTests.scala | 6 ++-- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/Core/src/org/tbasket/auth/Authenticator.scala b/Core/src/org/tbasket/auth/Authenticator.scala index 20d5cd0..54b4641 100644 --- a/Core/src/org/tbasket/auth/Authenticator.scala +++ b/Core/src/org/tbasket/auth/Authenticator.scala @@ -77,8 +77,8 @@ class Authenticator(url: URL, key: PublicKey, algorithm: JwtAsymmetricAlgorithm) import ctx.v.* findByMail(mail) - .someOrFail(UserNotFound)// await one second if password fails to reduce bruteforce //FIXME this wont actually reduce bruteforce - .filterOrElse(_.passwordHash == hashPassword(password))(ZIO.sleep(1.second) *> ZIO.fail(InvalidPassword)) + .someOrFail(UserNotFound) // await one second if password fails to reduce bruteforce //FIXME this wont actually reduce bruteforce + .filterOrElse(_.passwordHash == hashPassword(password))(Clock.sleep(1.seconds) *> ZIO.fail(InvalidPassword)) } private def insert(user: User) = quote { diff --git a/target/test-reports-zio/output.json b/target/test-reports-zio/output.json index 8702013..32b4171 100644 --- a/target/test-reports-zio/output.json +++ b/target/test-reports-zio/output.json @@ -1,33 +1,33 @@ { "results": [ { - "name" : "Test Task name not available here/\/login page handler/login situation tests/login with unknown account", + "name" : "Test Task name not available here/\/login page handler/login situation tests/login with known account wrong password", "status" : "Success", - "durationMillis" : "3877", + "durationMillis" : "5030", "annotations" : "", "fullyQualifiedClassName" : "Test Task name not available here", - "labels" : ["\/login page handler", "login situation tests", "login with unknown account"] + "labels" : ["\/login page handler", "login situation tests", "login with known account wrong password"] }, { - "name" : "Test Task name not available here/\/login page handler/login situation tests/login with known account", + "name" : "Test Task name not available here/\/login page handler/login situation tests/login with unknown account", "status" : "Success", - "durationMillis" : "4862", + "durationMillis" : "5077", "annotations" : "", "fullyQualifiedClassName" : "Test Task name not available here", - "labels" : ["\/login page handler", "login situation tests", "login with known account"] + "labels" : ["\/login page handler", "login situation tests", "login with unknown account"] }, { - "name" : "Test Task name not available here/\/login page handler/erroned request body tests/empty packet", + "name" : "Test Task name not available here/\/login page handler/login situation tests/login with known account", "status" : "Success", - "durationMillis" : "2683", + "durationMillis" : "6398", "annotations" : "", "fullyQualifiedClassName" : "Test Task name not available here", - "labels" : ["\/login page handler", "erroned request body tests", "empty packet"] + "labels" : ["\/login page handler", "login situation tests", "login with known account"] }, { "name" : "Test Task name not available here/\/login page handler/erroned request body tests/with no password attribute", "status" : "Success", - "durationMillis" : "2698", + "durationMillis" : "3098", "annotations" : "", "fullyQualifiedClassName" : "Test Task name not available here", "labels" : ["\/login page handler", "erroned request body tests", "with no password attribute"] @@ -35,15 +35,23 @@ { "name" : "Test Task name not available here/\/login page handler/erroned request body tests/with no mail attribute", "status" : "Success", - "durationMillis" : "2697", + "durationMillis" : "3172", "annotations" : "", "fullyQualifiedClassName" : "Test Task name not available here", "labels" : ["\/login page handler", "erroned request body tests", "with no mail attribute"] }, + { + "name" : "Test Task name not available here/\/login page handler/erroned request body tests/empty packet", + "status" : "Success", + "durationMillis" : "3200", + "annotations" : "", + "fullyQualifiedClassName" : "Test Task name not available here", + "labels" : ["\/login page handler", "erroned request body tests", "empty packet"] + }, { "name" : "Test Task name not available here/\/login page handler/erroned request body tests/with invalid json", "status" : "Success", - "durationMillis" : "2679", + "durationMillis" : "3251", "annotations" : "", "fullyQualifiedClassName" : "Test Task name not available here", "labels" : ["\/login page handler", "erroned request body tests", "with invalid json"] diff --git a/tests/src/org/tbasket/test/pages/LoginPageHandlerTests.scala b/tests/src/org/tbasket/test/pages/LoginPageHandlerTests.scala index 5ba4df1..d61ca53 100644 --- a/tests/src/org/tbasket/test/pages/LoginPageHandlerTests.scala +++ b/tests/src/org/tbasket/test/pages/LoginPageHandlerTests.scala @@ -77,15 +77,17 @@ object LoginPageHandlerTests extends ZIOSpecDefault { }, test("login with known account wrong password") { + val requestJson = """{"password":"this is a wrong password","email":"maximebatista18@gmail.com"}""" for - response <- post(Request.post(Body.fromString("""{"password":"this is a wrong password","email":"maximebatista18@gmail.com"}"""), URL.empty)) + fiber <- post(Request.post(Body.fromString(requestJson), URL.empty)).fork + _ <- TestClock.adjust(1.seconds) + response <- ZIO.fromFiber(fiber) json <- getJsonBody(response) errorType <- parseAttribute(json, "error", JsonCursor.field("error").isString) errorMsg <- parseAttribute(json, "msg", JsonCursor.field("msg").isString) yield assert(errorType)(equalTo("unauthorized")) && assert(errorMsg)(equalTo("invalid password")) - && assert(response)(hasField("headers", _.headers, hasSameElements(Headers.location("/register")))) } ) }