mirror of
https://github.com/google/nomulus.git
synced 2025-07-10 05:03:24 +02:00
Validate provided email addresses when creating a registrar
This commit is contained in:
parent
8f2a8835d7
commit
7cf0dce057
9 changed files with 135 additions and 24 deletions
|
@ -452,6 +452,42 @@ public class RegistrarTest extends EntityTestCase {
|
|||
() -> registrar.asBuilder().setAllowedTldsUncached(ImmutableSet.of("bad")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_nullEmail() {
|
||||
NullPointerException thrown =
|
||||
assertThrows(NullPointerException.class, () -> registrar.asBuilder().setEmailAddress(null));
|
||||
assertThat(thrown).hasMessageThat().isEqualTo("Provided email was null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_invalidEmail() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> registrar.asBuilder().setEmailAddress("lolcat"));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.isEqualTo("Provided email lolcat is not a valid email address");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_nullIcannReferralEmail() {
|
||||
NullPointerException thrown =
|
||||
assertThrows(
|
||||
NullPointerException.class, () -> registrar.asBuilder().setIcannReferralEmail(null));
|
||||
assertThat(thrown).hasMessageThat().isEqualTo("Provided email was null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_invalidIcannEmail() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> registrar.asBuilder().setIcannReferralEmail("lolcat"));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.isEqualTo("Provided email lolcat is not a valid email address");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_setAllowedTldsUncached_newTldNotInCache() {
|
||||
int origSingletonCacheRefreshSeconds =
|
||||
|
|
|
@ -1771,4 +1771,28 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
|
|||
"--cc US",
|
||||
"clientz"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_badEmail() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
runCommandForced(
|
||||
"--name=blobio",
|
||||
"--password=some_password",
|
||||
"--registrar_type=REAL",
|
||||
"--iana_id=8",
|
||||
"--passcode=01234",
|
||||
"--icann_referral_email=lolcat",
|
||||
"--street=\"123 Fake St\"",
|
||||
"--city Fakington",
|
||||
"--state MA",
|
||||
"--zip 00351",
|
||||
"--cc US",
|
||||
"clientz"));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.isEqualTo("Provided email lolcat is not a valid email address");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -367,4 +367,26 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
|
|||
"--mode=CREATE", "--name=Jim Doe", "--email=jim.doe@example.com", "NewRegistrar");
|
||||
assertThat(loadRegistrar("NewRegistrar").getContactsRequireSyncing()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreate_failure_badEmail() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
runCommandForced(
|
||||
"--mode=CREATE", "--name=Jim Doe", "--email=lolcat", "NewRegistrar"));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.isEqualTo("Provided email lolcat is not a valid email address");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreate_failure_nullEmail() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> runCommandForced("--mode=CREATE", "--name=Jim Doe", "NewRegistrar"));
|
||||
assertThat(thrown).hasMessageThat().isEqualTo("--email is required when --mode=CREATE");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -815,6 +815,17 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
|
|||
assertThat(loadRegistrar("NewRegistrar").getPoNumber()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_badEmail() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> runCommand("--email=lolcat", "--force", "NewRegistrar"));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.isEqualTo("Provided email lolcat is not a valid email address");
|
||||
}
|
||||
|
||||
private void persistWhoisAbuseContact() {
|
||||
persistResource(
|
||||
AppEngineRule.makeRegistrarContact1()
|
||||
|
|
|
@ -412,6 +412,27 @@ public final class ConsoleRegistrarCreatorActionTest {
|
|||
assertThat(registrar.getPhonePasscode()).isEqualTo("10203");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPost_badEmailFails() {
|
||||
action.clientId = Optional.of("myclientid");
|
||||
action.name = Optional.of("registrar name");
|
||||
action.billingAccount = Optional.of("USD=billing-account");
|
||||
action.ianaId = Optional.of(12321);
|
||||
action.referralEmail = Optional.of("lolcat");
|
||||
action.driveId = Optional.of("drive-id");
|
||||
action.consoleUserEmail = Optional.of("myclientid@registry.example");
|
||||
|
||||
action.street1 = Optional.of("my street");
|
||||
action.city = Optional.of("my city");
|
||||
action.countryCode = Optional.of("CC");
|
||||
|
||||
action.method = Method.POST;
|
||||
action.run();
|
||||
|
||||
assertThat(response.getPayload())
|
||||
.contains("Failed: Provided email lolcat is not a valid email address");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPost_unauthorized() {
|
||||
action.registrarAccessor =
|
||||
|
|
|
@ -151,24 +151,6 @@ public class RegistrarSettingsActionTest extends RegistrarSettingsActionTestCase
|
|||
assertMetric(CLIENT_ID, "update", "[OWNER]", "ERROR: FormFieldException");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdate_emptyJsonObject_emailFieldNotRequiredWhenEmpty() {
|
||||
persistResource(loadRegistrar(CLIENT_ID).asBuilder().setEmailAddress(null).build());
|
||||
Map<String, Object> args = Maps.newHashMap(loadRegistrar(CLIENT_ID).toJsonMap());
|
||||
args.remove("emailAddress");
|
||||
|
||||
Map<String, Object> response = action.handleJsonRequest(ImmutableMap.of(
|
||||
"op", "update",
|
||||
"id", CLIENT_ID,
|
||||
"args", args));
|
||||
|
||||
assertThat(response).containsExactly(
|
||||
"status", "SUCCESS",
|
||||
"message", "Saved TheRegistrar",
|
||||
"results", ImmutableList.of(loadRegistrar(CLIENT_ID).toJsonMap()));
|
||||
assertMetric(CLIENT_ID, "update", "[OWNER]", "SUCCESS");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_updateRegistrarInfo_notAuthorized() {
|
||||
setUserWithoutAccess();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue