Skip to content

Commit

Permalink
Add tests for anyObjects
Browse files Browse the repository at this point in the history
Creating a 'device' object
  • Loading branch information
Sylinsic committed Oct 2, 2023
1 parent 97c932e commit 2f33c4b
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,42 @@ public void accountUserNameAttributesItemNotNull() {
assertThrows(ConfigurationException.class, () -> config.validate());
}

@Test
public void anyObjectNameAttributesNotEmpty() {
config.setAnyObjectNameAttributes();
assertThrows(ConfigurationException.class, () -> config.validate());
}

@Test
public void anyObjectNameAttributesNotNull() {
config.setAnyObjectNameAttributes((String) null);
assertThrows(ConfigurationException.class, () -> config.validate());
}

@Test
public void anyObjectNameAttributesNotBlank() {
config.setAnyObjectNameAttributes(" ");
assertThrows(ConfigurationException.class, () -> config.validate());
}

@Test
public void anyObjectClassesNotEmpty() {
config.setAnyObjectClasses();
assertThrows(ConfigurationException.class, () -> config.validate());
}

@Test
public void anyObjectClassesNotNull() {
config.setAnyObjectClasses((String) null);
assertThrows(ConfigurationException.class, () -> config.validate());
}

@Test
public void anyObjectClassesNotBlank() {
config.setAnyObjectClasses(" ");
assertThrows(ConfigurationException.class, () -> config.validate());
}

@Test
public void groupMemberAttributeNotNull() {
config.setGroupMemberAttribute(null);
Expand Down Expand Up @@ -311,6 +347,8 @@ public void defaultValues() {
assertNull(config.getGroupSearchFilter());
assertEquals(0, config.getReadTimeout());
assertEquals(0, config.getConnectTimeout());
assertEquals(CollectionUtil.newList("top"), Arrays.asList(config.getAnyObjectClasses()));
assertEquals(CollectionUtil.newList("entryUUID"), Arrays.asList(config.getAnyObjectNameAttributes()));
}

private static void assertCanValidate(LdapConfiguration config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ public abstract class LdapConnectorTestBase {

public static final String USER_0_GIVEN_NAME = "Aaccf";

public static final String DEVICE_0_DN = "cn=Laptop,o=Small Company,dc=example,dc=com";

public static final String DEVICE_0_CN = "Laptop";

public static final String DEVICE_0_SERIALNUMBER = "42";

@BeforeAll
public static void init() throws IOException {
InputStream propStream = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,44 @@ private void doCreateArbitrary(ConnectorFacade facade) {
assertEquals(name, newObject.getName());
}

@Test
public void createArbitraryWhenNameAttributesNotDefault() {
LdapConfiguration config = newConfiguration();
assertFalse(config.getUidAttribute().equalsIgnoreCase("entryDN"));
config.setAnyObjectNameAttributes("cn");
config.setBaseContexts(SMALL_COMPANY_DN);
ConnectorFacade facade = newFacade(config);

doCreateDevice(facade);
}

@Test
public void createArbitraryWhenObjectClassesNotDefault() {
LdapConfiguration config = newConfiguration();
assertFalse(config.getUidAttribute().equalsIgnoreCase("entryDN"));
config.setAnyObjectClasses("top", "organization");
config.setBaseContexts(SMALL_COMPANY_DN);
ConnectorFacade facade = newFacade(config);

doCreateDevice(facade);
}

private void doCreateDevice(ConnectorFacade facade) {
Set<Attribute> attributes = new HashSet<>();
Name name = new Name(DEVICE_0_DN);
attributes.add(name);
attributes.add(AttributeBuilder.build("cn", DEVICE_0_CN));
attributes.add(AttributeBuilder.build("serialNumber", DEVICE_0_SERIALNUMBER));

ObjectClass oclass = new ObjectClass("device");
Uid uid = facade.create(oclass, attributes, null);

ConnectorObject newObject = facade.getObject(oclass, uid, null);
assertEquals(name, newObject.getName());

}


@Test
public void createBinaryAttributes() throws IOException {
ConnectorFacade facade = newFacade();
Expand Down

0 comments on commit 2f33c4b

Please sign in to comment.