Filter empty domains from OrganizationsRepresentation before running validation

Closes #29809

Signed-off-by: vramik <vramik@redhat.com>
This commit is contained in:
vramik 2024-05-23 12:36:33 +02:00 committed by Pedro Igor
parent c6e071cf07
commit 0508d279f7
3 changed files with 11 additions and 1 deletions

View file

@ -92,7 +92,10 @@ public class OrganizationsResource {
throw ErrorResponse.error("Organization cannot be null.", Response.Status.BAD_REQUEST);
}
Set<String> domains = ofNullable(organization.getDomains()).orElse(Set.of()).stream().map(OrganizationDomainRepresentation::getName).collect(Collectors.toSet());
Set<String> domains = ofNullable(organization.getDomains()).orElse(Set.of()).stream()
.map(OrganizationDomainRepresentation::getName)
.filter(StringUtil::isNotBlank)
.collect(Collectors.toSet());
OrganizationModel model = provider.create(organization.getName(), domains);
Organizations.toModel(organization, model);

View file

@ -170,6 +170,7 @@ public class Organizations {
model.setAttributes(rep.getAttributes());
model.setDomains(ofNullable(rep.getDomains()).orElse(Set.of()).stream()
.filter(Objects::nonNull)
.filter(domain -> StringUtil.isNotBlank(domain.getName()))
.map(Organizations::toModel)
.collect(Collectors.toSet()));

View file

@ -375,6 +375,12 @@ public class OrganizationTest extends AbstractOrganizationTest {
assertNotNull(existing.getDomain("acme.com"));
}
@Test
public void testFilterEmptyDomain() {
//org should be created with only one domain
assertThat(createOrganization("singleValidDomainOrg", "validDomain.com", "", null).getDomains(), hasSize(1));
}
@Test
public void testDisabledOrganizationProvider() throws IOException {
OrganizationRepresentation existing = createOrganization("acme", "acme.org", "acme.net");