Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#91 Fixed fuzzed errors #98

Merged
merged 12 commits into from
Apr 30, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.RestController
import ru.vityaman.lms.botalka.app.spring.api.http.error.InvalidPromotionRequestStatus
import ru.vityaman.lms.botalka.app.spring.api.http.message.toMessage
import ru.vityaman.lms.botalka.app.spring.api.http.message.toModel
import ru.vityaman.lms.botalka.app.spring.api.http.server.PromotionRequestDraftMessage
import ru.vityaman.lms.botalka.app.spring.api.http.server.PromotionRequestMessage
import ru.vityaman.lms.botalka.app.spring.api.http.server.PromotionRequestPatchMessage
import ru.vityaman.lms.botalka.app.spring.api.http.server.apis.PromotionApi
import ru.vityaman.lms.botalka.core.exception.InvalidValueException
import ru.vityaman.lms.botalka.core.logic.PromotionService
import ru.vityaman.lms.botalka.core.model.PromotionRequest
import ru.vityaman.lms.botalka.core.model.User
Expand All @@ -27,9 +27,9 @@ class PromotionHttpApi(

when (val status = promotionRequestPatchMessage.status.toModel()) {
PromotionRequest.Status.CREATED -> {
throw InvalidPromotionRequestStatus(
throw InvalidValueException(
buildString {
append("Can't change promotion request status")
append("Can't change promotion request status ")
append("to ${status.toMessage()}")
},
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
package ru.vityaman.lms.botalka.app.spring.api.http.error

import com.fasterxml.jackson.core.JsonParseException
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.RestControllerAdvice
import org.springframework.web.server.ServerWebInputException
import ru.vityaman.lms.botalka.app.spring.api.http.server.GeneralErrorMessage

@RestControllerAdvice
class DriverExceptionMapping {
@ExceptionHandler(JsonParseException::class)
fun handle(exception: JsonParseException): ResponseEntity<Any> {
@ExceptionHandler(ServerWebInputException::class)
fun handle(exception: ServerWebInputException) = run {
val code = HttpStatus.BAD_REQUEST
val offset = exception.location.offsetDescription()
return ResponseEntity
ResponseEntity
.status(code)
.body(
GeneralErrorMessage(
code = code.value(),
status = code.reasonPhrase,
message = "Json syntax error at $offset",
message = "Input is invalid: ${exception.reason ?: "?"}",
),
)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ data class Homework(
}

companion object {
private val range = 0..2000
private val range = 1..2000
}
}

Expand All @@ -70,6 +70,10 @@ data class Homework(
val deadlineMoment: OffsetDateTime,
) {
init {
val maxDeadline = OffsetDateTime.parse("4096-08-08T08:08:08+03:00")
expect(deadlineMoment.isBefore(maxDeadline)) {
append("Homework deadline must be before $maxDeadline")
}
expect(publicationMoment.plusMinutes(1).isBefore(deadlineMoment)) {
append("Homework must be published 1 minute before deadline")
}
Expand Down
24 changes: 24 additions & 0 deletions botalka/src/main/resources/static/openapi/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ paths:
type: array
items:
$ref: '#/components/schemas/WorkspaceEvent'
400:
description: Invalid parameters
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
404:
description: Homework or student with given id not found
content:
Expand Down Expand Up @@ -160,6 +166,12 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/User'
400:
description: Invalid parameters
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
404:
description: Not found
content:
Expand Down Expand Up @@ -218,6 +230,12 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/PromotionRequest'
400:
description: Invalid parameters
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
404:
description: User not found
content:
Expand Down Expand Up @@ -253,6 +271,12 @@ paths:
responses:
204:
description: Promotion request resolved
400:
description: Invalid parameters
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
404:
description: Promotion request not found
content:
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ services:
- GF_SECURITY_ADMIN_PASSWORD=0000
networks:
- lms-network
profiles:
- infra
prometheus:
container_name: lms-prometheus
image: prom/prometheus
Expand All @@ -53,6 +55,8 @@ services:
- ./infra/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
networks:
- lms-network
profiles:
- infra
restler:
container_name: lms-restler
image: restler
Expand Down
Loading