From 5a277fb06fd16c06548400eb795f53da023a19ed Mon Sep 17 00:00:00 2001
From: Violette Roche-Montane <violette.roche-montane@forgerock.com>
Date: Tue, 01 Oct 2013 13:56:47 +0000
Subject: [PATCH] Backport fix for OPENDJ-1162 - Rest2LDAP returns an invalid binary attribute value

---
 opendj-server2x-adapter/src/main/java/org/forgerock/opendj/adapter/server2x/Converters.java         |    2 +-
 opendj-server2x-adapter/src/test/java/org/forgerock/opendj/adapter/server2x/ConvertersTestCase.java |   32 ++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletions(-)

diff --git a/opendj-server2x-adapter/src/main/java/org/forgerock/opendj/adapter/server2x/Converters.java b/opendj-server2x-adapter/src/main/java/org/forgerock/opendj/adapter/server2x/Converters.java
index 5325143..13cca89 100644
--- a/opendj-server2x-adapter/src/main/java/org/forgerock/opendj/adapter/server2x/Converters.java
+++ b/opendj-server2x-adapter/src/main/java/org/forgerock/opendj/adapter/server2x/Converters.java
@@ -546,7 +546,7 @@
             final org.opends.server.types.Attribute attribute) {
         Attribute sdkAttribute = new LinkedAttribute(attribute.getNameWithOptions());
         for (AttributeValue value : attribute) {
-            sdkAttribute.add(value);
+            sdkAttribute.add(from(value.getValue()));
         }
         return sdkAttribute;
     }
diff --git a/opendj-server2x-adapter/src/test/java/org/forgerock/opendj/adapter/server2x/ConvertersTestCase.java b/opendj-server2x-adapter/src/test/java/org/forgerock/opendj/adapter/server2x/ConvertersTestCase.java
index 4e88d16..b8e533a 100644
--- a/opendj-server2x-adapter/src/test/java/org/forgerock/opendj/adapter/server2x/ConvertersTestCase.java
+++ b/opendj-server2x-adapter/src/test/java/org/forgerock/opendj/adapter/server2x/ConvertersTestCase.java
@@ -59,11 +59,15 @@
 import org.forgerock.testng.ForgeRockTestCase;
 import org.opends.server.core.BindOperation;
 import org.opends.server.core.CompareOperation;
+import org.opends.server.core.DirectoryServer;
 import org.opends.server.core.ExtendedOperation;
 import org.opends.server.core.SearchOperation;
 import org.opends.server.protocols.ldap.LDAPControl;
 import org.opends.server.protocols.ldap.LDAPFilter;
+import org.opends.server.types.Attribute;
 import org.opends.server.types.AttributeValue;
+import org.opends.server.types.AttributeValues;
+import org.opends.server.types.Attributes;
 import org.opends.server.types.DirectoryException;
 import org.opends.server.types.FilterType;
 import org.opends.server.types.LDAPException;
@@ -439,6 +443,34 @@
     }
 
     /**
+     * Converts an LDAP attribute to an SDK attribute.
+     */
+    @Test(groups = { "needRunningServer" })
+    public final void testFromAttribute() throws DirectoryException {
+
+        final org.opends.server.types.Attribute srvAttribute = Attributes.create("CN", "JOHN DOE");
+        final org.forgerock.opendj.ldap.Attribute sdkAttribute = from(srvAttribute);
+
+        assertThat(sdkAttribute.getAttributeDescriptionAsString()).isEqualTo("CN");
+        assertThat(sdkAttribute.size()).isEqualTo(1);
+        assertThat(sdkAttribute.firstValueAsString()).isEqualTo("JOHN DOE");
+    }
+
+    /**
+     * Converts an LDAP attribute to an SDK attribute using binary attribute value.
+     */
+    @Test(groups = { "needRunningServer" })
+    public final void testFromAttributeUsingBinary() throws DirectoryException {
+
+        byte[] data = { 0x00, 0x01, 0x02, (byte) 0xff };
+
+        AttributeValue value = AttributeValues.create(org.opends.server.types.ByteString.wrap(data),
+                org.opends.server.types.ByteString.wrap(data));
+        Attribute attribute = Attributes.create(DirectoryServer.getAttributeType("cn"), value);
+        assertThat(from(attribute).firstValue().toByteArray()).isEqualTo(data);
+    }
+
+    /**
      * Converts an LDAP byte string to an SDK byte string.
      */
     @Test()

--
Gitblit v1.10.0