Skip to content

Commit

Permalink
Merge pull request #84 from hmrc/APIS-4826b
Browse files Browse the repository at this point in the history
APIS-4826: Allow local urls are valid
  • Loading branch information
NC-1234 authored Aug 3, 2020
2 parents 206cff0 + 7e701fb commit a0c2132
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/uk/gov/hmrc/apisubscriptionfields/model/Model.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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._

Expand All @@ -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)
}
}
Expand Down
4 changes: 4 additions & 0 deletions test/uk/gov/hmrc/apisubscriptionfields/model/ModelSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")

}

0 comments on commit a0c2132

Please sign in to comment.