Don't override existing registrar email address when setting referral email (#2300)

The fallback should only apply on creates, not on updates, otherwise it can
override an existing value for the email address when only the referral email
should be what's updated.

This fixes a bug introduced back in commit in 0ead4f8d9d.

BUG= http://b/322026165
This commit is contained in:
Ben McIlwain 2024-01-30 12:31:54 -05:00 committed by GitHub
parent 829be0777b
commit 5e36cf30c3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 5 deletions

View file

@ -292,8 +292,8 @@ abstract class CreateOrUpdateRegistrarCommand extends MutatingCommand {
}
if (!isNullOrEmpty(email)) {
builder.setEmailAddress(email);
} else if (!isNullOrEmpty(
icannReferralEmail)) { // fall back to ICANN referral email if present
} else if (!isNullOrEmpty(icannReferralEmail) && oldRegistrar == null) {
// On creates, fall back to ICANN referral email (if present).
builder.setEmailAddress(icannReferralEmail);
}
if (url != null) {

View file

@ -637,10 +637,12 @@ class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarCommand>
@Test
void testSuccess_setIcannEmail() throws Exception {
runCommand("--icann_referral_email=foo@bar.test", "--force", "TheRegistrar");
Registrar registrar = loadRegistrar("TheRegistrar");
assertThat(registrar.getIcannReferralEmail()).isEqualTo("foo@bar.test");
assertThat(registrar.getEmailAddress()).isEqualTo("foo@bar.test");
assertThat(registrar.getEmailAddress()).isEqualTo("the.registrar@example.com");
runCommand("--icann_referral_email=foo@bar.test", "--force", "TheRegistrar");
Registrar updatedRegistrar = loadRegistrar("TheRegistrar");
assertThat(updatedRegistrar.getIcannReferralEmail()).isEqualTo("foo@bar.test");
assertThat(updatedRegistrar.getEmailAddress()).isEqualTo("the.registrar@example.com");
}
@Test