1
0
mirror of https://github.com/google/nomulus synced 2026-01-04 04:04:22 +00:00

Update RDAP TOS link (#2678)

This commit is contained in:
Lai Jiang
2025-02-18 12:00:26 -05:00
committed by GitHub
parent 6f7ae1eabc
commit df7fec7a3e
5 changed files with 11 additions and 39 deletions

View File

@@ -70,7 +70,7 @@ import google.registry.rdap.RdapObjectClasses.RdapRegistrarEntity;
import google.registry.rdap.RdapObjectClasses.SecureDns;
import google.registry.rdap.RdapObjectClasses.Vcard;
import google.registry.rdap.RdapObjectClasses.VcardArray;
import google.registry.request.FullServletPath;
import google.registry.request.RequestServerName;
import google.registry.util.Clock;
import jakarta.persistence.Entity;
import java.net.Inet4Address;
@@ -114,7 +114,7 @@ public class RdapJsonFormatter {
@Nullable
String rdapTosStaticUrl;
@Inject @FullServletPath String fullServletPath;
@Inject @RequestServerName String serverName;
@Inject RdapAuthorization rdapAuthorization;
@Inject Clock clock;
@@ -267,7 +267,7 @@ public class RdapJsonFormatter {
.setDescription(rdapTos)
.addLink(selfLink);
if (rdapTosStaticUrl != null) {
URI htmlBaseURI = URI.create(fullServletPath);
URI htmlBaseURI = URI.create("https//:" + serverName + "/rdap/");
URI htmlUri = htmlBaseURI.resolve(rdapTosStaticUrl);
noticeBuilder.addLink(
Link.builder()
@@ -1071,7 +1071,7 @@ public class RdapJsonFormatter {
/** Create a link relative to the RDAP server endpoint. */
String makeRdapServletRelativeUrl(String part, String... moreParts) {
return makeServerRelativeUrl(fullServletPath, part, moreParts);
return makeServerRelativeUrl("https://" + serverName + "/rdap/", part, moreParts);
}
/** Create a link relative to some base server */

View File

@@ -151,17 +151,9 @@ public final class RequestModule {
* query string.
*/
@Provides
@FullServletPath
static String provideFullServletPath(HttpServletRequest req) {
// Include the port only if it differs from the default for the scheme.
if (("http".equals(req.getScheme()) && (req.getServerPort() == 80))
|| ("https".equals(req.getScheme()) && (req.getServerPort() == 443))) {
return String.format("%s://%s%s", req.getScheme(), req.getServerName(), req.getServletPath());
} else {
return String.format(
"%s://%s:%d%s",
req.getScheme(), req.getServerName(), req.getServerPort(), req.getServletPath());
}
@RequestServerName
static String provideServerName(HttpServletRequest req) {
return req.getServerName();
}
@Provides

View File

@@ -20,11 +20,11 @@ import java.lang.annotation.RetentionPolicy;
import javax.inject.Qualifier;
/**
* Dagger qualifier for the HTTP servlet path, prepended with scheme, host and port.
* Dagger qualifier for the server name of the HTTP request.
*
* <p>See {@link jakarta.servlet.http.HttpServletRequest#getServletPath}
* <p>See {@link jakarta.servlet.http.HttpServletRequest#getServerName()}
*/
@Qualifier
@Documented
@Retention(RetentionPolicy.RUNTIME)
public @interface FullServletPath {}
public @interface RequestServerName {}

View File

@@ -406,26 +406,6 @@ class RdapJsonFormatterTest {
.isEqualTo(loadJson("rdapjson_registrant_logged_out.json"));
}
@Test
void testRegistrant_baseHasNoTrailingSlash() {
// First, make sure we have a trailing slash at the end by default!
// This test tries to change the default state, if the default doesn't have a /, then this test
// doesn't help.
assertThat(rdapJsonFormatter.fullServletPath).endsWith("/");
rdapJsonFormatter.fullServletPath =
rdapJsonFormatter.fullServletPath.substring(
0, rdapJsonFormatter.fullServletPath.length() - 1);
assertAboutJson()
.that(
rdapJsonFormatter
.createRdapContactEntity(
contactRegistrant,
ImmutableSet.of(RdapEntity.Role.REGISTRANT),
OutputDataType.FULL)
.toJson())
.isEqualTo(loadJson("rdapjson_registrant.json"));
}
@Test
void testAdmin() {
assertAboutJson()

View File

@@ -150,7 +150,7 @@ class RdapTestHelper {
static RdapJsonFormatter getTestRdapJsonFormatter(Clock clock) {
RdapJsonFormatter rdapJsonFormatter = new RdapJsonFormatter();
rdapJsonFormatter.rdapAuthorization = RdapAuthorization.PUBLIC_AUTHORIZATION;
rdapJsonFormatter.fullServletPath = "https://example.tld/rdap/";
rdapJsonFormatter.serverName = "example.tld";
rdapJsonFormatter.clock = clock;
rdapJsonFormatter.rdapTos =
ImmutableList.of(