Skip to content

Commit

Permalink
Fixes for conntests:
Browse files Browse the repository at this point in the history
1. switching order for executing testConnection and testPartialConfigurationResourceObject().
In the previous order, so if the testPartialConfigurationResourceObject was executed after testConnection,
 the connector instance was indeed removed from the pool. The removal of connector instance after
testing only partial configuration is correct behavior. Since we have only partial resource configuration,
we don't want to keep instance alive longer than inevitable. The problem was, that tests running after
testConnection rely on the existence of the connector instance. Therefore the order was switched and
connector instance should be kept.
2. number of accounts for AD resources was adapted to the actual size. For the future, the names of the accounts
are now in the comment, so it will be possible to compare those results in the future with previous versions.
3. Since 4.6 there is a difference while searching in provisioning according to the objectClass or using the
couple kind/intent. Therefore counters were adapted.
4. Small cleanup and other stuffs
  • Loading branch information
katkav committed Jul 15, 2022
1 parent e86393c commit dd57025
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,19 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
}

@Test
public void test010Connection() throws Exception {
public void test010PartialConfigurationResourceObject() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();
PrismObject<ResourceType> resourceFromRepo = getObject(ResourceType.class, getResourceOid());
ResourceType resource = new ResourceType()
.name("newResource")
.connectorRef(resourceFromRepo.asObjectable().getConnectorRef())
.connectorConfiguration(resourceFromRepo.asObjectable().getConnectorConfiguration());

OperationResult testResult = provisioningService.testResource(getResourceOid(), task, task.getResult());
OperationResult testResult = provisioningService.testPartialConfiguration(resource.asPrismObject(), task, result);

display("Test connection result", testResult);
TestUtil.assertSuccess("Test connection failed", testResult);
display("Test partial configuration of resource result", testResult);
TestUtil.assertSuccess("Test partial configuration of resource failed", testResult);

if (isAssertOpenFiles()) {
// Set lsof baseline only after the first connection.
Expand All @@ -354,22 +360,16 @@ public void test010Connection() throws Exception {
displayDumpable("lsof baseline", lsof);
}

resource = getObject(ResourceType.class, getResourceOid());
displayXml("Resource after test connection", resource);
displayXml("Resource after test connection", resource.asPrismObject());

assertNull("Resource was saved to repo, during partial configuration test", findObjectByName(ResourceType.class, "newResource"));
}

@Test
public void test011ConnectionResourceObject() throws Exception {
public void test011Connection() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();
PrismObject<ResourceType> resourceFromRepo = getObject(ResourceType.class, getResourceOid());
ResourceType resource = new ResourceType()
.name("newResource")
.connectorRef(resourceFromRepo.asObjectable().getConnectorRef())
.connectorConfiguration(resourceFromRepo.asObjectable().getConnectorConfiguration())
.schema(resourceFromRepo.asObjectable().getSchema());

OperationResult testResult = provisioningService.testResource(resource.asPrismObject(), task, result);
OperationResult testResult = provisioningService.testResource(getResourceOid(), task, task.getResult());

display("Test connection result", testResult);
TestUtil.assertSuccess("Test connection failed", testResult);
Expand All @@ -381,25 +381,25 @@ public void test011ConnectionResourceObject() throws Exception {
displayDumpable("lsof baseline", lsof);
}

displayXml("Resource after test connection", resource.asPrismObject());

assertNull("Resource was saved to repo, during partial configuration test", findObjectByName(ResourceType.class, "newResource"));
resource = getObject(ResourceType.class, getResourceOid());
displayXml("Resource after test connection", resource);
}

@Test
public void test012PartialConfigurationResourceObject() throws Exception {
public void test012ConnectionResourceObject() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();
PrismObject<ResourceType> resourceFromRepo = getObject(ResourceType.class, getResourceOid());
ResourceType resource = new ResourceType()
.name("newResource")
.connectorRef(resourceFromRepo.asObjectable().getConnectorRef())
.connectorConfiguration(resourceFromRepo.asObjectable().getConnectorConfiguration());
.connectorConfiguration(resourceFromRepo.asObjectable().getConnectorConfiguration())
.schema(resourceFromRepo.asObjectable().getSchema());

OperationResult testResult = provisioningService.testPartialConfiguration(resource.asPrismObject(), task, result);
OperationResult testResult = provisioningService.testResource(resource.asPrismObject(), task, result);

display("Test partial configuration of resource result", testResult);
TestUtil.assertSuccess("Test partial configuration of resource failed", testResult);
display("Test connection result", testResult);
TestUtil.assertSuccess("Test connection failed", testResult);

if (isAssertOpenFiles()) {
// Set lsof baseline only after the first connection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition;
import com.evolveum.midpoint.schema.processor.ResourceSchemaFactory;

import com.evolveum.midpoint.testing.conntest.AbstractLdapTest;
import com.evolveum.midpoint.testing.conntest.ad.AbstractAdLdapTest;
import com.evolveum.midpoint.testing.conntest.ad.AdTestMixin;

Expand Down Expand Up @@ -445,7 +446,7 @@ public void test105SearchPiratesByCn() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();

ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getGroupObjectClass(), prismContext);
ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getGroupObjectClass());
ObjectQueryUtil.filterAnd(query.getFilter(), createAttributeFilter("cn", GROUP_PIRATES_NAME), prismContext);

rememberCounter(InternalCounters.CONNECTOR_OPERATION_COUNT);
Expand Down Expand Up @@ -528,7 +529,7 @@ public void test150SearchAllAccounts() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();

ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass(), prismContext);
ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass());

rememberCounter(InternalCounters.CONNECTOR_OPERATION_COUNT);
rememberCounter(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT);
Expand All @@ -537,11 +538,13 @@ public void test150SearchAllAccounts() throws Exception {
SearchResultList<PrismObject<ShadowType>> searchResultList = doSearch(query,
getNumberOfAllAccounts(), task, result);

searchResultList.forEach(shadow -> logger.info("shadow: \n {}", shadow.getName()));

if (isVagueTest()) {
rememberCounter(InternalCounters.CONNECTOR_OPERATION_COUNT);
} else {
// This seems to vary quite wildly from system to system. Maybe TODO investigate the reasons later?
assertCounterIncrement(InternalCounters.CONNECTOR_OPERATION_COUNT, 9,10);
assertCounterIncrement(InternalCounters.CONNECTOR_OPERATION_COUNT, 8,10);
}
assertCounterIncrement(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT, 0);

Expand All @@ -562,16 +565,15 @@ public void test152SearchFirst2Accounts() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();

ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass(), prismContext);
ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass());

ObjectPaging paging = prismContext.queryFactory().createPaging();
paging.setMaxSize(2);
query.setPaging(paging);

SearchResultList<PrismObject<ShadowType>> searchResultList = doSearch(query, 2, task, result);

// TODO: Why 2? Why not 1?
assertCounterIncrement(InternalCounters.CONNECTOR_OPERATION_COUNT, 2);
assertCounterIncrement(InternalCounters.CONNECTOR_OPERATION_COUNT, 1);
assertCounterIncrement(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT, 0);

SearchResultMetadata metadata = searchResultList.getMetadata();
Expand All @@ -588,16 +590,15 @@ public void test154SearchFirst5Accounts() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();

ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass(), prismContext);
ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass());

ObjectPaging paging = prismContext.queryFactory().createPaging();
paging.setMaxSize(5);
query.setPaging(paging);

SearchResultList<PrismObject<ShadowType>> searchResultList = doSearch(query, 5, task, result);

// TODO: Why 2? Why not 1?
assertCounterIncrement(InternalCounters.CONNECTOR_OPERATION_COUNT, 2);
assertCounterIncrement(InternalCounters.CONNECTOR_OPERATION_COUNT, 1);
assertCounterIncrement(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT, 0);

SearchResultMetadata metadata = searchResultList.getMetadata();
Expand All @@ -614,7 +615,7 @@ public void test162SearchFirst2AccountsOffset0() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();

ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass(), prismContext);
ObjectQuery query = ObjectQueryUtil.createResourceAndKindIntent(getResourceOid(), ShadowKindType.ACCOUNT, "default");

ObjectPaging paging = prismContext.queryFactory().createPaging();
paging.setOffset(0);
Expand All @@ -623,7 +624,9 @@ public void test162SearchFirst2AccountsOffset0() throws Exception {

SearchResultList<PrismObject<ShadowType>> searchResultList = doSearch(query, 2, task, result);

// TODO: Why 2? Why not 1?
// increment = 2 because there are two searches:
// 1. one for baseContext (as defined for account/default)
// 2. one for objects
assertCounterIncrement(InternalCounters.CONNECTOR_OPERATION_COUNT, 2);
assertCounterIncrement(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT, 0);

Expand All @@ -645,15 +648,14 @@ public void test172Search2AccountsOffset1() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();

ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass(), prismContext);
ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass());

ObjectPaging paging = prismContext.queryFactory().createPaging(1, 2);
query.setPaging(paging);

SearchResultList<PrismObject<ShadowType>> searchResultList = doSearch(query, 2, task, result);

// TODO: Why 2? Why not 1?
assertCounterIncrement(InternalCounters.CONNECTOR_OPERATION_COUNT, 2);
assertCounterIncrement(InternalCounters.CONNECTOR_OPERATION_COUNT, 1);
assertCounterIncrement(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT, 0);

SearchResultMetadata metadata = searchResultList.getMetadata();
Expand All @@ -674,7 +676,7 @@ public void test174SearchFirst5AccountsOffset2() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();

ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass(), prismContext);
ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass());

ObjectPaging paging = prismContext.queryFactory().createPaging(2, 5);
query.setPaging(paging);
Expand All @@ -687,8 +689,7 @@ public void test174SearchFirst5AccountsOffset2() throws Exception {
// THEN
allowDuplicateSearchResults = false;

// TODO: Why 2? Why not 1?
assertCounterIncrement(InternalCounters.CONNECTOR_OPERATION_COUNT, 2);
assertCounterIncrement(InternalCounters.CONNECTOR_OPERATION_COUNT, 1);
assertCounterIncrement(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT, 0);

SearchResultMetadata metadata = searchResultList.getMetadata();
Expand Down Expand Up @@ -721,8 +722,7 @@ public void test182Search2AccountsOffset1SortCn() throws Exception {
// assertAccountShadow(shadows.get(0), "CN=Adolf Supperior,CN=Users,DC=ad,DC=evolveum,DC=com");
// assertAccountShadow(shadows.get(1), "CN=DiscoverySearchMailbox {D919BA05-46A6-415f-80AD-7E09334BB852},CN=Users,DC=ad,DC=evolveum,DC=com");

// TODO: Why 2? Why not 1?
assertCounterIncrement(InternalCounters.CONNECTOR_OPERATION_COUNT, 2);
assertCounterIncrement(InternalCounters.CONNECTOR_OPERATION_COUNT, 1);
assertCounterIncrement(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT, 0);

SearchResultMetadata metadata = shadows.getMetadata();
Expand All @@ -734,7 +734,7 @@ public void test182Search2AccountsOffset1SortCn() throws Exception {
}

protected String getExpected182FirstShadow() {
return "CN=Administrator," + getPeopleLdapSuffix();
return "CN=Admin," + getPeopleLdapSuffix();
}

/**
Expand All @@ -756,7 +756,7 @@ public void test190GetGhost() throws Exception {

// WHEN
when();
PrismObject<ShadowType> shadow = modelService.getObject(ShadowType.class, SHADOW_GHOST_OID, null, task, result);
modelService.getObject(ShadowType.class, SHADOW_GHOST_OID, null, task, result);

// THEN
then();
Expand Down Expand Up @@ -1085,7 +1085,7 @@ protected void testModifyUserBarbossaPasswordSelfServiceSuccess(String oldPasswo
}

protected void testModifyUserBarbossaPasswordSelfServiceFailure(
String oldPassword, String newPassword) throws Exception {
String oldPassword) throws Exception {
// GIVEN
login(USER_BARBOSSA_USERNAME);

Expand All @@ -1094,7 +1094,7 @@ protected void testModifyUserBarbossaPasswordSelfServiceFailure(
OperationResult result = task.getResult();

ObjectDelta<UserType> objectDelta = createOldNewPasswordDelta(USER_BARBOSSA_OID,
oldPassword, newPassword);
oldPassword, AbstractLdapTest.USER_BARBOSSA_PASSWORD_AD_1);

// WHEN
when();
Expand All @@ -1105,9 +1105,9 @@ protected void testModifyUserBarbossaPasswordSelfServiceFailure(
login(USER_ADMINISTRATOR_USERNAME);
assertPartialError(result);

assertBarbossaEnabled(newPassword);
assertBarbossaEnabled(AbstractLdapTest.USER_BARBOSSA_PASSWORD_AD_1);
assertUserAfter(USER_BARBOSSA_OID)
.assertPassword(newPassword);
.assertPassword(AbstractLdapTest.USER_BARBOSSA_PASSWORD_AD_1);

assertLdapPassword(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME, oldPassword);

Expand All @@ -1133,7 +1133,7 @@ public void test230DisableUserBarbossa() throws Exception {
then();
assertSuccess(result);

assertBarbossaDisabled(USER_BARBOSSA_PASSWORD_AD_1);
assertBarbossaDisabled();
}

/**
Expand All @@ -1153,7 +1153,7 @@ public void test232ReconcileBarbossa() throws Exception {
then();
assertSuccess(result);

assertBarbossaDisabled(USER_BARBOSSA_PASSWORD_AD_1);
assertBarbossaDisabled();
}

/**
Expand Down Expand Up @@ -1222,7 +1222,7 @@ public void test238DisableUserBarbossaRawAndReconcile() throws Exception {
then();
assertSuccess(result);

assertBarbossaDisabled(USER_BARBOSSA_PASSWORD_AD_1);
assertBarbossaDisabled();

assertLdapConnectorReasonableInstances();
}
Expand Down Expand Up @@ -1274,7 +1274,7 @@ protected PrismObject<UserType> assertBarbossaEnabled(String ldapPassword) throw
return user;
}

private void assertBarbossaDisabled(String password) throws Exception {
private void assertBarbossaDisabled() throws Exception {
// assertLdapConnectorInstances(2);

PrismObject<UserType> user = getUser(USER_BARBOSSA_OID);
Expand All @@ -1293,7 +1293,7 @@ private void assertBarbossaDisabled(String password) throws Exception {
assertAccountDisabled(shadow);

try {
assertLdapPassword(null, entry, password);
assertLdapPassword(null, entry, AbstractLdapTest.USER_BARBOSSA_PASSWORD_AD_1);
AssertJUnit.fail("Password authentication works, but it should fail");
} catch (SecurityException e) {
// this is expected
Expand Down Expand Up @@ -1918,6 +1918,7 @@ public void test600AssignAccountSubman() throws Exception {
display("Shadow (model)", shadow);
accountSubmanOid = shadow.getOid();
Collection<ResourceAttribute<?>> identifiers = ShadowUtil.getPrimaryIdentifiers(shadow);
assertNotNull("Unexpected situation, no identifiers found", identifiers);
String accountBarbossaIcfUid = (String) identifiers.iterator().next().getRealValue();
assertNotNull("No identifier in " + shadow, accountBarbossaIcfUid);

Expand Down Expand Up @@ -2199,7 +2200,7 @@ public void test850ReconcileAccounts() throws Exception {
// THEN
then();

assertUsers(getNumberOfAllAccounts() + 2); // all accounts + administrator + ?
assertUsers(getNumberOfAllAccounts() + 1); // all accounts + administrator

// TODO: better asserts

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ protected File getShadowGhostFile() {

@Override
protected int getNumberOfAllAccounts() {
return 11;
// Namely: SUB2016$, Administrator, Guest, DefaultAccount, cloudbase-init,
// Admin, Jack Sparrow, MidPoint, SSH Test, sshd, AD05, krbtgt
return 12;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ protected File getShadowGhostFile() {

@Override
protected int getNumberOfAllAccounts() {
return 10;
// Namely: Administrator, Guest, cloudbase-init, Admin, sshd, AD03,
// krbtgt, SSH Test SUB2019$, MidPoint, Jack Sparrow
return 11;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,17 @@
</q:substring>
</filter>
</protected>
<protected>
<filter>
<q:substring>
<q:path>attributes/dn</q:path>
<q:value>CN=AD05</q:value>
<q:anchorStart>true</q:anchorStart>
<!-- Explicit matching rule needs to be specified in the query. See MID-6935 -->
<q:matching>http://prism.evolveum.com/xml/ns/public/matching-rule-3#distinguishedName</q:matching>
</q:substring>
</filter>
</protected>

<activation>
<administrativeStatus>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,17 @@
</q:substring>
</filter>
</protected>
<protected>
<filter>
<q:substring>
<q:path>attributes/dn</q:path>
<q:value>CN=AD03</q:value>
<q:anchorStart>true</q:anchorStart>
<!-- Explicit matching rule needs to be specified in the query. See MID-6935 -->
<q:matching>http://prism.evolveum.com/xml/ns/public/matching-rule-3#distinguishedName</q:matching>
</q:substring>
</filter>
</protected>

<activation>
<administrativeStatus>
Expand Down

0 comments on commit dd57025

Please sign in to comment.