use of org.apache.syncope.common.lib.to.PlainSchemaTO in project syncope by apache.
the class PlainSchemaITCase method testBinaryValidation.
@Test
public void testBinaryValidation() throws IOException {
// pdf - with validator
PlainSchemaTO schemaTOpdf = new PlainSchemaTO();
schemaTOpdf.setKey("BinaryPDF");
schemaTOpdf.setType(AttrSchemaType.Binary);
schemaTOpdf.setMimeType("application/pdf");
schemaTOpdf.setValidator("BinaryValidator");
schemaTOpdf.setAnyTypeClass("minimal user");
createSchema(SchemaType.PLAIN, schemaTOpdf);
// json - with validator
PlainSchemaTO schemaTOjson = new PlainSchemaTO();
schemaTOjson.setKey("BinaryJSON");
schemaTOjson.setType(AttrSchemaType.Binary);
schemaTOjson.setMimeType("application/json");
schemaTOjson.setValidator("BinaryValidator");
schemaTOjson.setAnyTypeClass("minimal user");
createSchema(SchemaType.PLAIN, schemaTOjson);
// json - no validator
PlainSchemaTO schemaTOjson2 = new PlainSchemaTO();
schemaTOjson2.setKey("BinaryJSON2");
schemaTOjson2.setType(AttrSchemaType.Binary);
schemaTOjson2.setMimeType("application/json");
schemaTOjson2.setAnyTypeClass("minimal user");
createSchema(SchemaType.PLAIN, schemaTOjson2);
UserTO userTO = UserITCase.getUniqueSampleTO("test@syncope.apache.org");
userTO = createUser(userTO).getEntity();
assertNotNull(userTO);
UserPatch userPatch = new UserPatch();
userPatch.setKey(userTO.getKey());
// validation OK - application/pdf -> application/pdf
userPatch.getPlainAttrs().add(new AttrPatch.Builder().operation(PatchOperation.ADD_REPLACE).attrTO(attrTO("BinaryPDF", Base64.getEncoder().encodeToString(IOUtils.readBytesFromStream(getClass().getResourceAsStream("/test.pdf"))))).build());
updateUser(userPatch);
assertNotNull(userService.read(userTO.getKey()).getPlainAttr("BinaryPDF"));
userPatch = new UserPatch();
userPatch.setKey(userTO.getKey());
// validation KO - text/html -> application/pdf
try {
userPatch.getPlainAttrs().add(new AttrPatch.Builder().operation(PatchOperation.ADD_REPLACE).attrTO(attrTO("BinaryPDF", Base64.getEncoder().encodeToString(IOUtils.readBytesFromStream(getClass().getResourceAsStream("/test.html"))))).build());
updateUser(userPatch);
fail("This should not be reacheable");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.InvalidValues, e.getType());
}
userPatch = new UserPatch();
userPatch.setKey(userTO.getKey());
// validation ok - application/json -> application/json
userPatch.getPlainAttrs().add(new AttrPatch.Builder().operation(PatchOperation.ADD_REPLACE).attrTO(attrTO("BinaryJSON", Base64.getEncoder().encodeToString(IOUtils.readBytesFromStream(getClass().getResourceAsStream("/test.json"))))).build());
updateUser(userPatch);
assertNotNull(userService.read(userTO.getKey()).getPlainAttr("BinaryJSON"));
userPatch = new UserPatch();
userPatch.setKey(userTO.getKey());
// no validation - application/xml -> application/json
userPatch.getPlainAttrs().add(new AttrPatch.Builder().operation(PatchOperation.ADD_REPLACE).attrTO(attrTO("BinaryJSON2", Base64.getEncoder().encodeToString(IOUtils.readBytesFromStream(getClass().getResourceAsStream("/test.xml"))))).build());
updateUser(userPatch);
assertNotNull(userService.read(userTO.getKey()).getPlainAttr("BinaryJSON2"));
}
use of org.apache.syncope.common.lib.to.PlainSchemaTO in project syncope by apache.
the class PlainSchemaITCase method createUEnumWithoutEnumeration.
@Test
public void createUEnumWithoutEnumeration() {
PlainSchemaTO schemaTO = new PlainSchemaTO();
schemaTO.setKey("enumcheck");
schemaTO.setType(AttrSchemaType.Enum);
try {
createSchema(SchemaType.PLAIN, schemaTO);
fail("This should not be reacheable");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.InvalidPlainSchema, e.getType());
assertTrue(e.getElements().iterator().next().contains(EntityViolationType.InvalidSchemaEnum.name()));
}
}
use of org.apache.syncope.common.lib.to.PlainSchemaTO in project syncope by apache.
the class PlainSchemaITCase method createBinary.
@Test
public void createBinary() {
PlainSchemaTO schemaTO = new PlainSchemaTO();
schemaTO.setKey("x509certificate");
schemaTO.setType(AttrSchemaType.Binary);
schemaTO.setMimeType("application/x-x509-ca-cert");
createSchema(SchemaType.PLAIN, schemaTO);
}
use of org.apache.syncope.common.lib.to.PlainSchemaTO in project syncope by apache.
the class PlainSchemaITCase method issue259.
@Test
public void issue259() {
PlainSchemaTO schemaTO = buildPlainSchemaTO("schema_issue259", AttrSchemaType.Double);
schemaTO.setUniqueConstraint(true);
schemaTO = createSchema(SchemaType.PLAIN, schemaTO);
assertNotNull(schemaTO);
AnyTypeClassTO typeClass = new AnyTypeClassTO();
typeClass.setKey("issue259");
typeClass.getPlainSchemas().add(schemaTO.getKey());
anyTypeClassService.create(typeClass);
UserTO userTO = UserITCase.getUniqueSampleTO("issue259@syncope.apache.org");
userTO.getAuxClasses().add(typeClass.getKey());
userTO.getPlainAttrs().add(attrTO(schemaTO.getKey(), "1"));
userTO = createUser(userTO).getEntity();
assertNotNull(userTO);
UserTO newUserTO = SerializationUtils.clone(userTO);
newUserTO.getMemberships().add(new MembershipTO.Builder().group("b1f7c12d-ec83-441f-a50e-1691daaedf3b").build());
userTO = userService.update(newUserTO).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
}).getEntity();
assertNotNull(userTO);
}
use of org.apache.syncope.common.lib.to.PlainSchemaTO in project syncope by apache.
the class PlainSchemaITCase method issueSYNCOPE418.
@Test
public void issueSYNCOPE418() {
PlainSchemaTO schema = buildPlainSchemaTO("http://schemas.examples.org/security/authorization/organizationUnit", AttrSchemaType.Double);
try {
createSchema(SchemaType.PLAIN, schema);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.InvalidPlainSchema, e.getType());
assertTrue(e.getElements().iterator().next().contains(EntityViolationType.InvalidKey.name()));
}
}
Aggregations