Search in sources :

Example 21 with PlainSchemaTO

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"));
}
Also used : PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) UserTO(org.apache.syncope.common.lib.to.UserTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 22 with PlainSchemaTO

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()));
    }
}
Also used : PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Test(org.junit.jupiter.api.Test)

Example 23 with PlainSchemaTO

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);
}
Also used : PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) Test(org.junit.jupiter.api.Test)

Example 24 with PlainSchemaTO

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);
}
Also used : PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) Test(org.junit.jupiter.api.Test)

Example 25 with PlainSchemaTO

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()));
    }
}
Also used : PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Test(org.junit.jupiter.api.Test)

Aggregations

PlainSchemaTO (org.apache.syncope.common.lib.to.PlainSchemaTO)39 Test (org.junit.jupiter.api.Test)26 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)19 AnyTypeClassTO (org.apache.syncope.common.lib.to.AnyTypeClassTO)11 UserTO (org.apache.syncope.common.lib.to.UserTO)9 AttrTO (org.apache.syncope.common.lib.to.AttrTO)6 Response (javax.ws.rs.core.Response)5 IOException (java.io.IOException)4 Set (java.util.Set)4 StandardCharsets (java.nio.charset.StandardCharsets)3 AnyTypeTO (org.apache.syncope.common.lib.to.AnyTypeTO)3 DerSchemaTO (org.apache.syncope.common.lib.to.DerSchemaTO)3 GroupTO (org.apache.syncope.common.lib.to.GroupTO)3 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)3 SchemaService (org.apache.syncope.common.rest.api.service.SchemaService)3 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 ListIterator (java.util.ListIterator)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2