Fix usage of OutgoingEmailValidator to make sure TLD override works

The call to DomainValidator.updateTLDOverride may only be done before
the call to EmailValidator.getInstance otherwise it throws an exception.

Putting the DomainValidator.updateTLDOverride call inside a static
block doesn't seem to be safe enough. Protect it with an atomic boolean
insteed.

Also fix CreateEmail and CreateAccount to use OutgoingEmailValidator
instead of EmailValidator.getInstance directly. By directly using it we
don't necessarily set up the TLD override correctly before first use.

Bug: Issue 4521
Change-Id: I92a6c98d8ae188c08da7c0a077d67000dfdab4fd
This commit is contained in:
David Pursehouse
2016-09-08 17:43:25 +09:00
parent fdfc3738fc
commit 3aaf831893
3 changed files with 10 additions and 8 deletions

View File

@@ -38,6 +38,7 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.account.CreateAccount.Input;
import com.google.gerrit.server.group.GroupsCollection;
import com.google.gerrit.server.mail.OutgoingEmailValidator;
import com.google.gerrit.server.ssh.SshKeyCache;
import com.google.gwtorm.server.OrmDuplicateKeyException;
import com.google.gwtorm.server.OrmException;
@@ -45,8 +46,6 @@ import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.assistedinject.Assisted;
import org.apache.commons.validator.routines.EmailValidator;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -132,7 +131,7 @@ public class CreateAccount implements RestModifyView<TopLevelResource, Input> {
throw new UnprocessableEntityException(
"email '" + input.email + "' already exists");
}
if (!EmailValidator.getInstance().isValid(input.email)) {
if (!OutgoingEmailValidator.isValid(input.email)) {
throw new BadRequestException("invalid email address");
}
}