Skip to content

Commit

Permalink
Fixing ISNULL search condition with pgjsonb
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgrosso committed Nov 21, 2023
1 parent 19248e6 commit eb81536
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ protected void fillAttrQuery(
switch (cond.getType()) {

case ISNULL:
// shouldn't occour: processed before
query.append(column).append(" IS NULL");
break;

case ISNOTNULL:
Expand Down Expand Up @@ -816,8 +816,9 @@ protected void fillAttrQuery(
query.append(column);
query.append('=');

if ((schema.getType() == AttrSchemaType.String
|| schema.getType() == AttrSchemaType.Enum) && lower) {
if (lower
&& (schema.getType() == AttrSchemaType.String || schema.getType() == AttrSchemaType.Enum)) {

query.append("LOWER(?").append(setParameter(parameters, attrValue.getValue())).append(')');
} else {
query.append('?').append(setParameter(parameters, attrValue.getValue()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,23 @@ public void asGroupOwner() {
}
}

@Test
public void changePwdDate() {
AnyCond statusCond = new AnyCond(AttrCond.Type.IEQ);
statusCond.setSchema("status");
statusCond.setExpression("suspended");

AnyCond changePwdDateCond = new AnyCond(AttrCond.Type.ISNULL);
changePwdDateCond.setSchema("changePwdDate");

SearchCond cond = SearchCond.getAnd(SearchCond.getNotLeaf(statusCond), SearchCond.getLeaf(changePwdDateCond));
assertTrue(cond.isValid());

List<User> users = searchDAO.search(cond, AnyTypeKind.USER);
assertNotNull(users);
assertEquals(5, users.size());
}

@Test
public void issue202() {
ResourceCond ws2 = new ResourceCond();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,14 @@ public void searchConnObjectsWithFilter() {
anyMatch(connObject -> connObject.getAttr("homePhone").isEmpty()));
}

@Test
public void changePwdDate() {
int users = USER_SERVICE.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).
fiql("status!~suspended;changePwdDate==$null").build()).
getTotalCount();
assertTrue(users > 0);
}

@Test
public void issueSYNCOPE768() {
int usersWithNullable = USER_SERVICE.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).
Expand Down

0 comments on commit eb81536

Please sign in to comment.