Skip to content

Commit

Permalink
Add unit test for ScimUserEndpoints: should throw during creation if …
Browse files Browse the repository at this point in the history
…alias properties are invalid
  • Loading branch information
adrianhoelzl-sap committed Apr 17, 2024
1 parent 9001886 commit 5e682bc
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;

Expand Down Expand Up @@ -141,7 +142,6 @@ class ScimUserEndpointsTests {
@Autowired
private IdentityZoneManager identityZoneManager;

@Autowired
private ScimUserAliasHandler scimUserAliasHandler;

@Autowired
Expand Down Expand Up @@ -207,6 +207,12 @@ void setUpAfterSeeding(final IdentityZone identityZone) {

spiedScimGroupMembershipManager = spy(scimGroupMembershipManager);

scimUserAliasHandler = mock(ScimUserAliasHandler.class);
when(scimUserAliasHandler.aliasPropertiesAreValid(any(), any())).thenReturn(true);
when(scimUserAliasHandler.ensureConsistencyOfAliasEntity(any(), any()))
.then(invocationOnMock -> invocationOnMock.getArgument(0));
when(scimUserAliasHandler.retrieveAliasEntity(any())).thenReturn(Optional.empty());

scimUserEndpoints = new ScimUserEndpoints(
new IdentityZoneManagerImpl(),
new IsSelfCheck(null),
Expand Down Expand Up @@ -385,6 +391,25 @@ void createUser_whenPasswordIsInvalid_throwsException() {
ReflectionTestUtils.setField(scimUserEndpoints, "scimUserProvisioning", jdbcScimUserProvisioning);
}

@Test
void createUser_ShouldThrow_WhenAliasPropertiesAreInvalid() {
final String userName = "user@example.com";
final ScimUser user = new ScimUser("user1", userName, null, null);
user.addEmail(userName);
user.setOrigin(OriginKeys.UAA);
user.setPassword("password");

when(scimUserAliasHandler.aliasPropertiesAreValid(any(), eq(null)))
.thenReturn(false);

final ScimException exception = assertThrows(ScimException.class, () ->
scimUserEndpoints.createUser(user, new MockHttpServletRequest(), new MockHttpServletResponse())
);

assertEquals(HttpStatus.BAD_REQUEST, exception.getStatus());
assertEquals("Alias ID and/or alias ZID are invalid.", exception.getMessage());
}

@Test
void userWithNoEmailNotAllowed() {
ScimUser user = new ScimUser(null, "dave", "David", "Syer");
Expand Down

0 comments on commit 5e682bc

Please sign in to comment.