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

TRELLO-2795 : prevent reporting gouv website #1832

Merged
merged 1 commit into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions app/orchestrators/ReportOrchestrator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import models.report.reportmetadata.ReportWithMetadataAndBookmark
import models.token.TokenKind.CompanyInit
import models.website.Website
import orchestrators.ReportOrchestrator.ReportCompanyChangeThresholdInDays
import orchestrators.ReportOrchestrator.isGouvWebsite
import play.api.Logger
import play.api.i18n.MessagesApi
import play.api.libs.json.Json
Expand Down Expand Up @@ -65,6 +66,7 @@ import java.time.ZoneOffset
import java.time.temporal.TemporalAmount
import java.util.UUID
import java.util.concurrent.TimeUnit
import java.util.regex.Pattern
import scala.concurrent.ExecutionContext
import scala.concurrent.Future
import scala.concurrent.duration._
Expand Down Expand Up @@ -303,6 +305,7 @@ class ReportOrchestrator(
Future.failed(AppError.CannotReportPublicAdministration)
case _ => Future.unit
}
_ <- isGouvWebsite(reportDraft)
_ <- reportDraft.companySiret match {
case Some(siret) =>
// Try to check if siret exist in signal conso database
Expand Down Expand Up @@ -1112,4 +1115,20 @@ class ReportOrchestrator(

object ReportOrchestrator {
val ReportCompanyChangeThresholdInDays: Long = 90L

def isGouvWebsite(reportDraft: ReportDraft): Future[Unit] = {

def isAGouvWebsite(input: URL): Boolean = {
val regex = "^(?!.*\\.gouv\\.fr(?:[\\/\\?#]|$)).*$"
val pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE)
!pattern.matcher(input.value).matches()
}

reportDraft.websiteURL match {
case Some(websiteURL) if isAGouvWebsite(websiteURL) =>
Future.failed(AppError.CannotReportPublicAdministration)
case _ => Future.unit
}
}

}
12 changes: 11 additions & 1 deletion test/orchestrators/ReportOrchestratorTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.specs2.mutable.Specification
import utils.AppSpec
import utils.Fixtures
import utils.TestApp

import utils.URL
import java.time.LocalDate
import java.time.OffsetDateTime
import java.time.ZoneOffset
Expand Down Expand Up @@ -242,6 +242,16 @@ class ReportOrchestratorTest(implicit ee: ExecutionEnv) extends Specification wi
res must throwA[CannotReportPublicAdministration.type].await
}

"fail when reporting gouv website " in {
val draftReportOnPublicCompany = aDraftReport.copy(
companyActivityCode = Some("90.10"),
websiteURL = Some(URL("http://totot.gouv.fr?titi=tr"))
)
val res =
components.reportOrchestrator.validateAndCreateReport(draftReportOnPublicCompany, ConsumerIp("0.0.0.0"))
res must throwA[CannotReportPublicAdministration.type].await
}

"succeed when reporting private company" in {
val draftReportOnPrivateCompany = aDraftReport.copy(
companyActivityCode = Some("90.10")
Expand Down
Loading