Search in sources :

Example 6 with LdifAttributesReader

use of org.apache.directory.api.ldap.model.ldif.LdifAttributesReader in project directory-ldap-api by apache.

the class LdifAttributesReaderTest method testLdifParserRFC2849Sample5WithSizeLimit.

@Test
public void testLdifParserRFC2849Sample5WithSizeLimit() throws Exception {
    String ldif = "objectclass: top\n" + "objectclass: person\n" + "objectclass: organizationalPerson\n" + "cn: Horatio Jensen\n" + "cn: Horatio N Jensen\n" + "sn: Jensen\n" + "uid: hjensen\n" + "telephonenumber: +1 408 555 1212\n" + "jpegphoto:< file:" + HJENSEN_JPEG_FILE.getAbsolutePath() + "\n";
    LdifAttributesReader reader = new LdifAttributesReader();
    reader.setSizeLimit(128);
    try {
        reader.parseEntry(ldif);
        fail();
    } catch (LdapLdifException ne) {
        assertTrue(I18n.err(I18n.ERR_13442_ERROR_PARSING_LDIF_BUFFER), ne.getMessage().startsWith(I18n.ERR_13442_ERROR_PARSING_LDIF_BUFFER.getErrorCode()));
    }
    reader.close();
}
Also used : LdapLdifException(org.apache.directory.api.ldap.model.ldif.LdapLdifException) LdifAttributesReader(org.apache.directory.api.ldap.model.ldif.LdifAttributesReader) Test(org.junit.Test)

Example 7 with LdifAttributesReader

use of org.apache.directory.api.ldap.model.ldif.LdifAttributesReader in project directory-ldap-api by apache.

the class LdifAttributesReaderTest method testLdifParserCommentsEmptyLines.

@Test
public void testLdifParserCommentsEmptyLines() throws NamingException, Exception {
    String ldif = "#\n" + "#  Licensed to the Apache Software Foundation (ASF) under one\n" + "#  or more contributor license agreements.  See the NOTICE file\n" + "#  distributed with this work for additional information\n" + "#  regarding copyright ownership.  The ASF licenses this file\n" + "#  to you under the Apache License, Version 2.0 (the\n" + "#  \"License\"); you may not use this file except in compliance\n" + "#  with the License.  You may obtain a copy of the License at\n" + "#  \n" + "#    http://www.apache.org/licenses/LICENSE-2.0\n" + "#  \n" + "#  Unless required by applicable law or agreed to in writing,\n" + "#  software distributed under the License is distributed on an\n" + "#  \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n" + "#  KIND, either express or implied.  See the License for the\n" + "#  specific language governing permissions and limitations\n" + "#  under the License. \n" + "#  \n" + "#\n" + "#\n" + "#   EXAMPLE.COM is freely and reserved for testing according to this RFC:\n" + "#\n" + "#   http://www.rfc-editor.org/rfc/rfc2606.txt\n" + "#\n" + "#\n" + "\n" + "#\n" + "# This ACI allows brouse access to the root suffix and one level below that to anyone.\n" + "# At this level there is nothing critical exposed.  Everything that matters is one or\n" + "# more levels below this.\n" + "#\n" + "\n" + "objectClass: top\n" + "objectClass: subentry\n" + "objectClass: accessControlSubentry\n" + "subtreeSpecification: { maximum 1 }\n" + "prescriptiveACI: { identificationTag \"browseRoot\", precedence 100, authenticationLevel none, itemOrUserFirst userFirst: { userClasses { allUsers }, userPermissions { { protectedItems {entry}, grantsAndDenials { grantReturnDN, grantBrowse } } } } }\n";
    LdifAttributesReader reader = new LdifAttributesReader();
    Attributes attributes = reader.parseAttributes(ldif);
    javax.naming.directory.Attribute attr = attributes.get("objectClass");
    assertTrue(attr.contains("top"));
    assertTrue(attr.contains(SchemaConstants.SUBENTRY_OC));
    assertTrue(attr.contains("accessControlSubentry"));
    attr = attributes.get("subtreeSpecification");
    assertTrue(attr.contains("{ maximum 1 }"));
    attr = attributes.get("prescriptiveACI");
    assertTrue(attr.contains("{ identificationTag \"browseRoot\", precedence 100, authenticationLevel none, itemOrUserFirst userFirst: { userClasses { allUsers }, userPermissions { { protectedItems {entry}, grantsAndDenials { grantReturnDN, grantBrowse } } } } }"));
    reader.close();
}
Also used : Attributes(javax.naming.directory.Attributes) LdifAttributesReader(org.apache.directory.api.ldap.model.ldif.LdifAttributesReader) Test(org.junit.Test)

Example 8 with LdifAttributesReader

use of org.apache.directory.api.ldap.model.ldif.LdifAttributesReader in project directory-ldap-api by apache.

the class LdifAttributesReaderTest method testLdifParserMultiLineEntries.

@Test
public void testLdifParserMultiLineEntries() throws LdapLdifException, IOException {
    String ldif = "#comment\n" + "cn: app1#another comment\n" + "objectClass: top\n" + "objectClass: apAppli\n" + " cation\n" + "displayName: app1\n" + "serviceType: http\n" + "dependencies:\n" + "httpHeaders:\n" + "startupOptions:\n" + "envVars:";
    LdifAttributesReader reader = new LdifAttributesReader();
    Entry entry = reader.parseEntry(ldif);
    assertNotNull(entry);
    Attribute attr = entry.get("cn");
    assertTrue(attr.contains("app1#another comment"));
    attr = entry.get("objectclass");
    assertTrue(attr.contains("top"));
    assertTrue(attr.contains("apApplication"));
    attr = entry.get("displayname");
    assertTrue(attr.contains("app1"));
    attr = entry.get("dependencies");
    assertEquals("", attr.get().getValue());
    attr = entry.get("envvars");
    assertEquals("", attr.get().getValue());
    reader.close();
}
Also used : Entry(org.apache.directory.api.ldap.model.entry.Entry) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) LdifAttributesReader(org.apache.directory.api.ldap.model.ldif.LdifAttributesReader) Test(org.junit.Test)

Example 9 with LdifAttributesReader

use of org.apache.directory.api.ldap.model.ldif.LdifAttributesReader in project directory-ldap-api by apache.

the class LdifAttributesReaderTest method testLdifNull.

@Test
public void testLdifNull() throws LdapLdifException, IOException {
    String ldif = null;
    LdifAttributesReader reader = new LdifAttributesReader();
    Entry entry = reader.parseEntry(ldif);
    assertEquals(0, entry.size());
    reader.close();
}
Also used : Entry(org.apache.directory.api.ldap.model.entry.Entry) LdifAttributesReader(org.apache.directory.api.ldap.model.ldif.LdifAttributesReader) Test(org.junit.Test)

Example 10 with LdifAttributesReader

use of org.apache.directory.api.ldap.model.ldif.LdifAttributesReader in project directory-ldap-api by apache.

the class LdifAttributesReaderTest method testLdifParserBase64MultiLine.

@Test
public void testLdifParserBase64MultiLine() throws LdapLdifException, IOException {
    String ldif = "#comment\n" + "cn:: RW1tYW51ZWwg\n" + " TMOpY2hhcm55ICA=\n" + "objectClass: top\n" + "objectClass: apApplication\n" + "displayName: app1\n" + "serviceType: http\n" + "dependencies:\n" + "httpHeaders:\n" + "startupOptions:\n" + "envVars:";
    LdifAttributesReader reader = new LdifAttributesReader();
    Entry entry = reader.parseEntry(ldif);
    assertNotNull(entry);
    Attribute attr = entry.get("cn");
    assertTrue(attr.contains("Emmanuel L\u00e9charny  ".getBytes(StandardCharsets.UTF_8)));
    attr = entry.get("objectclass");
    assertTrue(attr.contains("top"));
    assertTrue(attr.contains("apApplication"));
    attr = entry.get("displayname");
    assertTrue(attr.contains("app1"));
    attr = entry.get("dependencies");
    assertEquals("", attr.get().getValue());
    attr = entry.get("envvars");
    assertEquals("", attr.get().getValue());
    reader.close();
}
Also used : Entry(org.apache.directory.api.ldap.model.entry.Entry) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) LdifAttributesReader(org.apache.directory.api.ldap.model.ldif.LdifAttributesReader) Test(org.junit.Test)

Aggregations

LdifAttributesReader (org.apache.directory.api.ldap.model.ldif.LdifAttributesReader)21 Test (org.junit.Test)20 Entry (org.apache.directory.api.ldap.model.entry.Entry)13 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)9 Attributes (javax.naming.directory.Attributes)6 LdapLdifException (org.apache.directory.api.ldap.model.ldif.LdapLdifException)2 IOException (java.io.IOException)1 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)1