From dbdeddf416d417daa73303c321e68f35190fefbb Mon Sep 17 00:00:00 2001 From: lorenzo Date: Tue, 21 May 2024 12:29:26 +0200 Subject: [PATCH] [AD-76] maven profile for starting in embedded mode and run single IT --- pom.xml | 43 ++++++- .../bundles/ad/crud/UserCrudTestITCase.java | 113 ++++++++++++++++++ src/test/resources/docker/tirasaad/Dockerfile | 3 +- .../docker/tirasaad/samba-ad-setup.sh | 2 - 4 files changed, 153 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 9b60ded..5f1019d 100644 --- a/pom.xml +++ b/pom.xml @@ -83,6 +83,7 @@ UTF-8 false + false @@ -297,7 +298,7 @@ maven-failsafe-plugin 3.2.5 - ${exec.skip} + ${skipTests} true alphabetical @@ -317,7 +318,7 @@ maven-surefire-plugin true - ${exec.skip} + ${skipTests} @@ -327,7 +328,7 @@ test - ${exec.skip} + ${skipTests} **/*Test.java @@ -341,7 +342,6 @@ docker-maven-plugin 0.44.0 - ${exec.skip} tirasaad @@ -369,7 +369,7 @@ - samba version 4.15.13-Ubuntu started + samba version 4.19.5 started @@ -384,6 +384,9 @@ stop remove + + ${exec.skip} + start-docker @@ -392,6 +395,9 @@ build start + + ${exec.skip} + remove-containers-post-test @@ -400,6 +406,9 @@ stop remove + + ${exec.skip} + @@ -425,6 +434,7 @@ skipTests + true true @@ -432,6 +442,29 @@ clean install + + debug + + true + true + + + clean package io.fabric8:docker-maven-plugin:build io.fabric8:docker-maven-plugin:start + + + + + tests + + + false + true + + + + test + + diff --git a/src/test/java/net/tirasa/connid/bundles/ad/crud/UserCrudTestITCase.java b/src/test/java/net/tirasa/connid/bundles/ad/crud/UserCrudTestITCase.java index 7ded139..f659cc4 100644 --- a/src/test/java/net/tirasa/connid/bundles/ad/crud/UserCrudTestITCase.java +++ b/src/test/java/net/tirasa/connid/bundles/ad/crud/UserCrudTestITCase.java @@ -16,6 +16,7 @@ package net.tirasa.connid.bundles.ad.crud; import static net.tirasa.connid.bundles.ad.ADConnector.UACCONTROL_ATTR; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -45,6 +46,7 @@ import net.tirasa.connid.bundles.ad.TestUtil; import net.tirasa.connid.bundles.ad.UserTest; import net.tirasa.connid.bundles.ldap.commons.LdapConstants; +import org.identityconnectors.common.CollectionUtil; import org.identityconnectors.common.security.GuardedString; import org.identityconnectors.framework.api.APIConfiguration; import org.identityconnectors.framework.api.ConnectorFacade; @@ -52,6 +54,8 @@ import org.identityconnectors.framework.common.exceptions.ConnectorException; import org.identityconnectors.framework.common.objects.Attribute; import org.identityconnectors.framework.common.objects.AttributeBuilder; +import org.identityconnectors.framework.common.objects.AttributeDelta; +import org.identityconnectors.framework.common.objects.AttributeDeltaBuilder; import org.identityconnectors.framework.common.objects.AttributeUtil; import org.identityconnectors.framework.common.objects.ConnectorObject; import org.identityconnectors.framework.common.objects.Name; @@ -68,10 +72,17 @@ import org.identityconnectors.framework.impl.api.APIConfigurationImpl; import org.identityconnectors.framework.impl.api.local.JavaClassProperties; import org.identityconnectors.test.common.TestHelpers; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; public class UserCrudTestITCase extends UserTest { + private static final String NUMBER1 = "+1 800 123 4567"; + + private static final String NUMBER2 = "+1 800 765 4321"; + + private static final String NUMBER3 = "+1 800 765 9876"; + @Test public void pagedSearch() { final List results = new ArrayList<>(); @@ -448,6 +459,108 @@ public void update() { // -------------------------- } + @Test + public void updateDeltaNoValuePresent() { + assertNotNull(connector); + assertNotNull(conf); + + final Map.Entry ids = util.getEntryIDs("3"); + + Uid authUid = connector.authenticate( + ObjectClass.ACCOUNT, // object class + ids.getValue(), // uid + new GuardedString("Password123".toCharArray()), // password + null); + + assertNotNull(authUid); + + try { + connector.authenticate( + ObjectClass.ACCOUNT, // object class + ids.getValue(), // uid + new GuardedString("Password321".toCharArray()), // password + null); + fail(); + } catch (ConnectorException ignore) { + // ignore + } + + // updateDelta with values to add and to remove + AttributeDelta delta = AttributeDeltaBuilder.build( + "givenName", "gnupdate"); + connector.updateDelta(ObjectClass.ACCOUNT, new Uid(ids.getValue()), Collections.singleton(delta), null); + + OperationOptions options = new OperationOptionsBuilder().setAttributesToGet("givenName").build(); + + ConnectorObject obj = connector.getObject(ObjectClass.ACCOUNT, new Uid(ids.getValue()), options); + Attribute givenName = obj.getAttributeByName("givenName"); + assertNotNull(obj); + assertEquals(ids.getValue(), obj.getUid().getUidValue()); + assertEquals("gnupdate", givenName.getValue().get(0)); + + } + + @Test + @Disabled("Update Delta with value already present not possible with Samba") + public void updateDelta() { + // 1. take user and set attribute + final Map.Entry ids = util.getEntryIDs("3"); + connector.update( + ObjectClass.ACCOUNT, + new Uid(ids.getValue()), + Collections.singleton(AttributeBuilder.build("telephoneNumber", NUMBER1)), + null); + + OperationOptions options = new OperationOptionsBuilder().setAttributesToGet("telephoneNumber").build(); + ConnectorObject bugs = connector.getObject(ObjectClass.ACCOUNT, new Uid(ids.getValue()), options); + Attribute telephoneAttr = bugs.getAttributeByName("telephoneNumber"); + List numberAttr = telephoneAttr.getValue(); + assertEquals(1, numberAttr.size()); + assertEquals(NUMBER1, numberAttr.get(0)); + + // 2. updateDelta with values to add and to remove + AttributeDelta delta = AttributeDeltaBuilder.build( + "telephoneNumber", Collections.singletonList(NUMBER2), Collections.singletonList(NUMBER1)); + connector.updateDelta(ObjectClass.ACCOUNT, new Uid(ids.getValue()), Collections.singleton(delta), null); + + bugs = connector.getObject(ObjectClass.ACCOUNT, new Uid(ids.getValue()), options); + numberAttr = bugs.getAttributeByName("telephoneNumber").getValue(); + assertEquals(1, numberAttr.size()); + assertEquals(NUMBER2, numberAttr.get(0)); + + // 3. updateDelta with values to add + delta = AttributeDeltaBuilder.build( + "telephoneNumber", Collections.singletonList(NUMBER1), Collections.emptyList()); + connector.updateDelta(ObjectClass.ACCOUNT, new Uid(ids.getValue()), Collections.singleton(delta), null); + + bugs = connector.getObject(ObjectClass.ACCOUNT, new Uid(ids.getValue()), options); + numberAttr = bugs.getAttributeByName("telephoneNumber").getValue(); + assertEquals(2, numberAttr.size()); + assertTrue(numberAttr.contains(NUMBER1)); + assertTrue(numberAttr.contains(NUMBER2)); + + // 4. updateDelta with values to replace + assertDoesNotThrow(() -> connector.authenticate( + ObjectClass.ACCOUNT, ids.getValue(), new GuardedString("carrot".toCharArray()), null)); + + delta = AttributeDeltaBuilder.build("telephoneNumber", CollectionUtil.newList(NUMBER1, NUMBER3)); + GuardedString newPwd = new GuardedString("newPwd".toCharArray()); + connector.updateDelta( + ObjectClass.ACCOUNT, + new Uid(ids.getValue()), + CollectionUtil.newSet(delta, AttributeDeltaBuilder.buildPassword(newPwd)), + null); + + bugs = connector.getObject(ObjectClass.ACCOUNT, new Uid(ids.getValue()), options); + numberAttr = bugs.getAttributeByName("telephoneNumber").getValue(); + assertEquals(2, numberAttr.size()); + assertTrue(numberAttr.contains(NUMBER1)); + assertTrue(numberAttr.contains(NUMBER3)); + + assertDoesNotThrow(() -> connector.authenticate(ObjectClass.ACCOUNT, ids.getValue(), newPwd, null)); + connector.removeAttributeValues(ObjectClass.ACCOUNT, new Uid(ids.getValue()), Collections.singleton(telephoneAttr), null); + } + @Test public void rename() { assertNotNull(connector); diff --git a/src/test/resources/docker/tirasaad/Dockerfile b/src/test/resources/docker/tirasaad/Dockerfile index 690945d..3036e78 100644 --- a/src/test/resources/docker/tirasaad/Dockerfile +++ b/src/test/resources/docker/tirasaad/Dockerfile @@ -16,11 +16,12 @@ FROM ubuntu:22.04 +RUN apt-get update && apt-get install -y software-properties-common && rm -rf /var/lib/apt/lists/* +RUN add-apt-repository ppa:linux-schools/samba-latest RUN DEBIAN_FRONTEND=noninteractive apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install samba krb5-config winbind smbclient RUN DEBIAN_FRONTEND=noninteractive apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install iproute2 RUN DEBIAN_FRONTEND=noninteractive apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install openssl RUN DEBIAN_FRONTEND=noninteractive apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install vim -RUN DEBIAN_FRONTEND=noninteractive apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install ldb-tools RUN rm /etc/krb5.conf RUN mkdir -p /opt/ad-scripts diff --git a/src/test/resources/docker/tirasaad/samba-ad-setup.sh b/src/test/resources/docker/tirasaad/samba-ad-setup.sh index 3962123..d1ff597 100755 --- a/src/test/resources/docker/tirasaad/samba-ad-setup.sh +++ b/src/test/resources/docker/tirasaad/samba-ad-setup.sh @@ -31,8 +31,6 @@ info "Provisioning domain controller..." info "Given admin password: ${SMB_ADMIN_PASSWORD}" -rm /etc/samba/smb.conf - samba-tool domain provision\ --server-role=dc\ --use-rfc2307\