Skip to content

Commit

Permalink
tests: address flakyness in ScimUserEndpointsAliasMockMvcTests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kehrlann committed Dec 20, 2024
1 parent 5e2e6d6 commit 1da7b55
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.cloudfoundry.identity.uaa.scim.ScimUserAliasHandler;
import org.cloudfoundry.identity.uaa.scim.jdbc.JdbcScimUserProvisioning;
import org.cloudfoundry.identity.uaa.scim.services.ScimUserService;
import org.cloudfoundry.identity.uaa.util.AlphanumericRandomValueStringGenerator;
import org.cloudfoundry.identity.uaa.util.JsonUtils;
import org.cloudfoundry.identity.uaa.util.UaaStringUtils;
import org.cloudfoundry.identity.uaa.zone.IdentityZone;
Expand All @@ -26,8 +27,10 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.MvcResult;
Expand All @@ -52,15 +55,22 @@

@DefaultTestContext
public class ScimUserEndpointsAliasMockMvcTests extends AliasMockMvcTestBase {
private static final String TEST_USERNAME = new AlphanumericRandomValueStringGenerator(12).generate().toLowerCase();

private IdentityProviderAliasHandler idpEntityAliasHandler;
private IdentityProviderEndpoints identityProviderEndpoints;
private ScimUserAliasHandler scimUserAliasHandler;
private ScimUserEndpoints scimUserEndpoints;
private ScimUserService scimUserService;
@Autowired
JdbcTemplate jdbcTemplate;

@BeforeEach
void setUp() throws Exception {
setUpTokensAndCustomZone();
// There is a race conditions where multiple users with the same name are created between tests
// We ensure that the tests are independent by deleting the test user before every test.
jdbcTemplate.execute("DELETE FROM users WHERE username = '" + TEST_USERNAME + "'");

idpEntityAliasHandler = requireNonNull(webApplicationContext.getBean(IdentityProviderAliasHandler.class));
identityProviderEndpoints = requireNonNull(webApplicationContext.getBean(IdentityProviderEndpoints.class));
Expand Down Expand Up @@ -242,7 +252,6 @@ private void shouldAccept_ShouldCreateAliasUser(
final ScimUser createdScimUser = createScimUser(zone1, scimUser);

// find alias user
//TODO this is flaky
final List<ScimUser> usersZone2 = readRecentlyCreatedUsersInZone(zone2);
final Optional<ScimUser> aliasUserOpt = usersZone2.stream()
.filter(user -> user.getId().equals(createdScimUser.getAliasId()))
Expand Down Expand Up @@ -1600,7 +1609,7 @@ private static ScimUser buildScimUser(
scimUser.setAliasZid(aliasZid);
scimUser.setZoneId(zoneId);

scimUser.setUserName("john.doe");
scimUser.setUserName(TEST_USERNAME);
scimUser.setName(new ScimUser.Name("John", "Doe"));
scimUser.setPrimaryEmail("john.doe@example.com");
scimUser.setPassword("some-password");
Expand Down

0 comments on commit 1da7b55

Please sign in to comment.