From 3adb04b8e682338c5891fbb37bbef4b76e014491 Mon Sep 17 00:00:00 2001 From: Jay07GIT Date: Wed, 25 May 2022 13:45:17 +0530 Subject: [PATCH] update tests --- .../api/domain/DomainValidations.scala | 4 ++-- .../api/domain/DomainValidationsSpec.scala | 8 ++++---- .../batch/BatchChangeValidationsSpec.scala | 4 ++-- .../core/domain/DomainValidationErrors.scala | 18 +++++++++--------- .../core/domain/SingleChangeError.scala | 5 ++--- 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/modules/api/src/main/scala/vinyldns/api/domain/DomainValidations.scala b/modules/api/src/main/scala/vinyldns/api/domain/DomainValidations.scala index b0992dbe2..5a12eb74b 100644 --- a/modules/api/src/main/scala/vinyldns/api/domain/DomainValidations.scala +++ b/modules/api/src/main/scala/vinyldns/api/domain/DomainValidations.scala @@ -73,7 +73,7 @@ object DomainValidations { val checkRegex = validReverseZoneFQDNRegex .findFirstIn(name) .map(_.validNel) - .getOrElse(InvalidReverseZoneCame(name).invalidNel) + .getOrElse(InvalidCname(name,isReverse).invalidNel) val checkLength = validateStringLength(name, Some(HOST_MIN_LENGTH), HOST_MAX_LENGTH) checkRegex.combine(checkLength).map(_ => name) @@ -81,7 +81,7 @@ object DomainValidations { val checkRegex = validForwardZoneFQDNRegex .findFirstIn(name) .map(_.validNel) - .getOrElse(InvalidForwardZoneCame(name).invalidNel) + .getOrElse(InvalidCname(name,isReverse).invalidNel) val checkLength = validateStringLength(name, Some(HOST_MIN_LENGTH), HOST_MAX_LENGTH) checkRegex.combine(checkLength).map(_ => name) diff --git a/modules/api/src/test/scala/vinyldns/api/domain/DomainValidationsSpec.scala b/modules/api/src/test/scala/vinyldns/api/domain/DomainValidationsSpec.scala index 36bc5f462..3101f9571 100644 --- a/modules/api/src/test/scala/vinyldns/api/domain/DomainValidationsSpec.scala +++ b/modules/api/src/test/scala/vinyldns/api/domain/DomainValidationsSpec.scala @@ -22,7 +22,7 @@ import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks import org.scalatest.propspec.AnyPropSpec import org.scalatest.matchers.should.Matchers import vinyldns.api.ValidationTestImprovements._ -import vinyldns.core.domain.{InvalidDomainName, InvalidForwardZoneCame, InvalidLength} +import vinyldns.core.domain.{InvalidDomainName, InvalidCname, InvalidLength} class DomainValidationsSpec extends AnyPropSpec @@ -154,8 +154,8 @@ class DomainValidationsSpec validateCname("slash.cname./name.",true).isValid } property("Cname names with forward slash should fail with forward zone") { - validateCname("/slash.cname.name.",false).failWith[InvalidForwardZoneCame] - validateCname("slash./cname.name.",false).failWith[InvalidForwardZoneCame] - validateCname("slash.cname./name.",false).failWith[InvalidForwardZoneCame] + validateCname("/slash.cname.name.",false).failWith[InvalidCname] + validateCname("slash./cname.name.",false).failWith[InvalidCname] + validateCname("slash.cname./name.",false).failWith[InvalidCname] } } diff --git a/modules/api/src/test/scala/vinyldns/api/domain/batch/BatchChangeValidationsSpec.scala b/modules/api/src/test/scala/vinyldns/api/domain/batch/BatchChangeValidationsSpec.scala index 3e60e4cba..76b621c89 100644 --- a/modules/api/src/test/scala/vinyldns/api/domain/batch/BatchChangeValidationsSpec.scala +++ b/modules/api/src/test/scala/vinyldns/api/domain/batch/BatchChangeValidationsSpec.scala @@ -712,7 +712,7 @@ class BatchChangeValidationsSpec ) val result = validateAddChangeInput(change, false) - result should haveInvalid[DomainValidationError](InvalidDomainName(s"$invalidCNAMERecordData.")) + result should haveInvalid[DomainValidationError](InvalidCname(s"$invalidCNAMERecordData.",false)) } property("""validateAddChangeInput: should fail with InvalidLength @@ -2670,7 +2670,7 @@ class BatchChangeValidationsSpec property("validateAddChangeInput: should fail for a CNAME addChangeInput with forward slash for forward zone") { val cnameWithForwardSlash = AddChangeInput("cname.ok.", RecordType.CNAME, ttl, CNAMEData(Fqdn("cname/"))) val result = validateAddChangeInput(cnameWithForwardSlash, false) - result should haveInvalid[DomainValidationError](InvalidDomainName("cname/.")) + result should haveInvalid[DomainValidationError](InvalidCname("cname/.",false)) } property("validateAddChangeInput: should succeed for a valid CNAME addChangeInput without forward slash for forward zone") { val cname = AddChangeInput("cname.ok.", RecordType.CNAME, ttl, CNAMEData(Fqdn("cname"))) diff --git a/modules/core/src/main/scala/vinyldns/core/domain/DomainValidationErrors.scala b/modules/core/src/main/scala/vinyldns/core/domain/DomainValidationErrors.scala index 9f0babbfb..c258ad975 100644 --- a/modules/core/src/main/scala/vinyldns/core/domain/DomainValidationErrors.scala +++ b/modules/core/src/main/scala/vinyldns/core/domain/DomainValidationErrors.scala @@ -52,16 +52,16 @@ final case class InvalidDomainName(param: String) extends DomainValidationError "joined by dots, and terminated with a dot." } -final case class InvalidReverseZoneCame(param: String) extends DomainValidationError { +final case class InvalidCname(param: String, isReverseZone: Boolean) extends DomainValidationError { def message: String = - s"""Invalid Cname: "$param", valid cnames must be letters, numbers, slashes, underscores, and hyphens, """ + - "joined by dots, and terminated with a dot." -} - -final case class InvalidForwardZoneCame(param: String) extends DomainValidationError { - def message: String = - s"""Invalid Cname: "$param", valid cnames must be letters, numbers, underscores, and hyphens, """ + - "joined by dots, and terminated with a dot." + isReverseZone match { + case true => + s"""Invalid Cname: "$param", valid cnames must be letters, numbers, slashes, underscores, and hyphens, """ + + "joined by dots, and terminated with a dot." + case false => + s"""Invalid Cname: "$param", valid cnames must be letters, numbers, underscores, and hyphens, """ + + "joined by dots, and terminated with a dot." + } } final case class InvalidLength(param: String, minLengthInclusive: Int, maxLengthInclusive: Int) diff --git a/modules/core/src/main/scala/vinyldns/core/domain/SingleChangeError.scala b/modules/core/src/main/scala/vinyldns/core/domain/SingleChangeError.scala index 4e6bf7f98..c7805e74c 100644 --- a/modules/core/src/main/scala/vinyldns/core/domain/SingleChangeError.scala +++ b/modules/core/src/main/scala/vinyldns/core/domain/SingleChangeError.scala @@ -30,7 +30,7 @@ object DomainValidationErrorType extends Enumeration { type DomainValidationErrorType = Value // NOTE: once defined, an error code type cannot be changed! val ChangeLimitExceeded, BatchChangeIsEmpty, GroupDoesNotExist, NotAMemberOfOwnerGroup, - InvalidDomainName, InvalidReverseZoneCame, InvalidForwardZoneCame, InvalidLength, InvalidEmail, InvalidRecordType, InvalidPortNumber, + InvalidDomainName, InvalidCname, InvalidLength, InvalidEmail, InvalidRecordType, InvalidPortNumber, InvalidIpv4Address, InvalidIpv6Address, InvalidIPAddress, InvalidTTL, InvalidMxPreference, InvalidBatchRecordType, ZoneDiscoveryError, RecordAlreadyExists, RecordDoesNotExist, CnameIsNotUniqueError, UserIsNotAuthorized, UserIsNotAuthorizedError, RecordNameNotUniqueInBatch, @@ -46,8 +46,7 @@ object DomainValidationErrorType extends Enumeration { case _: GroupDoesNotExist => GroupDoesNotExist case _: NotAMemberOfOwnerGroup => NotAMemberOfOwnerGroup case _: InvalidDomainName => InvalidDomainName - case _: InvalidReverseZoneCame => InvalidReverseZoneCame - case _: InvalidForwardZoneCame => InvalidForwardZoneCame + case _: InvalidCname => InvalidCname case _: InvalidLength => InvalidLength case _: InvalidEmail => InvalidEmail case _: InvalidRecordType => InvalidRecordType