feat/gitignore #9
|
|
@ -17,7 +17,8 @@ fun isValidPassword(password: String): Boolean {
|
||||||
if (password.length < 8) return false
|
if (password.length < 8) return false
|
||||||
|
|
||||||
val hasUppercase = password.any { it.isUpperCase() }
|
val hasUppercase = password.any { it.isUpperCase() }
|
||||||
val hasEmoji = password.any { char ->
|
val hasEmoji =
|
||||||
|
password.any { char ->
|
||||||
val type = Character.getType(char).toByte()
|
val type = Character.getType(char).toByte()
|
||||||
type == Character.SURROGATE ||
|
type == Character.SURROGATE ||
|
||||||
type == Character.OTHER_SYMBOL ||
|
type == Character.OTHER_SYMBOL ||
|
||||||
|
|
@ -32,7 +33,6 @@ fun isValidPassword(password: String): Boolean {
|
||||||
return hasUppercase && hasSpecialChar && !hasEmoji
|
return hasUppercase && hasSpecialChar && !hasEmoji
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Application.configureRouting(repository: KidioRepository, jwtService : JwtService) {
|
|
||||||
fun Application.configureRouting(
|
fun Application.configureRouting(
|
||||||
repository: KidioRepository,
|
repository: KidioRepository,
|
||||||
jwtService: JwtService,
|
jwtService: JwtService,
|
||||||
|
|
@ -47,7 +47,8 @@ fun Application.configureRouting(repository: KidioRepository, jwtService : JwtSe
|
||||||
if (!isValidPassword(registerRequest.passwordPlain)) {
|
if (!isValidPassword(registerRequest.passwordPlain)) {
|
||||||
call.respond(
|
call.respond(
|
||||||
HttpStatusCode.BadRequest,
|
HttpStatusCode.BadRequest,
|
||||||
"Das Passwort muss mindestens 8 Zeichen lang sein, mindestens einen Großbuchstaben und ein Sonderzeichen enthalten und darf keine Emojis enthalten."
|
"Das Passwort muss mindestens 8 Zeichen lang sein, " +
|
||||||
|
"mindestens einen Großbuchstaben und ein Sonderzeichen enthalten.",
|
||||||
)
|
)
|
||||||
return@post
|
return@post
|
||||||
}
|
}
|
||||||
|
|
@ -115,12 +116,9 @@ fun Application.configureRouting(repository: KidioRepository, jwtService : JwtSe
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
return@post
|
return@post
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
authenticate("auth-jwt") {
|
authenticate("auth-jwt") {
|
||||||
|
|
||||||
// 1. Alle verfügbaren Aufgaben abrufen
|
// 1. Alle verfügbaren Aufgaben abrufen
|
||||||
get("/api/v1/tasks") {
|
get("/api/v1/tasks") {
|
||||||
val tasks = repository.getAllTasks()
|
val tasks = repository.getAllTasks()
|
||||||
|
|
@ -135,7 +133,7 @@ fun Application.configureRouting(repository: KidioRepository, jwtService : JwtSe
|
||||||
if (userId == null) {
|
if (userId == null) {
|
||||||
call.respond(
|
call.respond(
|
||||||
HttpStatusCode.Unauthorized,
|
HttpStatusCode.Unauthorized,
|
||||||
mapOf("error" to "Ungültiges oder abgelaufenes Token")
|
mapOf("error" to "Ungültiges oder abgelaufenes Token"),
|
||||||
)
|
)
|
||||||
return@post
|
return@post
|
||||||
}
|
}
|
||||||
|
|
@ -219,5 +217,3 @@ fun Application.configureRouting(repository: KidioRepository, jwtService : JwtSe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,7 @@ class ServerTest {
|
||||||
setBody(
|
setBody(
|
||||||
"""{
|
"""{
|
||||||
"email": "test@family.de",
|
"email": "test@family.de",
|
||||||
"passwordPlain": "strengGeheim1",
|
"passwordPlain": "StrengGeheim1!",
|
||||||
"familyName": "Familie Schmidt",
|
"familyName": "Familie Schmidt",
|
||||||
"childAge": 8,
|
"childAge": 8,
|
||||||
"parentPin": "4321"
|
"parentPin": "4321"
|
||||||
|
|
@ -140,7 +140,8 @@ class ServerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test registration rejects invalid passwords`() = testApplication {
|
fun `test registration rejects invalid passwords`() =
|
||||||
|
testApplication {
|
||||||
val jwtService = JwtService()
|
val jwtService = JwtService()
|
||||||
val repository = InMemoryKidioRepository()
|
val repository = InMemoryKidioRepository()
|
||||||
|
|
||||||
|
|
@ -152,15 +153,17 @@ class ServerTest {
|
||||||
configureRouting(repository, jwtService)
|
configureRouting(repository, jwtService)
|
||||||
}
|
}
|
||||||
|
|
||||||
val invalidPasswords = listOf(
|
val invalidPasswords =
|
||||||
|
listOf(
|
||||||
"Kurz1!",
|
"Kurz1!",
|
||||||
"keingrossbuch1!",
|
"keingrossbuch1!",
|
||||||
"KeinSonder12",
|
"KeinSonder12",
|
||||||
"Passwort123!😊"
|
"Passwort123!😊",
|
||||||
)
|
)
|
||||||
|
|
||||||
for (password in invalidPasswords) {
|
for (password in invalidPasswords) {
|
||||||
val response = client.post("/api/v1/auth/register") {
|
val response =
|
||||||
|
client.post("/api/v1/auth/register") {
|
||||||
header(HttpHeaders.ContentType, ContentType.Application.Json.toString())
|
header(HttpHeaders.ContentType, ContentType.Application.Json.toString())
|
||||||
setBody(
|
setBody(
|
||||||
"""{
|
"""{
|
||||||
|
|
@ -169,13 +172,13 @@ class ServerTest {
|
||||||
"familyName": "Familie Schmidt",
|
"familyName": "Familie Schmidt",
|
||||||
"childAge": 8,
|
"childAge": 8,
|
||||||
"parentPin": "4321"
|
"parentPin": "4321"
|
||||||
}"""
|
}""",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
assertEquals(
|
assertEquals(
|
||||||
HttpStatusCode.BadRequest,
|
HttpStatusCode.BadRequest,
|
||||||
response.status,
|
response.status,
|
||||||
"Passwort '$password' hätte abgelehnt werden müssen!"
|
"Passwort '$password' hätte abgelehnt werden müssen!",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue