Skip to content

Commit

Permalink
Fix IdentityProviderEndpointsTest
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianhoelzl-sap committed Feb 22, 2024
1 parent 7badbac commit b6ed90d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ public final EntityAliasResult<T> ensureConsistencyOfAliasEntity(
aliasEntity.setAliasId(null);
aliasEntity.setAliasZid(null);

final T updatedAliasEntity;
try {
updateEntity(aliasEntity, aliasEntity.getZoneId());
updatedAliasEntity = updateEntity(aliasEntity, aliasEntity.getZoneId());
} catch (final DataAccessException e) {
throw new EntityAliasFailedException(
String.format(
Expand All @@ -160,7 +161,7 @@ public final EntityAliasResult<T> ensureConsistencyOfAliasEntity(
}

// no change required in the original entity since its aliasId and aliasZid were already set to null
return new EntityAliasResult<>(originalEntity, aliasEntity);
return new EntityAliasResult<>(originalEntity, updatedAliasEntity);
}

if (!hasText(originalEntity.getAliasZid())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.Optional;

import org.cloudfoundry.identity.uaa.alias.EntityAliasFailedException;
import org.cloudfoundry.identity.uaa.alias.EntityAliasHandler.EntityAliasResult;
import org.cloudfoundry.identity.uaa.audit.event.EntityDeletedEvent;
import org.cloudfoundry.identity.uaa.authentication.manager.DynamicLdapAuthenticationManager;
import org.cloudfoundry.identity.uaa.authentication.manager.LdapLoginAuthenticationManager;
Expand Down Expand Up @@ -147,7 +148,11 @@ public ResponseEntity<IdentityProvider> createIdentityProvider(@RequestBody Iden
try {
createdIdp = transactionTemplate.execute(txStatus -> {
final IdentityProvider<?> createdOriginalIdp = identityProviderProvisioning.create(body, zoneId);
return idpAliasHandler.ensureConsistencyOfAliasEntity(createdOriginalIdp, null);
final EntityAliasResult<IdentityProvider<?>> aliasResult = idpAliasHandler.ensureConsistencyOfAliasEntity(
createdOriginalIdp,
null
);
return aliasResult.originalEntity();
});
} catch (final IdpAlreadyExistsException e) {
return new ResponseEntity<>(body, CONFLICT);
Expand Down Expand Up @@ -256,7 +261,11 @@ public ResponseEntity<IdentityProvider> updateIdentityProvider(@PathVariable Str
try {
updatedIdp = transactionTemplate.execute(txStatus -> {
final IdentityProvider<?> updatedOriginalIdp = identityProviderProvisioning.update(body, zoneId);
return idpAliasHandler.ensureConsistencyOfAliasEntity(updatedOriginalIdp, existing);
final EntityAliasResult<IdentityProvider<?>> aliasResult = idpAliasHandler.ensureConsistencyOfAliasEntity(
updatedOriginalIdp,
existing
);
return aliasResult.originalEntity();
});
} catch (final IdpAlreadyExistsException e) {
return new ResponseEntity<>(body, CONFLICT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ void setup() {
lenient().when(mockIdpAliasHandler.aliasPropertiesAreValid(any(), any()))
.thenReturn(true);
lenient().when(mockIdpAliasHandler.ensureConsistencyOfAliasEntity(any(), any()))
.then(invocationOnMock -> invocationOnMock.getArgument(0));
.then(invocationOnMock -> {
final IdentityProvider<?> originalIdp = invocationOnMock.getArgument(0);
return new EntityAliasResult<IdentityProvider<?>>(originalIdp, null);
});
}

IdentityProvider<AbstractExternalOAuthIdentityProviderDefinition> getExternalOAuthProvider() {
Expand Down

0 comments on commit b6ed90d

Please sign in to comment.