diff --git a/modules/api/functional_test/live_tests/batch/create_batch_change_test.py b/modules/api/functional_test/live_tests/batch/create_batch_change_test.py index cc470a17b..dee2013f0 100644 --- a/modules/api/functional_test/live_tests/batch/create_batch_change_test.py +++ b/modules/api/functional_test/live_tests/batch/create_batch_change_test.py @@ -1399,15 +1399,15 @@ def test_create_batch_change_with_readonly_user_fails(shared_zone_test_context): errors = dummy_client.create_batch_change(batch_change_input, status=400) assert_failed_change_in_error_response(errors[0], input_name="relative.ok.", record_data="4.5.6.7", - error_messages=['User \"dummy\" is not authorized. Contact zone owner group: ok-group at test@test.com.']) + error_messages=['User \"dummy\" is not authorized. Contact zone owner group: ok-group at test@test.com to make DNS changes.']) assert_failed_change_in_error_response(errors[1], input_name="delete.ok.", change_type="DeleteRecordSet", record_data="4.5.6.7", - error_messages=['User "dummy" is not authorized. Contact zone owner group: ok-group at test@test.com.']) + error_messages=['User "dummy" is not authorized. Contact zone owner group: ok-group at test@test.com to make DNS changes.']) assert_failed_change_in_error_response(errors[2], input_name="update.ok.", record_data="1.2.3.4", - error_messages=['User \"dummy\" is not authorized. Contact zone owner group: ok-group at test@test.com.']) + error_messages=['User \"dummy\" is not authorized. Contact zone owner group: ok-group at test@test.com to make DNS changes.']) assert_failed_change_in_error_response(errors[3], input_name="update.ok.", change_type="DeleteRecordSet", record_data=None, - error_messages=['User \"dummy\" is not authorized. Contact zone owner group: ok-group at test@test.com.']) + error_messages=['User \"dummy\" is not authorized. Contact zone owner group: ok-group at test@test.com to make DNS changes.']) finally: clear_ok_acl_rules(shared_zone_test_context) clear_recordset_list(to_delete, ok_client) @@ -1504,7 +1504,7 @@ def test_a_recordtype_add_checks(shared_zone_test_context): "CNAME Conflict: CNAME record names must be unique. Existing record with name \"" + existing_cname_fqdn + "\" and type \"CNAME\" conflicts with this record."]) assert_failed_change_in_error_response(response[9], input_name="user-add-unauthorized.dummy.", record_data="1.2.3.4", - error_messages=["User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com."]) + error_messages=["User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com to make DNS changes."]) finally: clear_recordset_list(to_delete, client) @@ -1644,16 +1644,16 @@ def test_a_recordtype_update_delete_checks(shared_zone_test_context): 'Record "non-existent.ok." Does Not Exist: cannot delete a record that does not exist.']) assert_failed_change_in_error_response(response[11], input_name=rs_delete_dummy_fqdn, change_type="DeleteRecordSet", - error_messages=['User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com.']) + error_messages=['User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com to make DNS changes.']) assert_failed_change_in_error_response(response[12], input_name=rs_update_dummy_fqdn, change_type="DeleteRecordSet", - error_messages=['User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com.']) + error_messages=['User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com to make DNS changes.']) assert_failed_change_in_error_response(response[13], input_name=rs_update_dummy_fqdn, ttl=300, - error_messages=['User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com.']) + error_messages=['User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com to make DNS changes.']) assert_failed_change_in_error_response(response[14], input_name=rs_update_dummy_with_owner_fqdn, change_type="DeleteRecordSet", - error_messages=['User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com.']) + error_messages=['User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com to make DNS changes.']) assert_failed_change_in_error_response(response[15], input_name=rs_update_dummy_with_owner_fqdn, ttl=300, - error_messages=['User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com.']) + error_messages=['User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com to make DNS changes.']) finally: # Clean up updates @@ -1756,7 +1756,7 @@ def test_aaaa_recordtype_add_checks(shared_zone_test_context): "CNAME Conflict: CNAME record names must be unique. Existing record with name \"" + existing_cname_fqdn+ "\" and type \"CNAME\" conflicts with this record."]) assert_failed_change_in_error_response(response[9], input_name="user-add-unauthorized.dummy.", record_type="AAAA", record_data="1::1", - error_messages=["User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com."]) + error_messages=["User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com to make DNS changes."]) finally: clear_recordset_list(to_delete, client) @@ -1881,13 +1881,13 @@ def test_aaaa_recordtype_update_delete_checks(shared_zone_test_context): record_type="AAAA", record_data="1::1") assert_failed_change_in_error_response(response[11], input_name=rs_delete_dummy_fqdn, record_type="AAAA", record_data=None, change_type="DeleteRecordSet", - error_messages=["User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com."]) + error_messages=["User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com to make DNS changes."]) assert_failed_change_in_error_response(response[12], input_name=rs_update_dummy_fqdn, record_type="AAAA", record_data="1::1", - error_messages=["User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com."]) + error_messages=["User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com to make DNS changes."]) assert_failed_change_in_error_response(response[13], input_name=rs_update_dummy_fqdn, record_type="AAAA", record_data=None, change_type="DeleteRecordSet", - error_messages=["User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com."]) + error_messages=["User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com to make DNS changes."]) finally: # Clean up updates @@ -2042,7 +2042,7 @@ def test_cname_recordtype_add_checks(shared_zone_test_context): "CNAME Conflict: CNAME record names must be unique. Existing record with name \"" + existing_reverse_fqdn + "\" and type \"PTR\" conflicts with this record."]) assert_failed_change_in_error_response(response[16], input_name="user-add-unauthorized.dummy.", record_type="CNAME", record_data="test.com.", - error_messages=["User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com."]) + error_messages=["User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com to make DNS changes."]) finally: clear_recordset_list(to_delete, client) @@ -2173,13 +2173,13 @@ def test_cname_recordtype_update_delete_checks(shared_zone_test_context): record_type="CNAME", record_data="test.com.") assert_failed_change_in_error_response(response[13], input_name="delete-unauthorized3.dummy.", record_type="CNAME", change_type="DeleteRecordSet", - error_messages=['User "ok" is not authorized. Contact zone owner group: dummy-group at test@test.com.']) + error_messages=['User "ok" is not authorized. Contact zone owner group: dummy-group at test@test.com to make DNS changes.']) assert_failed_change_in_error_response(response[14], input_name="update-unauthorized3.dummy.", record_type="CNAME", change_type="DeleteRecordSet", - error_messages=['User "ok" is not authorized. Contact zone owner group: dummy-group at test@test.com.']) + error_messages=['User "ok" is not authorized. Contact zone owner group: dummy-group at test@test.com to make DNS changes.']) assert_failed_change_in_error_response(response[15], input_name="update-unauthorized3.dummy.", record_type="CNAME", ttl=300, record_data="test.com.", - error_messages=['User "ok" is not authorized. Contact zone owner group: dummy-group at test@test.com.']) + error_messages=['User "ok" is not authorized. Contact zone owner group: dummy-group at test@test.com to make DNS changes.']) assert_successful_change_in_error_response(response[16], input_name="existing-cname2.parent.com.", record_type="CNAME", change_type="DeleteRecordSet") assert_failed_change_in_error_response(response[17], input_name="existing-cname2.parent.com.", @@ -2235,19 +2235,19 @@ def test_ptr_recordtype_auth_checks(shared_zone_test_context): assert_failed_change_in_error_response(errors[0], input_name="192.0.2.5", record_type="PTR", record_data="not.authorized.ipv4.ptr.base.", - error_messages=["User \"dummy\" is not authorized. Contact zone owner group: ok-group at test@test.com."]) + error_messages=["User \"dummy\" is not authorized. Contact zone owner group: ok-group at test@test.com to make DNS changes."]) assert_failed_change_in_error_response(errors[1], input_name="192.0.2.193", record_type="PTR", record_data="not.authorized.ipv4.ptr.classless.delegation.", - error_messages=["User \"dummy\" is not authorized. Contact zone owner group: ok-group at test@test.com."]) + error_messages=["User \"dummy\" is not authorized. Contact zone owner group: ok-group at test@test.com to make DNS changes."]) assert_failed_change_in_error_response(errors[2], input_name="fd69:27cc:fe91:1000::1234", record_type="PTR", record_data="not.authorized.ipv6.ptr.", - error_messages=["User \"dummy\" is not authorized. Contact zone owner group: ok-group at test@test.com."]) + error_messages=["User \"dummy\" is not authorized. Contact zone owner group: ok-group at test@test.com to make DNS changes."]) assert_failed_change_in_error_response(errors[3], input_name="192.0.2.25", record_type="PTR", record_data=None, change_type="DeleteRecordSet", - error_messages=["User \"dummy\" is not authorized. Contact zone owner group: ok-group at test@test.com."]) + error_messages=["User \"dummy\" is not authorized. Contact zone owner group: ok-group at test@test.com to make DNS changes."]) assert_failed_change_in_error_response(errors[4], input_name="fd69:27cc:fe91:1000::1234", record_type="PTR", record_data=None, change_type="DeleteRecordSet", - error_messages=["User \"dummy\" is not authorized. Contact zone owner group: ok-group at test@test.com."]) + error_messages=["User \"dummy\" is not authorized. Contact zone owner group: ok-group at test@test.com to make DNS changes."]) finally: clear_recordset_list(to_delete, ok_client) @@ -2721,7 +2721,7 @@ def test_txt_recordtype_add_checks(shared_zone_test_context): "CNAME Conflict: CNAME record names must be unique. Existing record with name \"" + existing_cname_fqdn + "\" and type \"CNAME\" conflicts with this record."]) assert_failed_change_in_error_response(response[7], input_name="user-add-unauthorized.dummy.", record_type="TXT", record_data="test", - error_messages=["User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com."]) + error_messages=["User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com to make DNS changes."]) finally: clear_recordset_list(to_delete, client) @@ -2832,13 +2832,13 @@ def test_txt_recordtype_update_delete_checks(shared_zone_test_context): record_data="test") assert_failed_change_in_error_response(response[9], input_name=rs_delete_dummy_fqdn, record_type="TXT", record_data=None, change_type="DeleteRecordSet", - error_messages=["User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com."]) + error_messages=["User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com to make DNS changes."]) assert_failed_change_in_error_response(response[10], input_name=rs_update_dummy_fqdn, record_type="TXT", record_data="test", - error_messages=["User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com."]) + error_messages=["User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com to make DNS changes."]) assert_failed_change_in_error_response(response[11], input_name=rs_update_dummy_fqdn, record_type="TXT", record_data=None, change_type="DeleteRecordSet", - error_messages=["User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com."]) + error_messages=["User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com to make DNS changes."]) finally: # Clean up updates @@ -2944,7 +2944,7 @@ def test_mx_recordtype_add_checks(shared_zone_test_context): "CNAME Conflict: CNAME record names must be unique. Existing record with name \"" + existing_cname_fqdn + "\" and type \"CNAME\" conflicts with this record."]) assert_failed_change_in_error_response(response[10], input_name="user-add-unauthorized.dummy.", record_type="MX", record_data={"preference": 1, "exchange": "foo.bar."}, - error_messages=["User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com."]) + error_messages=["User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com to make DNS changes."]) finally: clear_recordset_list(to_delete, client) @@ -3068,13 +3068,13 @@ def test_mx_recordtype_update_delete_checks(shared_zone_test_context): record_data={"preference": 1000, "exchange": "foo.bar."}) assert_failed_change_in_error_response(response[11], input_name=rs_delete_dummy_fqdn, record_type="MX", record_data=None, change_type="DeleteRecordSet", - error_messages=["User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com."]) + error_messages=["User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com to make DNS changes."]) assert_failed_change_in_error_response(response[12], input_name=rs_update_dummy_fqdn, record_type="MX", record_data={"preference": 1000, "exchange": "foo.bar."}, - error_messages=["User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com."]) + error_messages=["User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com to make DNS changes."]) assert_failed_change_in_error_response(response[13], input_name=rs_update_dummy_fqdn, record_type="MX", record_data=None, change_type="DeleteRecordSet", - error_messages=["User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com."]) + error_messages=["User \"ok\" is not authorized. Contact zone owner group: dummy-group at test@test.com to make DNS changes."]) finally: # Clean up updates @@ -3107,16 +3107,16 @@ def test_user_validation_ownership(shared_zone_test_context): response = client.create_batch_change(batch_change_input, status=400) assert_failed_change_in_error_response(response[0], input_name="add-test-batch.non.test.shared.", record_data="1.1.1.1", - error_messages=["User \"sharedZoneUser\" is not authorized. Contact zone owner group: testSharedZoneGroup at email."]) + error_messages=["User \"sharedZoneUser\" is not authorized. Contact zone owner group: testSharedZoneGroup at email to make DNS changes."]) assert_failed_change_in_error_response(response[1], input_name="update-test-batch.non.test.shared.", change_type="DeleteRecordSet", - error_messages=["User \"sharedZoneUser\" is not authorized. Contact zone owner group: testSharedZoneGroup at email."]) + error_messages=["User \"sharedZoneUser\" is not authorized. Contact zone owner group: testSharedZoneGroup at email to make DNS changes."]) assert_failed_change_in_error_response(response[2], input_name="update-test-batch.non.test.shared.", record_data="1.1.1.1", - error_messages=["User \"sharedZoneUser\" is not authorized. Contact zone owner group: testSharedZoneGroup at email."]) + error_messages=["User \"sharedZoneUser\" is not authorized. Contact zone owner group: testSharedZoneGroup at email to make DNS changes."]) assert_failed_change_in_error_response(response[3], input_name="delete-test-batch.non.test.shared.", change_type="DeleteRecordSet", - error_messages=["User \"sharedZoneUser\" is not authorized. Contact zone owner group: testSharedZoneGroup at email."]) + error_messages=["User \"sharedZoneUser\" is not authorized. Contact zone owner group: testSharedZoneGroup at email to make DNS changes."]) assert_successful_change_in_error_response(response[4], input_name="add-test-batch.shared.") assert_successful_change_in_error_response(response[5], input_name="update-test-batch.shared.", @@ -3144,16 +3144,16 @@ def test_user_validation_shared(shared_zone_test_context): response = client.create_batch_change(batch_change_input, status=400) assert_failed_change_in_error_response(response[0], input_name="add-test-batch.non.test.shared.", record_data="1.1.1.1", - error_messages=["User \"ok\" is not authorized. Contact zone owner group: testSharedZoneGroup at email."]) + error_messages=["User \"ok\" is not authorized. Contact zone owner group: testSharedZoneGroup at email to make DNS changes."]) assert_failed_change_in_error_response(response[1], input_name="update-test-batch.non.test.shared.", change_type="DeleteRecordSet", - error_messages=["User \"ok\" is not authorized. Contact zone owner group: testSharedZoneGroup at email."]) + error_messages=["User \"ok\" is not authorized. Contact zone owner group: testSharedZoneGroup at email to make DNS changes."]) assert_failed_change_in_error_response(response[2], input_name="update-test-batch.non.test.shared.", record_data="1.1.1.1", - error_messages=["User \"ok\" is not authorized. Contact zone owner group: testSharedZoneGroup at email."]) + error_messages=["User \"ok\" is not authorized. Contact zone owner group: testSharedZoneGroup at email to make DNS changes."]) assert_failed_change_in_error_response(response[3], input_name="delete-test-batch.non.test.shared.", change_type="DeleteRecordSet", - error_messages=["User \"ok\" is not authorized. Contact zone owner group: testSharedZoneGroup at email."]) + error_messages=["User \"ok\" is not authorized. Contact zone owner group: testSharedZoneGroup at email to make DNS changes."]) def test_create_batch_change_does_not_save_owner_group_id_for_non_shared_zone(shared_zone_test_context): @@ -3636,7 +3636,7 @@ def test_create_batch_delete_recordset_for_unassociated_user_not_in_owner_group_ assert_failed_change_in_error_response(response[0], input_name=shared_delete_fqdn, change_type="DeleteRecordSet", - error_messages=['User "list-group-user" is not authorized. Contact record owner group: record-ownergroup at test@test.com.']) + error_messages=['User "list-group-user" is not authorized. Contact record owner group: record-ownergroup at test@test.com to make DNS changes.']) finally: if create_rs: @@ -3824,7 +3824,7 @@ def test_create_batch_with_irrelevant_global_acl_rule_applied_fails(shared_zone_ response = test_user_client.create_batch_change(batch_change_input, status=400) assert_failed_change_in_error_response(response[0], input_name=a_fqdn, record_type="A", change_type="Add", record_data="192.0.2.45", - error_messages=['User "testuser" is not authorized. Contact record owner group: testSharedZoneGroup at email.']) + error_messages=['User "testuser" is not authorized. Contact record owner group: testSharedZoneGroup at email to make DNS changes.']) finally: if create_a_rs: @@ -3957,7 +3957,7 @@ def test_create_batch_delete_record_access_checks(shared_zone_test_context): assert_successful_change_in_error_response(response[3], input_name=txt_update_fqdn, record_type="TXT", record_data="test", change_type="DeleteRecordSet") assert_successful_change_in_error_response(response[4], input_name=txt_update_fqdn, record_type="TXT", record_data="updated text") assert_failed_change_in_error_response(response[5], input_name=txt_delete_fqdn, record_type="TXT", record_data="test", change_type="DeleteRecordSet", - error_messages=['User "dummy" is not authorized. Contact zone owner group: ok-group at test@test.com.']) + error_messages=['User "dummy" is not authorized. Contact zone owner group: ok-group at test@test.com to make DNS changes.']) finally: clear_ok_acl_rules(shared_zone_test_context) diff --git a/modules/api/src/main/scala/vinyldns/api/domain/membership/MembershipService.scala b/modules/api/src/main/scala/vinyldns/api/domain/membership/MembershipService.scala index 0d47bace4..5eff173b3 100644 --- a/modules/api/src/main/scala/vinyldns/api/domain/membership/MembershipService.scala +++ b/modules/api/src/main/scala/vinyldns/api/domain/membership/MembershipService.scala @@ -24,6 +24,7 @@ import vinyldns.core.domain.membership.LockStatus.LockStatus import vinyldns.core.domain.zone.ZoneRepository import vinyldns.core.domain.membership._ import vinyldns.core.domain.record.RecordSetRepository +import vinyldns.core.Messages._ object MembershipService { def apply(dataAccessor: ApiDataAccessor): MembershipService = @@ -235,7 +236,7 @@ class MembershipService( .getGroupByName(name) .map { case Some(existingGroup) if existingGroup.status != GroupStatus.Deleted => - GroupAlreadyExistsError(s"Group with name $name already exists").asLeft + GroupAlreadyExistsError(GroupAlreadyExistsErrorMsg.format(name, existingGroup.email)).asLeft case _ => ().asRight } @@ -257,7 +258,7 @@ class MembershipService( .map { case Some(existingGroup) if existingGroup.status != GroupStatus.Deleted && existingGroup.id != groupId => - GroupAlreadyExistsError(s"Group with name $name already exists").asLeft + GroupAlreadyExistsError(GroupAlreadyExistsErrorMsg.format(name, existingGroup.email)).asLeft case _ => ().asRight } @@ -267,7 +268,7 @@ class MembershipService( zoneRepo .getZonesByAdminGroupId(group.id) .map { zones => - ensuring(InvalidGroupRequestError(s"${group.name} is the admin of a zone. Cannot delete."))( + ensuring(InvalidGroupRequestError(ZoneAdminError.format(group.name)))( zones.isEmpty ) } @@ -279,7 +280,7 @@ class MembershipService( .map { rsId => ensuring( InvalidGroupRequestError( - s"${group.name} is the owner for a record set including $rsId. Cannot delete." + RecordSetOwnerError.format(group.name, rsId) ) )(rsId.isEmpty) } @@ -291,7 +292,7 @@ class MembershipService( .map { zId => ensuring( InvalidGroupRequestError( - s"${group.name} has an ACL rule for a zone including $zId. Cannot delete." + ACLRuleError.format(group.name, zId) ) )(zId.isEmpty) } diff --git a/modules/api/src/main/scala/vinyldns/api/domain/record/RecordSetValidations.scala b/modules/api/src/main/scala/vinyldns/api/domain/record/RecordSetValidations.scala index add8ba515..168f27f1d 100644 --- a/modules/api/src/main/scala/vinyldns/api/domain/record/RecordSetValidations.scala +++ b/modules/api/src/main/scala/vinyldns/api/domain/record/RecordSetValidations.scala @@ -28,6 +28,7 @@ import vinyldns.core.domain.auth.AuthPrincipal import vinyldns.core.domain.membership.Group import vinyldns.core.domain.record.{RecordSet, RecordType} import vinyldns.core.domain.zone.Zone +import vinyldns.core.Messages._ import scala.util.matching.Regex @@ -316,7 +317,7 @@ object RecordSetValidations { def validRecordNameFilterLength(recordNameFilter: String): Either[Throwable, Unit] = ensuring( - InvalidRequest("recordNameFilter must contain at least two letters or numbers.") + InvalidRequest(RecordNameFilterError) ) { val searchRegex: Regex = """[a-zA-Z0-9].*[a-zA-Z0-9]+""".r searchRegex.findFirstIn(recordNameFilter).isDefined 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 9b34f7180..8edbe5dcf 100644 --- a/modules/api/src/main/scala/vinyldns/api/route/DnsJsonProtocol.scala +++ b/modules/api/src/main/scala/vinyldns/api/route/DnsJsonProtocol.scala @@ -30,6 +30,7 @@ import vinyldns.core.domain.DomainHelpers.removeWhitespace import vinyldns.core.domain.Fqdn import vinyldns.core.domain.record._ import vinyldns.core.domain.zone._ +import vinyldns.core.Messages._ trait DnsJsonProtocol extends JsonValidation { import vinyldns.core.domain.record.RecordType._ @@ -373,7 +374,7 @@ trait DnsJsonProtocol extends JsonValidation { .required[String]("Missing NS.nsdname") .check( "NS must be less than 255 characters" -> checkDomainNameLen, - "NS data must be absolute" -> nameContainsDots + NSDataError -> nameContainsDots ) .map(Fqdn.apply) .map(NSData.apply) diff --git a/modules/api/src/test/scala/vinyldns/api/domain/record/RecordSetValidationsSpec.scala b/modules/api/src/test/scala/vinyldns/api/domain/record/RecordSetValidationsSpec.scala index e77f900a3..ac9a0df36 100644 --- a/modules/api/src/test/scala/vinyldns/api/domain/record/RecordSetValidationsSpec.scala +++ b/modules/api/src/test/scala/vinyldns/api/domain/record/RecordSetValidationsSpec.scala @@ -36,6 +36,7 @@ import vinyldns.core.TestMembershipData._ import vinyldns.core.domain.Fqdn import vinyldns.core.domain.membership.Group import vinyldns.core.domain.record._ +import vinyldns.core.Messages._ import scala.util.matching.Regex @@ -601,7 +602,7 @@ class RecordSetValidationsSpec val invalidString = "*o*" val error = leftValue(validRecordNameFilterLength(invalidString)) error shouldBe an[InvalidRequest] - error.getMessage() shouldBe "recordNameFilter must contain at least two letters or numbers." + error.getMessage() shouldBe RecordNameFilterError } } } diff --git a/modules/api/src/test/scala/vinyldns/api/route/VinylDNSJsonProtocolSpec.scala b/modules/api/src/test/scala/vinyldns/api/route/VinylDNSJsonProtocolSpec.scala index 64b8b3f8a..d566637c2 100644 --- a/modules/api/src/test/scala/vinyldns/api/route/VinylDNSJsonProtocolSpec.scala +++ b/modules/api/src/test/scala/vinyldns/api/route/VinylDNSJsonProtocolSpec.scala @@ -27,6 +27,7 @@ import vinyldns.core.domain.record._ import vinyldns.core.domain.zone.{CreateZoneInput, UpdateZoneInput, ZoneConnection} import vinyldns.core.TestRecordSetData._ import vinyldns.core.domain.Fqdn +import vinyldns.core.Messages._ class VinylDNSJsonProtocolSpec extends AnyWordSpec @@ -594,7 +595,7 @@ class VinylDNSJsonProtocolSpec ("records" -> data) val thrown = the[MappingException] thrownBy recordSetJValue.extract[RecordSet] - thrown.msg should include("NS data must be absolute") + thrown.msg should include(NSDataError) } "round trip a DS record set" in { val rs = RecordSet( diff --git a/modules/core/src/main/scala/vinyldns/core/Messages.scala b/modules/core/src/main/scala/vinyldns/core/Messages.scala new file mode 100644 index 000000000..4275b1c88 --- /dev/null +++ b/modules/core/src/main/scala/vinyldns/core/Messages.scala @@ -0,0 +1,76 @@ +/* + * Copyright 2018 Comcast Cable Communications Management, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package vinyldns.core + +object Messages { + + // Error displayed when less than two letters or numbers is filled in Record Name Filter field in RecordSetSearch page + val RecordNameFilterError = "Record Name Filter field must contain at least two letters or numbers to perform a RecordSet Search." + + /* + * Error displayed when attempting to create group with name that already exists + * + * Placeholders: + * 1. [string] group name + * 2. [string] group email address + */ + val GroupAlreadyExistsErrorMsg = "Group with name %s already exists. Please try a different name or contact %s to be added to the group." + + /* + * Error displayed when deleting a group being the admin of a zone + * + * Placeholders: + * 1. [string] group name + */ + val ZoneAdminError = "%s is the admin of a zone. Cannot delete. Please transfer the ownership to another group before deleting." + + /* + * Error displayed when deleting a group being the owner for a record set + * + * Placeholders: + * 1. [string] group name + * 2. [string] record set id + */ + val RecordSetOwnerError = "%s is the owner for a record set including %s. Cannot delete. Please transfer the ownership to another group before deleting." + + /* + * Error displayed when deleting a group which has an ACL rule for a zone + * + * Placeholders: + * 1. [string] group name + * 2. [string] zone id + */ + val ACLRuleError = "%s has an ACL rule for a zone including %s. Cannot delete. Please transfer the ownership to another group before deleting." + + // Error displayed when NSData field is not a positive integer + val NSDataError = "NS data must be a positive integer" + + // Error displayed when importing files other than .csv + val ImportError = "Import failed. Not a valid file. File should be of ‘.csv’ type." + + /* + * Error displayed when user is not authorized to make changes to the record + * + * Placeholders: + * 1. [string] user name + * 2. [string] owner type + * 3. [string] owner group name | owner group id + * 4. [string] contact email + */ + val NotAuthorizedErrorMsg = "User \"%s\" is not authorized. Contact %s owner group: %s at %s to make DNS changes." + +} 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 591d5c7cd..91486ce79 100644 --- a/modules/core/src/main/scala/vinyldns/core/domain/DomainValidationErrors.scala +++ b/modules/core/src/main/scala/vinyldns/core/domain/DomainValidationErrors.scala @@ -19,6 +19,7 @@ package vinyldns.core.domain import vinyldns.core.domain.batch.OwnerType.OwnerType import vinyldns.core.domain.record.{RecordData, RecordSet, RecordType} import vinyldns.core.domain.record.RecordType.RecordType +import vinyldns.core.Messages._ // $COVERAGE-OFF$ sealed abstract class DomainValidationError(val isFatal: Boolean = true) { @@ -134,9 +135,12 @@ final case class UserIsNotAuthorizedError( ownerGroupName: Option[String] = None ) extends DomainValidationError { def message: String = - s"""User "$userName" is not authorized. Contact ${ownerType.toString.toLowerCase} owner group: - |${ownerGroupName.getOrElse(ownerGroupId)} at ${contactEmail.getOrElse("")}.""".stripMargin - .replaceAll("\n", " ") + NotAuthorizedErrorMsg.format( + userName, + ownerType.toString.toLowerCase, + ownerGroupName.getOrElse(ownerGroupId), + contactEmail.getOrElse("") + ) } final case class RecordNameNotUniqueInBatch(name: String, typ: RecordType) diff --git a/modules/portal/public/lib/dns-change/dns-change-new.controller.js b/modules/portal/public/lib/dns-change/dns-change-new.controller.js index 70848ee76..a0234c0ba 100644 --- a/modules/portal/public/lib/dns-change/dns-change-new.controller.js +++ b/modules/portal/public/lib/dns-change/dns-change-new.controller.js @@ -177,7 +177,7 @@ $scope.$apply() resolve($scope.newBatch.changes.length); } else { - reject("Import failed. Not a valid file."); + reject("Import failed. Not a valid file. File should be of ‘.csv’ type."); } } reader.readAsText(file);