Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AD-76] maven profile for starting in embedded mode and run single IT; create IT case for update delta feature #24

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 38 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<exec.skip>false</exec.skip>
<skipTests>false</skipTests>
</properties>

<dependencies>
Expand Down Expand Up @@ -297,7 +298,7 @@
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<skipTests>${exec.skip}</skipTests>
<skipTests>${skipTests}</skipTests>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<runOrder>alphabetical</runOrder>
</configuration>
Expand All @@ -317,7 +318,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<inherited>true</inherited>
<configuration>
<skipTests>${exec.skip}</skipTests>
<skipTests>${skipTests}</skipTests>
</configuration>
<executions>
<execution>
Expand All @@ -327,7 +328,7 @@
<goal>test</goal>
</goals>
<configuration>
<skip>${exec.skip}</skip>
<skip>${skipTests}</skip>
<includes>
<include>**/*Test.java</include>
</includes>
Expand All @@ -341,7 +342,6 @@
<artifactId>docker-maven-plugin</artifactId>
<version>0.44.0</version>
<configuration>
<skip>${exec.skip}</skip>
<images>
<image>
<alias>tirasaad</alias>
Expand Down Expand Up @@ -369,7 +369,7 @@
</bind>
</volumes>
<wait>
<log>samba version 4.15.13-Ubuntu started</log>
<log>samba version 4.19.5 started</log>
<time>60000</time>
</wait>
</run>
Expand All @@ -384,6 +384,9 @@
<goal>stop</goal>
<goal>remove</goal>
</goals>
<configuration>
<skip>${exec.skip}</skip>
</configuration>
</execution>
<execution>
<id>start-docker</id>
Expand All @@ -392,6 +395,9 @@
<goal>build</goal>
<goal>start</goal>
</goals>
<configuration>
<skip>${exec.skip}</skip>
</configuration>
</execution>
<execution>
<id>remove-containers-post-test</id>
Expand All @@ -400,6 +406,9 @@
<goal>stop</goal>
<goal>remove</goal>
</goals>
<configuration>
<skip>${exec.skip}</skip>
</configuration>
</execution>
</executions>
</plugin>
Expand All @@ -425,13 +434,37 @@
<id>skipTests</id>

<properties>
<skipTests>true</skipTests>
<exec.skip>true</exec.skip>
</properties>

<build>
<defaultGoal>clean install</defaultGoal>
</build>
</profile>
<profile>
<id>debug</id>
<properties>
<skipTests>true</skipTests>
<exec.skip>true</exec.skip>
</properties>
<build>
<defaultGoal>clean package io.fabric8:docker-maven-plugin:build io.fabric8:docker-maven-plugin:start
</defaultGoal>
</build>
</profile>
<profile>
<id>tests</id>

<properties>
<skipTests>false</skipTests>
<exec.skip>true</exec.skip>
</properties>

<build>
<defaultGoal>test</defaultGoal>
</build>
</profile>
</profiles>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -45,13 +46,16 @@
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;
import org.identityconnectors.framework.api.ConnectorFacadeFactory;
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;
Expand All @@ -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<ConnectorObject> results = new ArrayList<>();
Expand Down Expand Up @@ -448,6 +459,108 @@ public void update() {
// --------------------------
}

@Test
public void updateDeltaNoValuePresent() {
assertNotNull(connector);
assertNotNull(conf);

final Map.Entry<String, String> 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<String, String> 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<Object> 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);
Expand Down
3 changes: 2 additions & 1 deletion src/test/resources/docker/tirasaad/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/test/resources/docker/tirasaad/samba-ad-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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\
Expand Down