|
21 | 21 | import static org.junit.jupiter.api.Assertions.assertEquals; |
22 | 22 | import static org.junit.jupiter.api.Assertions.assertFalse; |
23 | 23 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 24 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
24 | 25 | import static org.junit.jupiter.api.Assertions.assertTrue; |
25 | 26 |
|
26 | 27 | import java.text.ParseException; |
|
36 | 37 | import org.apache.syncope.common.lib.SyncopeConstants; |
37 | 38 | import org.apache.syncope.common.lib.types.AnyTypeKind; |
38 | 39 | import org.apache.syncope.common.lib.types.IdRepoEntitlement; |
| 40 | +import org.apache.syncope.core.persistence.api.attrvalue.PlainAttrValidationManager; |
39 | 41 | import org.apache.syncope.core.persistence.api.dao.AnyObjectDAO; |
40 | 42 | import org.apache.syncope.core.persistence.api.dao.AnySearchDAO; |
41 | 43 | import org.apache.syncope.core.persistence.api.dao.AnyTypeDAO; |
42 | 44 | import org.apache.syncope.core.persistence.api.dao.GroupDAO; |
| 45 | +import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO; |
43 | 46 | import org.apache.syncope.core.persistence.api.dao.RealmDAO; |
44 | 47 | import org.apache.syncope.core.persistence.api.dao.RealmSearchDAO; |
45 | 48 | import org.apache.syncope.core.persistence.api.dao.RoleDAO; |
|
56 | 59 | import org.apache.syncope.core.persistence.api.dao.search.SearchCond; |
57 | 60 | import org.apache.syncope.core.persistence.api.entity.AnyType; |
58 | 61 | import org.apache.syncope.core.persistence.api.entity.PlainAttr; |
| 62 | +import org.apache.syncope.core.persistence.api.entity.PlainSchema; |
59 | 63 | import org.apache.syncope.core.persistence.api.entity.anyobject.AMembership; |
60 | 64 | import org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject; |
61 | 65 | import org.apache.syncope.core.persistence.api.entity.group.Group; |
@@ -105,6 +109,12 @@ public class AnySearchTest extends AbstractTest { |
105 | 109 | @Autowired |
106 | 110 | private RoleDAO roleDAO; |
107 | 111 |
|
| 112 | + @Autowired |
| 113 | + private PlainSchemaDAO plainSchemaDAO; |
| 114 | + |
| 115 | + @Autowired |
| 116 | + private PlainAttrValidationManager validator; |
| 117 | + |
108 | 118 | @BeforeEach |
109 | 119 | public void adjustLoginDateForLocalSystem() throws ParseException { |
110 | 120 | User rossini = userDAO.findByUsername("rossini").orElseThrow(); |
@@ -974,4 +984,32 @@ public void issueSYNCOPE1419() { |
974 | 984 | assertNotNull(users); |
975 | 985 | assertEquals(4, users.size()); |
976 | 986 | } |
| 987 | + |
| 988 | + @Test |
| 989 | + public void issueSYNCOPE1922() { |
| 990 | + User bellini = userDAO.findByUsername("bellini").orElseThrow(); |
| 991 | + |
| 992 | + PlainSchema obscureSchema = plainSchemaDAO.findById("obscure").orElseThrow(); |
| 993 | + |
| 994 | + userDAO.save(addPlainAttr(bellini, obscureSchema, "myobscurevalue")); |
| 995 | + |
| 996 | + AttrCond obscureCond = new AttrCond(AttrCond.Type.EQ); |
| 997 | + obscureCond.setSchema("obscure"); |
| 998 | + obscureCond.setExpression("myobscurevalue"); |
| 999 | + |
| 1000 | + assertThrows(IllegalArgumentException.class, |
| 1001 | + () -> searchDAO.search(SearchCond.of(obscureCond), AnyTypeKind.USER)); |
| 1002 | + } |
| 1003 | + |
| 1004 | + protected User addPlainAttr(final User user, final PlainSchema plainSchema, final String value) { |
| 1005 | + user.getPlainAttr(plainSchema.getKey()) |
| 1006 | + .ifPresentOrElse(ctype -> ctype.getValues().get(0).setStringValue(value), () -> { |
| 1007 | + PlainAttr attr = new PlainAttr(); |
| 1008 | + attr.setPlainSchema(plainSchema); |
| 1009 | + attr.add(validator, value); |
| 1010 | + |
| 1011 | + user.add(attr); |
| 1012 | + }); |
| 1013 | + return user; |
| 1014 | + } |
977 | 1015 | } |
0 commit comments