From 839b683dfe908ac2cf4d81d4ac278d195e824540 Mon Sep 17 00:00:00 2001 From: Aravindh-Raju Date: Tue, 30 May 2023 12:51:56 +0530 Subject: [PATCH] Add naptr validations --- .../vinyldns/api/route/DnsJsonProtocol.scala | 6 +++-- .../api/route/RecordSetRoutingSpec.scala | 10 ++++----- modules/portal/public/css/vinyldns.css | 6 +++-- .../lib/controllers/controller.records.js | 1 + .../portal/public/templates/record-modal.html | 22 ++++++++++--------- 5 files changed, 26 insertions(+), 19 deletions(-) diff --git a/modules/api/src/main/scala/vinyldns/api/route/DnsJsonProtocol.scala b/modules/api/src/main/scala/vinyldns/api/route/DnsJsonProtocol.scala index 8dba45315..7a23a9e2f 100644 --- a/modules/api/src/main/scala/vinyldns/api/route/DnsJsonProtocol.scala +++ b/modules/api/src/main/scala/vinyldns/api/route/DnsJsonProtocol.scala @@ -169,6 +169,8 @@ trait DnsJsonProtocol extends JsonValidation { } def checkDomainNameLen(s: String): Boolean = s.length <= 255 + def validateNaptrFlag(flag: String): Boolean = flag == "U" || flag == "S" || flag == "A" || flag == "P" + def validateNaptrRegexp(regexp: String): Boolean = regexp.startsWith("!") && regexp.endsWith("!") || regexp == "" def nameContainsDots(s: String): Boolean = s.contains(".") def nameDoesNotContainSpaces(s: String): Boolean = !s.contains(" ") @@ -514,7 +516,7 @@ trait DnsJsonProtocol extends JsonValidation { (js \ "flags") .required[String]("Missing NAPTR.flags") .check( - "NAPTR.flags must be less than 2 characters" -> (_.length < 2) + "Invalid NAPTR.flag. Valid NAPTR flag value must be U, S, A or P" -> validateNaptrFlag ), (js \ "service") .required[String]("Missing NAPTR.service") @@ -524,7 +526,7 @@ trait DnsJsonProtocol extends JsonValidation { (js \ "regexp") .required[String]("Missing NAPTR.regexp") .check( - "NAPTR.regexp must be less than 255 characters" -> checkDomainNameLen + "Invalid NAPTR.regexp. Valid NAPTR regexp value must start and end with '!' or can be empty" -> validateNaptrRegexp ), (js \ "replacement") diff --git a/modules/api/src/test/scala/vinyldns/api/route/RecordSetRoutingSpec.scala b/modules/api/src/test/scala/vinyldns/api/route/RecordSetRoutingSpec.scala index 019ab58fa..1e4286628 100644 --- a/modules/api/src/test/scala/vinyldns/api/route/RecordSetRoutingSpec.scala +++ b/modules/api/src/test/scala/vinyldns/api/route/RecordSetRoutingSpec.scala @@ -1480,11 +1480,11 @@ class RecordSetRoutingSpec } "return errors for invalid NAPTR record data" in { + val validFlags = List("U", "S", "A", "P") validateErrors( testRecordType( RecordType.NAPTR, ("replacement" -> Random.alphanumeric.take(260).mkString) ~~ - // should check regex better ("regexp" -> Random.alphanumeric.take(260).mkString) ~~ ("service" -> Random.alphanumeric.take(260).mkString) ~~ ("flags" -> Random.alphanumeric.take(2).mkString) ~~ @@ -1493,18 +1493,18 @@ class RecordSetRoutingSpec ), "NAPTR.order must be an unsigned 16 bit number", "NAPTR.preference must be an unsigned 16 bit number", - "NAPTR.flags must be less than 2 characters", + "Invalid NAPTR.flag. Valid NAPTR flag value must be U, S, A or P", "NAPTR.service must be less than 255 characters", - "NAPTR.regexp must be less than 255 characters", + "Invalid NAPTR.regexp. Valid NAPTR regexp value must start and end with '!' or can be empty", "NAPTR.replacement must be less than 255 characters" ) validateErrors( testRecordType( RecordType.NAPTR, - ("regexp" -> Random.alphanumeric.take(10).mkString) ~~ + ("regexp" -> "") ~~ ("service" -> Random.alphanumeric.take(10).mkString) ~~ ("replacement" -> Random.alphanumeric.take(10).mkString) ~~ - ("flags" -> Random.alphanumeric.take(1).mkString) ~~ + ("flags" -> validFlags.take(1).mkString) ~~ ("order" -> -1) ~~ ("preference" -> -1) ), diff --git a/modules/portal/public/css/vinyldns.css b/modules/portal/public/css/vinyldns.css index 075b496a3..24efabf8a 100644 --- a/modules/portal/public/css/vinyldns.css +++ b/modules/portal/public/css/vinyldns.css @@ -538,6 +538,8 @@ input[type="file"] { padding: 0px; margin: 0px; } - - /* Ending of css override for cron library and it's associated elements used in zone sync scheduling */ + +#set-dropdown-width { + width: 4em; +} diff --git a/modules/portal/public/lib/controllers/controller.records.js b/modules/portal/public/lib/controllers/controller.records.js index 46beaca0a..f3801e58a 100644 --- a/modules/portal/public/lib/controllers/controller.records.js +++ b/modules/portal/public/lib/controllers/controller.records.js @@ -29,6 +29,7 @@ angular.module('controller.records', []) $scope.recordTypes = ['A', 'AAAA', 'CNAME', 'DS', 'MX', 'NS', 'PTR', 'SRV', 'NAPTR', 'SSHFP', 'TXT']; $scope.readRecordTypes = ['A', 'AAAA', 'CNAME', 'DS', 'MX', 'NS', 'PTR', "SOA", 'SRV', 'NAPTR', 'SSHFP', 'TXT']; $scope.selectedRecordTypes = []; + $scope.naptrFlags = ["U", "S", "A", "P"]; $scope.sshfpAlgorithms = [{name: '(1) RSA', number: 1}, {name: '(2) DSA', number: 2}, {name: '(3) ECDSA', number: 3}, {name: '(4) Ed25519', number: 4}]; $scope.sshfpTypes = [{name: '(1) SHA-1', number: 1}, {name: '(2) SHA-256', number: 2}]; diff --git a/modules/portal/public/templates/record-modal.html b/modules/portal/public/templates/record-modal.html index 857776c69..42ce61557 100644 --- a/modules/portal/public/templates/record-modal.html +++ b/modules/portal/public/templates/record-modal.html @@ -324,7 +324,7 @@ required/> - - + - - -