mirror of
https://github.com/google/nomulus
synced 2026-08-20 22:26:12 +00:00
Return proper RDAP error messages when invalid IP addresses are specified
We were relying on Dagger to validate the IP address, but that resulted in 500 errors when the IP address was not valid, which is undesirable. Instead, accept the parameters as strings, then convert them to IP addresses and throw a proper error when conversion fails. Also fixes an improperly specified test. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=173172516
This commit is contained in:
@@ -22,6 +22,7 @@ import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.net.InetAddresses;
|
||||
import com.google.common.primitives.Booleans;
|
||||
import com.googlecode.objectify.cmd.Query;
|
||||
import google.registry.model.domain.DomainResource;
|
||||
@@ -66,7 +67,7 @@ public class RdapNameserverSearchAction extends RdapActionBase {
|
||||
|
||||
@Inject Clock clock;
|
||||
@Inject @Parameter("name") Optional<String> nameParam;
|
||||
@Inject @Parameter("ip") Optional<InetAddress> ipParam;
|
||||
@Inject @Parameter("ip") Optional<String> ipParam;
|
||||
@Inject RdapNameserverSearchAction() {}
|
||||
|
||||
@Override
|
||||
@@ -107,7 +108,13 @@ public class RdapNameserverSearchAction extends RdapActionBase {
|
||||
results = searchByName(RdapSearchPattern.create(Idn.toASCII(nameParam.get()), true), now);
|
||||
} else {
|
||||
// syntax: /rdap/nameservers?ip=1.2.3.4
|
||||
results = searchByIp(ipParam.get(), now);
|
||||
InetAddress inetAddress;
|
||||
try {
|
||||
inetAddress = InetAddresses.forString(ipParam.get());
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new BadRequestException("Invalid value of ip parameter");
|
||||
}
|
||||
results = searchByIp(inetAddress, now);
|
||||
}
|
||||
if (results.jsonList().isEmpty()) {
|
||||
throw new NotFoundException("No nameservers found");
|
||||
|
||||
Reference in New Issue
Block a user