Skip to content

Commit

Permalink
Update LDAP connector version, add/adapt tests
Browse files Browse the repository at this point in the history
In connectors-ldap 493d2f2a6fd99788b66b29c8f894dee2d06f1e72 we fixed
mapping for LDAP Integer from Java int to Java BigInteger. Then, in
prism 9703d9ce50fc48c47c130dd5e53a25ce86b44d0e we fixed related
automatic conversions between BigInteger and int and long.

This commit upgrades connector-ldap dependency to 3.6-SNAPSHOT and adds
some tests for this feature. Other tests are adapted, because the type
of LDAP Integer attributes (like uidNumber) has changed.

Related to MID-4424.
  • Loading branch information
mederly committed Mar 20, 2023
1 parent b3fa137 commit 69a5bb0
Show file tree
Hide file tree
Showing 17 changed files with 578 additions and 241 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,10 @@ private void assertNoOtherAttributes() throws SchemaException {
Objects.requireNonNull(attrDefBean.getRef(), () -> "No attribute name in " + attrDefBean));
// TODO check that we really look into aux object classes
if (!definition.containsAttributeDefinition(attrName) && !ResourceSchemaUtil.isIgnored(attrDefBean)) {
throw new SchemaException("Definition of attribute " + attrName + " not found in object class " +
definition.getObjectClassName() + " nor auxiliary object classes for " + definition +
" as defined in " + contextDescription);
throw new SchemaException(String.format(
"Definition of attribute %s not found in object class %s nor auxiliary object classes for %s "
+ "as defined in %s",
attrName, definition.getObjectClassName(), definition, contextDescription));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1155,19 +1155,24 @@ private interface ExtensionItemCreator {
Item<?, ?> create(PrismContainerValue<?> extension, List<?> realValues) throws SchemaException;
}

public static void setExtensionPropertyRealValues(PrismContext prismContext, PrismContainerValue<?> parent, ItemName propertyName,
Object... values) throws SchemaException {
public static void setExtensionPropertyRealValues(
PrismContext ignored, PrismContainerValue<?> parent, ItemName propertyName, Object... values) throws SchemaException {
setExtensionPropertyRealValues(parent, propertyName, values);
}

public static void setExtensionPropertyRealValues(
PrismContainerValue<?> parent, ItemName propertyName, Object... values) throws SchemaException {
setExtensionItemRealValues(parent,
extension -> extension.removeProperty(propertyName),
(extension, realValues) -> {
PrismProperty<Object> property = findPropertyDefinition(prismContext, extension, propertyName)
PrismProperty<Object> property = findPropertyDefinition(extension, propertyName)
.instantiate();
realValues.forEach(property::addRealValue);
return property;
}, values);
}

private static @NotNull PrismPropertyDefinition<Object> findPropertyDefinition(PrismContext prismContext,
private static @NotNull PrismPropertyDefinition<Object> findPropertyDefinition(
PrismContainerValue<?> extension, ItemName propertyName) {
if (extension.getDefinition() != null) {
PrismPropertyDefinition<Object> definitionInExtension = extension.getDefinition().findPropertyDefinition(propertyName);
Expand All @@ -1176,7 +1181,7 @@ public static void setExtensionPropertyRealValues(PrismContext prismContext, Pri
}
}
//noinspection unchecked
PrismPropertyDefinition<Object> globalDefinition = prismContext.getSchemaRegistry()
PrismPropertyDefinition<Object> globalDefinition = PrismContext.get().getSchemaRegistry()
.findPropertyDefinitionByElementName(propertyName);
if (globalDefinition != null) {
return globalDefinition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@
*/
package com.evolveum.midpoint.test.util;

import static com.evolveum.midpoint.schema.constants.MidPointConstants.NS_RI;

import java.io.File;

import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.schema.constants.MidPointConstants;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;

import javax.xml.namespace.QName;
import java.io.File;

import static com.evolveum.midpoint.schema.constants.MidPointConstants.NS_MIDPOINT_TEST_PREFIX;
import static com.evolveum.midpoint.schema.constants.MidPointConstants.NS_RI;
import static com.evolveum.midpoint.util.QNameUtil.qNameToUri;

public class MidPointTestConstants {

public static final String TEST_RESOURCES_PATH = "src/test/resources";
Expand Down Expand Up @@ -49,7 +46,5 @@ public class MidPointTestConstants {
public static final ItemName QNAME_MAIL = new ItemName(NS_RI, "mail");
public static final ItemPath PATH_MAIL = ItemPath.create(ShadowType.F_ATTRIBUTES, QNAME_MAIL);

public static final String TEST_POLICY_SITUATION_LEGACY = qNameToUri(new QName(NS_MIDPOINT_TEST_PREFIX, "legacy"));
public static final String TEST_POLICY_SITUATION_ILLEGAL = qNameToUri(new QName(NS_MIDPOINT_TEST_PREFIX, "illegal"));
public static final String TEST_POLICY_SITUATION_PENDING = qNameToUri(new QName(NS_MIDPOINT_TEST_PREFIX, "pending"));
public static final ItemName QNAME_UID_NUMBER = new ItemName(NS_RI, "uidNumber");
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public ObjectQuery customizeQuery(ObjectQuery configuredQuery, OperationResult r
.item(syncTimestampItem).le(getReconciliationStartTimestamp(result))
.or().item(syncTimestampItem).isNull()
.endBlock()
.and().item(ShadowType.F_RESOURCE_REF).ref(processingScope.getResourceOid())
.and().item(ShadowType.F_OBJECT_CLASS).eq(processingScope.getResolvedObjectClassName())
.and().item(ShadowType.F_RESOURCE_REF).ref(processingScope.getResourceOid())
.and().item(ShadowType.F_OBJECT_CLASS).eq(processingScope.getResolvedObjectClassName())
.build();
}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@
<groupId>com.evolveum.polygon</groupId>
<artifactId>connector-ldap</artifactId>
<!-- Do not forget to update provisioning/ucf-impl-connid/src/test/resources/connector-ldap.xml when changing connector version. -->
<version>3.5</version>
<version>3.6-SNAPSHOT</version>
<exclusions>
<!-- Needed otherwise the JDK14 SLF4J binding can override the midpoint's logback binding -->
<exclusion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@

import static com.evolveum.midpoint.test.IntegrationTestTools.createEntitleDelta;

import static com.evolveum.midpoint.test.util.MidPointTestConstants.*;

import static org.assertj.core.api.Assertions.*;
import static org.testng.AssertJUnit.*;

import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
Expand Down Expand Up @@ -2076,7 +2079,7 @@ public void test320AddAccountPosix() throws Exception {
assertAttribute(provisioningShadowType, "cn", "Haggis McMutton");
assertAttribute(provisioningShadowType, "sn", "McMutton");
assertAttribute(provisioningShadowType, "homeDirectory", "/home/scotland");
assertAttribute(provisioningShadowType, "uidNumber", 1001);
assertAttribute(provisioningShadowType, "uidNumber", BigInteger.valueOf(1001));

String uid = ShadowUtil.getSingleStringAttributeValue(repoShadowType, getPrimaryIdentifierQName());
assertNotNull(uid);
Expand Down Expand Up @@ -2122,7 +2125,7 @@ public void test322ModifyAccountPosix() throws Exception {
assertAttribute(accountType, "cn", "Haggis McMutton");
assertAttribute(accountType, "homeDirectory", "/home/caribbean");
assertAttribute(accountType, "roomNumber", "Barber Shop");
assertAttribute(accountType, "uidNumber", 1001);
assertAttribute(accountType, "uidNumber", BigInteger.valueOf(1001));

// Check if object was modified in LDAP

Expand Down Expand Up @@ -2199,7 +2202,7 @@ public void test330SearchForPosixAccount() throws Exception {
PrismObject<ShadowType> provisioningShadow = objListType.get(0);
assertAttribute(provisioningShadow, "cn", "Edward Van Helgen");
assertAttribute(provisioningShadow, "homeDirectory", "/home/vanhelgen");
assertAttribute(provisioningShadow, "uidNumber", 1002);
assertAttribute(provisioningShadow, "uidNumber", BigInteger.valueOf(1002));

assertConnectorOperationIncrement(1, 3);
assertCounterIncrement(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT, 0);
Expand Down Expand Up @@ -2513,7 +2516,7 @@ public void test419PhantomRenameMorgan() throws Exception {
OperationResult result = task.getResult();

ObjectDelta<ShadowType> delta = deltaFor(ShadowType.class)
.item(MidPointTestConstants.PATH_DN, getAccountAttributeDefinitionRequired(MidPointTestConstants.QNAME_DN))
.item(PATH_DN, getAccountAttributeDefinitionRequired(QNAME_DN))
.replace("uid=morgan,ou=People,dc=example,dc=com")
.asObjectDelta(ACCOUNT_MORGAN_OID);

Expand Down Expand Up @@ -2547,14 +2550,14 @@ public void test420PhantomRenameMorganRotten() throws Exception {
OperationResult result = task.getResult();

ObjectDelta<ShadowType> rotDelta = deltaFor(ShadowType.class)
.item(MidPointTestConstants.PATH_DN, getAccountAttributeDefinitionRequired(MidPointTestConstants.QNAME_DN))
.item(PATH_DN, getAccountAttributeDefinitionRequired(QNAME_DN))
.replace("uid=morgan-rotten,ou=People,dc=example,dc=com")
.asObjectDelta(ACCOUNT_MORGAN_OID);
repositoryService.modifyObject(ShadowType.class, ACCOUNT_MORGAN_OID, rotDelta.getModifications(), result);

// This is no-op on resource. (The DN on resource has not changed.)
ObjectDelta<ShadowType> delta = deltaFor(ShadowType.class)
.item(MidPointTestConstants.PATH_DN, getAccountAttributeDefinitionRequired(MidPointTestConstants.QNAME_DN))
.item(PATH_DN, getAccountAttributeDefinitionRequired(QNAME_DN))
.replace("uid=morgan,ou=People,dc=example,dc=com")
.asObjectDelta(ACCOUNT_MORGAN_OID);

Expand Down Expand Up @@ -3340,6 +3343,80 @@ public void test723ConnectionBadBindDn() throws Exception {
assertTrue("Unexpected connector initialization message: "+initResult.getMessage(), initResult.getMessage().contains("49"));
}

/** Creates two entries with `uidNumber` bigger than {@link Integer#MAX_VALUE}. MID-4424. */
@Test
public void test730IntegerOver32Bits() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();

long withinLong = 1_000_000_000_000_000L; // 10^15 = 3_8D7E_A4C6_8000 hex (51 bits)
BigInteger overLong = new BigInteger("10").pow(30); // 10^30 ~ 102 bits

given("account with uidNumber over Integer but within Long");
openDJController.addEntry("dn: uid=within-long,ou=People,dc=example,dc=com\n"
+ "uid: within-long\n"
+ "cn: Within Long\n"
+ "sn: Long\n"
+ "givenName: Within\n"
+ "objectclass: top\n"
+ "objectclass: person\n"
+ "objectclass: organizationalPerson\n"
+ "objectclass: inetOrgPerson\n"
+ "objectclass: posixAccount\n"
+ "uidNumber: " + withinLong + "\n"
+ "gidNumber: 1000\n"
+ "homeDirectory: /dev/null\n"
+ "\n");

when("it is retrieved");
List<PrismObject<ShadowType>> objectsWithinLong =
provisioningService.searchObjects(
ShadowType.class,
Resource.of(resource) // requires test004 to run before this test
.queryFor(OBJECT_CLASS_INETORGPERSON_QNAME)
.and().item(PATH_CN).eq("Within Long")
.build(),
null, task, result);

then("uidNumber is OK");
assertThat(objectsWithinLong).as("retrieved accounts").hasSize(1);
assertShadowAfter(objectsWithinLong.get(0))
.attributes()
.assertValue(QNAME_UID_NUMBER, BigInteger.valueOf(withinLong));

given("account with uidNumber over Long");
openDJController.addEntry("dn: uid=over-long,ou=People,dc=example,dc=com\n"
+ "uid: over-long\n"
+ "cn: Over Long\n"
+ "sn: Long\n"
+ "givenName: Over\n"
+ "objectclass: top\n"
+ "objectclass: person\n"
+ "objectclass: organizationalPerson\n"
+ "objectclass: inetOrgPerson\n"
+ "objectclass: posixAccount\n"
+ "uidNumber: " + overLong + "\n"
+ "gidNumber: 1000\n"
+ "homeDirectory: /dev/null\n"
+ "\n");

when("it is retrieved");
List<PrismObject<ShadowType>> objectsOverLong =
provisioningService.searchObjects(
ShadowType.class,
Resource.of(resource)
.queryFor(OBJECT_CLASS_INETORGPERSON_QNAME)
.and().item(PATH_CN).eq("Over Long")
.build(),
null, task, result);

then("uidNumber is OK");
assertThat(objectsOverLong).as("retrieved accounts").hasSize(1);
assertShadowAfter(objectsOverLong.get(0))
.attributes()
.assertValue(QNAME_UID_NUMBER, overLong);
}

/**
* Look insite OpenDJ logs to check for clues of undesirable behavior.
* MID-7091
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<name>ICF com.evolveum.polygon.connector.ldap.LdapConnector</name>
<framework>http://midpoint.evolveum.com/xml/ns/public/connector/icf-1</framework>
<connectorType>com.evolveum.polygon.connector.ldap.LdapConnector</connectorType>
<connectorVersion>3.5</connectorVersion>
<connectorVersion>3.6-SNAPSHOT</connectorVersion>
<connectorBundle>com.evolveum.polygon.connector-ldap</connectorBundle>
<namespace>http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/bundle/com.evolveum.polygon.connector-ldap/com.evolveum.polygon.connector.ldap.LdapConnector</namespace>
<schema>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,16 @@ public <T> PrismContainerValueAsserter<C, RA> sendItemValue(ItemPath path, Check
@SuppressWarnings("unchecked")
public <T> PrismContainerValueAsserter<C, RA> assertPropertyValuesEqual(ItemPath path, T... expectedValues) {
PrismProperty<T> property = findProperty(path);
assertNotNull("No property " + path + " in " + desc(), property);
PrismAsserts.assertPropertyValueDesc(property, desc(), expectedValues);
if (expectedValues.length > 0) {
assertNotNull("No property " + path + " in " + desc(), property);
PrismAsserts.assertPropertyValueDesc(property, desc(), expectedValues);
} else if (property != null) {
assertThat(property.getValues())
.as("values of " + path + " in " + desc())
.isEmpty();
} else {
// OK!
}
return this;
}

Expand Down

0 comments on commit 69a5bb0

Please sign in to comment.