2
0
mirror of https://github.com/VinylDNS/vinyldns synced 2025-08-31 14:25:30 +00:00

update tests

This commit is contained in:
Jay07GIT
2022-05-25 13:45:17 +05:30
parent 4896f4e823
commit 3adb04b8e6
5 changed files with 19 additions and 20 deletions

View File

@@ -73,7 +73,7 @@ object DomainValidations {
val checkRegex = validReverseZoneFQDNRegex val checkRegex = validReverseZoneFQDNRegex
.findFirstIn(name) .findFirstIn(name)
.map(_.validNel) .map(_.validNel)
.getOrElse(InvalidReverseZoneCame(name).invalidNel) .getOrElse(InvalidCname(name,isReverse).invalidNel)
val checkLength = validateStringLength(name, Some(HOST_MIN_LENGTH), HOST_MAX_LENGTH) val checkLength = validateStringLength(name, Some(HOST_MIN_LENGTH), HOST_MAX_LENGTH)
checkRegex.combine(checkLength).map(_ => name) checkRegex.combine(checkLength).map(_ => name)
@@ -81,7 +81,7 @@ object DomainValidations {
val checkRegex = validForwardZoneFQDNRegex val checkRegex = validForwardZoneFQDNRegex
.findFirstIn(name) .findFirstIn(name)
.map(_.validNel) .map(_.validNel)
.getOrElse(InvalidForwardZoneCame(name).invalidNel) .getOrElse(InvalidCname(name,isReverse).invalidNel)
val checkLength = validateStringLength(name, Some(HOST_MIN_LENGTH), HOST_MAX_LENGTH) val checkLength = validateStringLength(name, Some(HOST_MIN_LENGTH), HOST_MAX_LENGTH)
checkRegex.combine(checkLength).map(_ => name) checkRegex.combine(checkLength).map(_ => name)

View File

@@ -22,7 +22,7 @@ import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks
import org.scalatest.propspec.AnyPropSpec import org.scalatest.propspec.AnyPropSpec
import org.scalatest.matchers.should.Matchers import org.scalatest.matchers.should.Matchers
import vinyldns.api.ValidationTestImprovements._ import vinyldns.api.ValidationTestImprovements._
import vinyldns.core.domain.{InvalidDomainName, InvalidForwardZoneCame, InvalidLength} import vinyldns.core.domain.{InvalidDomainName, InvalidCname, InvalidLength}
class DomainValidationsSpec class DomainValidationsSpec
extends AnyPropSpec extends AnyPropSpec
@@ -154,8 +154,8 @@ class DomainValidationsSpec
validateCname("slash.cname./name.",true).isValid validateCname("slash.cname./name.",true).isValid
} }
property("Cname names with forward slash should fail with forward zone") { property("Cname names with forward slash should fail with forward zone") {
validateCname("/slash.cname.name.",false).failWith[InvalidForwardZoneCame] validateCname("/slash.cname.name.",false).failWith[InvalidCname]
validateCname("slash./cname.name.",false).failWith[InvalidForwardZoneCame] validateCname("slash./cname.name.",false).failWith[InvalidCname]
validateCname("slash.cname./name.",false).failWith[InvalidForwardZoneCame] validateCname("slash.cname./name.",false).failWith[InvalidCname]
} }
} }

View File

@@ -712,7 +712,7 @@ class BatchChangeValidationsSpec
) )
val result = validateAddChangeInput(change, false) 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 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") { 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 cnameWithForwardSlash = AddChangeInput("cname.ok.", RecordType.CNAME, ttl, CNAMEData(Fqdn("cname/")))
val result = validateAddChangeInput(cnameWithForwardSlash, false) 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") { 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"))) val cname = AddChangeInput("cname.ok.", RecordType.CNAME, ttl, CNAMEData(Fqdn("cname")))

View File

@@ -52,16 +52,16 @@ final case class InvalidDomainName(param: String) extends DomainValidationError
"joined by dots, and terminated with a dot." "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 = def message: String =
s"""Invalid Cname: "$param", valid cnames must be letters, numbers, slashes, underscores, and hyphens, """ + isReverseZone match {
"joined by dots, and terminated with a dot." case true =>
} 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 { case false =>
def message: String = s"""Invalid Cname: "$param", valid cnames must be letters, numbers, underscores, and hyphens, """ +
s"""Invalid Cname: "$param", valid cnames must be letters, numbers, underscores, and hyphens, """ + "joined by dots, and terminated with a dot."
"joined by dots, and terminated with a dot." }
} }
final case class InvalidLength(param: String, minLengthInclusive: Int, maxLengthInclusive: Int) final case class InvalidLength(param: String, minLengthInclusive: Int, maxLengthInclusive: Int)

View File

@@ -30,7 +30,7 @@ object DomainValidationErrorType extends Enumeration {
type DomainValidationErrorType = Value type DomainValidationErrorType = Value
// NOTE: once defined, an error code type cannot be changed! // NOTE: once defined, an error code type cannot be changed!
val ChangeLimitExceeded, BatchChangeIsEmpty, GroupDoesNotExist, NotAMemberOfOwnerGroup, val ChangeLimitExceeded, BatchChangeIsEmpty, GroupDoesNotExist, NotAMemberOfOwnerGroup,
InvalidDomainName, InvalidReverseZoneCame, InvalidForwardZoneCame, InvalidLength, InvalidEmail, InvalidRecordType, InvalidPortNumber, InvalidDomainName, InvalidCname, InvalidLength, InvalidEmail, InvalidRecordType, InvalidPortNumber,
InvalidIpv4Address, InvalidIpv6Address, InvalidIPAddress, InvalidTTL, InvalidMxPreference, InvalidIpv4Address, InvalidIpv6Address, InvalidIPAddress, InvalidTTL, InvalidMxPreference,
InvalidBatchRecordType, ZoneDiscoveryError, RecordAlreadyExists, RecordDoesNotExist, InvalidBatchRecordType, ZoneDiscoveryError, RecordAlreadyExists, RecordDoesNotExist,
CnameIsNotUniqueError, UserIsNotAuthorized, UserIsNotAuthorizedError, RecordNameNotUniqueInBatch, CnameIsNotUniqueError, UserIsNotAuthorized, UserIsNotAuthorizedError, RecordNameNotUniqueInBatch,
@@ -46,8 +46,7 @@ object DomainValidationErrorType extends Enumeration {
case _: GroupDoesNotExist => GroupDoesNotExist case _: GroupDoesNotExist => GroupDoesNotExist
case _: NotAMemberOfOwnerGroup => NotAMemberOfOwnerGroup case _: NotAMemberOfOwnerGroup => NotAMemberOfOwnerGroup
case _: InvalidDomainName => InvalidDomainName case _: InvalidDomainName => InvalidDomainName
case _: InvalidReverseZoneCame => InvalidReverseZoneCame case _: InvalidCname => InvalidCname
case _: InvalidForwardZoneCame => InvalidForwardZoneCame
case _: InvalidLength => InvalidLength case _: InvalidLength => InvalidLength
case _: InvalidEmail => InvalidEmail case _: InvalidEmail => InvalidEmail
case _: InvalidRecordType => InvalidRecordType case _: InvalidRecordType => InvalidRecordType