diff --git a/app/uk/gov/hmrc/apisubscriptionfields/model/Model.scala b/app/uk/gov/hmrc/apisubscriptionfields/model/Model.scala index 1e3d7c3..af35b50 100644 --- a/app/uk/gov/hmrc/apisubscriptionfields/model/Model.scala +++ b/app/uk/gov/hmrc/apisubscriptionfields/model/Model.scala @@ -18,6 +18,7 @@ package uk.gov.hmrc.apisubscriptionfields.model import cats.data.{NonEmptyList => NEL} import uk.gov.hmrc.apisubscriptionfields.model.FieldDefinitionType.FieldDefinitionType +import org.apache.commons.validator.routines.UrlValidator import eu.timepit.refined._ import Types._ @@ -37,7 +38,7 @@ case class RegexValidationRule(regex: RegexExpr) extends ValidationRule { case object UrlValidationRule extends ValidationRule { def validateAgainstRule(value: FieldValue): Boolean = { val schemes = Array("http","https") - val urlValidator = new org.apache.commons.validator.routines.UrlValidator(schemes) + val urlValidator = new org.apache.commons.validator.routines.UrlValidator(schemes, UrlValidator.ALLOW_LOCAL_URLS) urlValidator.isValid(value) } } diff --git a/test/uk/gov/hmrc/apisubscriptionfields/model/ModelSpec.scala b/test/uk/gov/hmrc/apisubscriptionfields/model/ModelSpec.scala index d90b3fd..1c6d5a3 100644 --- a/test/uk/gov/hmrc/apisubscriptionfields/model/ModelSpec.scala +++ b/test/uk/gov/hmrc/apisubscriptionfields/model/ModelSpec.scala @@ -47,6 +47,10 @@ class UrlValidationRuleSpec extends FunSpec with ValidationRuleTestData with Mat UrlValidationRule.validate(validUrl) shouldBe true } + describe("pass for localhost") { + UrlValidationRule.validate(localValidUrl) shouldBe true + } + describe("return true when the value is blank") { UrlValidationRule.validate("") shouldBe true } diff --git a/test/uk/gov/hmrc/apisubscriptionfields/model/ValidationRuleTestData.scala b/test/uk/gov/hmrc/apisubscriptionfields/model/ValidationRuleTestData.scala index 395b835..ca36abd 100644 --- a/test/uk/gov/hmrc/apisubscriptionfields/model/ValidationRuleTestData.scala +++ b/test/uk/gov/hmrc/apisubscriptionfields/model/ValidationRuleTestData.scala @@ -29,6 +29,7 @@ trait ValidationRuleTestData { val atLeastTenLongRule: ValidationRule = RegexValidationRule("""^.{10}.*$""") val validUrl = "https://www.example.com/here/and/there" + val localValidUrl = "https://localhost:9000/" val invalidUrls = List("www.example.com", "ftp://example.com/abc", "https://www example.com", "https://www&example.com", "https://www,example.com") }