From 18895e321da31910bfb2a66bcb488cf413e11c5e Mon Sep 17 00:00:00 2001 From: mherran Date: Mon, 23 Dec 2024 11:44:10 +0100 Subject: [PATCH] feat: fix mntner when querying by handle in RDAP entities --- .../db/whois/api/rdap/RdapObjectMapper.java | 8 +++++++- .../net/ripe/db/whois/api/rdap/RdapService.java | 2 +- .../RdapElasticServiceTestIntegration.java | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/whois-api/src/main/java/net/ripe/db/whois/api/rdap/RdapObjectMapper.java b/whois-api/src/main/java/net/ripe/db/whois/api/rdap/RdapObjectMapper.java index 1743319603..69229bd3ef 100644 --- a/whois-api/src/main/java/net/ripe/db/whois/api/rdap/RdapObjectMapper.java +++ b/whois-api/src/main/java/net/ripe/db/whois/api/rdap/RdapObjectMapper.java @@ -501,7 +501,13 @@ private static Event createEvent(final LocalDateTime lastChanged, final Action a private void mapContactEntities(final RdapObject rdapObject, final RpslObject rpslObject, final String requestUrl) { final Map contactsEntities = Maps.newTreeMap(); - final List filteredAttributes = rpslObject.getAttributes().stream().filter( rpslAttribute -> CONTACT_ATTRIBUTE_TO_ROLE_NAME.containsKey(rpslAttribute.getType())).collect(Collectors.toList()); + final List filteredAttributes = rpslObject.getAttributes().stream().filter( rpslAttribute -> { + final AttributeType attributeType = rpslAttribute.getType(); + if (attributeType == null){ + return false; + } + return CONTACT_ATTRIBUTE_TO_ROLE_NAME.containsKey(rpslAttribute.getType()); + }).toList(); filteredAttributes.forEach( rpslAttribute -> { for (final CIString value : rpslAttribute.getCleanValues()) { diff --git a/whois-api/src/main/java/net/ripe/db/whois/api/rdap/RdapService.java b/whois-api/src/main/java/net/ripe/db/whois/api/rdap/RdapService.java index 4ecef0d38a..b925610e44 100644 --- a/whois-api/src/main/java/net/ripe/db/whois/api/rdap/RdapService.java +++ b/whois-api/src/main/java/net/ripe/db/whois/api/rdap/RdapService.java @@ -171,7 +171,7 @@ public Response searchEntities( } if (name == null && handle != null) { - return handleSearch(new String[]{"organisation", "nic-hdl"}, handle, request); + return handleSearch(new String[]{"organisation", "nic-hdl", "mntner"}, handle, request); } throw new RdapException("400 Bad Request", "Either fn or handle is a required parameter, but never both", HttpStatus.BAD_REQUEST_400); diff --git a/whois-api/src/test/java/net/ripe/db/whois/api/elasticsearch/RdapElasticServiceTestIntegration.java b/whois-api/src/test/java/net/ripe/db/whois/api/elasticsearch/RdapElasticServiceTestIntegration.java index 518f545fa5..af299a849a 100644 --- a/whois-api/src/test/java/net/ripe/db/whois/api/elasticsearch/RdapElasticServiceTestIntegration.java +++ b/whois-api/src/test/java/net/ripe/db/whois/api/elasticsearch/RdapElasticServiceTestIntegration.java @@ -653,6 +653,23 @@ public void search_entity_multiple_object_response() { assertThat(result.getNotices().get(0).getTitle(), is("Terms and Conditions")); } + @Test + public void search_entity_handle_mntner_then_response() { + + final SearchResult result = createResource("entities?handle=OWNER-MNT") + .request(MediaType.APPLICATION_JSON_TYPE) + .get(SearchResult.class); + + assertThat( + result.getEntitySearchResults() + .stream() + .map(Entity::getHandle) + .collect(Collectors.toList()), + containsInAnyOrder("OWNER-MNT")); + assertThat(result.getNotices(), hasSize(1)); + assertThat(result.getNotices().getFirst().getTitle(), is("Terms and Conditions")); + } + @Test public void lookup_person_entity_acl_denied() { try {