harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lvj...@apache.org
Subject svn commit: r651215 - in /harmony/enhanced/classlib/trunk/modules/jndi/src: main/java/org/apache/harmony/jndi/provider/ldap/ test/java/org/apache/harmony/jndi/provider/ldap/ test/java/org/apache/harmony/jndi/provider/ldap/mock/
Date Thu, 24 Apr 2008 10:17:01 GMT
Author: lvjing
Date: Thu Apr 24 03:16:47 2008
New Revision: 651215

URL: http://svn.apache.org/viewvc?rev=651215&view=rev
Log:
Apply patch for HARMONY-5786,[classlib][jndi][ldap] - decode UnsolicitedNotificationImpl incorrectly

Added:
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/mock/DisconnectResponse.java
  (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/UnsolicitedNotificationImpl.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextServerMockedTest.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/mock/BindResponse.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/mock/MockLdapServer.java

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java?rev=651215&r1=651214&r2=651215&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/LdapContextImpl.java
Thu Apr 24 03:16:47 2008
@@ -2514,7 +2514,8 @@
                 EventObject event = null;
                 try {
                     un.setControls(narrowingControls(cs));
-                    event = new UnsolicitedNotificationEvent(this, un);
+                    event = new UnsolicitedNotificationEvent(
+                            LdapContextImpl.this, un);
                 } catch (NamingException e) {
                     event = new NamingExceptionEvent(LdapContextImpl.this, e);
                 }
@@ -2637,8 +2638,7 @@
     }
 
     public boolean targetMustExist() throws NamingException {
-        // FIXME
-        return false;
+        return true;
     }
 
     private NamingEvent constructNamingEvent(PersistentSearchResult result,

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/UnsolicitedNotificationImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/UnsolicitedNotificationImpl.java?rev=651215&r1=651214&r2=651215&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/UnsolicitedNotificationImpl.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/UnsolicitedNotificationImpl.java
Thu Apr 24 03:16:47 2008
@@ -40,7 +40,9 @@
     public void decodeValues(Object[] values) {
         result = new LdapResult();
         result.decodeValues(values);
-        oid = Utils.getString(values[4]);
+        if (values[4] != null) {
+            oid = Utils.getString(values[4]);
+        }
         if (values[5] != null) {
             encodedValue = (byte[]) values[5];
         }

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextServerMockedTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextServerMockedTest.java?rev=651215&r1=651214&r2=651215&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextServerMockedTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextServerMockedTest.java
Thu Apr 24 03:16:47 2008
@@ -32,11 +32,17 @@
 import javax.naming.ReferralException;
 import javax.naming.directory.DirContext;
 import javax.naming.directory.InitialDirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.event.EventDirContext;
+import javax.naming.event.NamingExceptionEvent;
 import javax.naming.ldap.Control;
 import javax.naming.ldap.InitialLdapContext;
 import javax.naming.ldap.LdapContext;
 import javax.naming.ldap.PagedResultsControl;
 import javax.naming.ldap.SortControl;
+import javax.naming.ldap.UnsolicitedNotification;
+import javax.naming.ldap.UnsolicitedNotificationEvent;
+import javax.naming.ldap.UnsolicitedNotificationListener;
 
 import junit.framework.TestCase;
 
@@ -44,8 +50,11 @@
 import org.apache.harmony.jndi.provider.ldap.asn1.LdapASN1Constant;
 import org.apache.harmony.jndi.provider.ldap.asn1.Utils;
 import org.apache.harmony.jndi.provider.ldap.mock.BindResponse;
+import org.apache.harmony.jndi.provider.ldap.mock.DisconnectResponse;
 import org.apache.harmony.jndi.provider.ldap.mock.EncodableLdapResult;
+import org.apache.harmony.jndi.provider.ldap.mock.MockLdapMessage;
 import org.apache.harmony.jndi.provider.ldap.mock.MockLdapServer;
+import org.apache.harmony.security.x509.IssuingDistributionPoint;
 
 public class LdapContextServerMockedTest extends TestCase {
     private MockLdapServer server;
@@ -612,5 +621,59 @@
                     ((LdapContext) addr.getContent()).getNameInNamespace());
             assertEquals("nns", addr.getType());
         }
+    }
+    public void testUnsolicitedNotification() throws Exception {
+        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
+                LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
+        LdapContext context = new InitialLdapContext(env, null);
+
+        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
+                LdapASN1Constant.OP_SEARCH_RESULT_DONE,
+                new EncodableLdapResult(), null) });
+        EventDirContext eventContext = (EventDirContext) context.lookup("");
+
+        assertTrue(eventContext.targetMustExist());
+
+        MockUnsolicitedNotificationListener listener = new MockUnsolicitedNotificationListener();
+
+        MockLdapMessage message = new MockLdapMessage(new LdapMessage(
+                LdapASN1Constant.OP_EXTENDED_RESPONSE,
+                new DisconnectResponse(), null));
+        message.setMessageId(0);
+        server.setResponseSeq(new LdapMessage[] { message });
+
+        eventContext.addNamingListener("", "(objectclass=cn)", new Object[0],
+                new SearchControls(), listener);
+        server.disconnectNotify();
+        Thread.sleep(5000);
+        assertNull(listener.exceptionEvent);
+        assertNotNull(listener.unsolicatedEvent);
+        assertTrue(listener.unsolicatedEvent.getSource() instanceof LdapContext);
+        UnsolicitedNotification notification = listener.unsolicatedEvent
+                .getNotification();
+        assertNotNull(notification);
+        assertEquals(DisconnectResponse.oid, notification.getID());
+        assertNull(notification.getControls());
+        assertNull(notification.getException());
+        assertNull(notification.getReferrals());
+        assertNull(notification.getEncodedValue());
+    }
+
+    public class MockUnsolicitedNotificationListener implements
+            UnsolicitedNotificationListener {
+
+        UnsolicitedNotificationEvent unsolicatedEvent;
+
+        NamingExceptionEvent exceptionEvent;
+
+        public void notificationReceived(UnsolicitedNotificationEvent e) {
+            unsolicatedEvent = e;
+        }
+
+        public void namingExceptionThrown(
+                NamingExceptionEvent namingExceptionEvent) {
+            exceptionEvent = namingExceptionEvent;
+        }
+
     }
 }

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/mock/BindResponse.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/mock/BindResponse.java?rev=651215&r1=651214&r2=651215&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/mock/BindResponse.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/mock/BindResponse.java
Thu Apr 24 03:16:47 2008
@@ -18,6 +18,7 @@
 package org.apache.harmony.jndi.provider.ldap.mock;
 
 import org.apache.harmony.jndi.provider.ldap.asn1.ASN1Encodable;
+import org.apache.harmony.jndi.provider.ldap.asn1.Utils;
 
 public class BindResponse implements ASN1Encodable {
 
@@ -36,7 +37,9 @@
 
     public void encodeValues(Object[] values) {
         result.encodeValues(values);
-        values[4] = saslCreds;
+        if (saslCreds != null) {
+            values[4] = Utils.getBytes(saslCreds);
+        }
     }
 
 }

Added: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/mock/DisconnectResponse.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/mock/DisconnectResponse.java?rev=651215&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/mock/DisconnectResponse.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/mock/DisconnectResponse.java
Thu Apr 24 03:16:47 2008
@@ -0,0 +1,36 @@
+/* 
+ *  Licensed to the Apache Software Foundation (ASF) under one or more 
+ *  contributor license agreements.  See the NOTICE file distributed with 
+ *  this work for additional information regarding copyright ownership. 
+ *  The ASF licenses this file to You under the Apache License, Version 2.0 
+ *  (the "License"); you may not use this file except in compliance with 
+ *  the License.  You may obtain a copy of the License at 
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0 
+ * 
+ *  Unless required by applicable law or agreed to in writing, software 
+ *  distributed under the License is distributed on an "AS IS" BASIS, 
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ *  See the License for the specific language governing permissions and 
+ *  limitations under the License. 
+ */
+
+package org.apache.harmony.jndi.provider.ldap.mock;
+
+import org.apache.harmony.jndi.provider.ldap.asn1.ASN1Encodable;
+import org.apache.harmony.jndi.provider.ldap.asn1.Utils;
+
+public class DisconnectResponse implements ASN1Encodable {
+    private EncodableLdapResult result;
+
+    public static final String oid = "1.3.6.1.4.1.1466.20036";
+
+    public DisconnectResponse() {
+        this.result = new EncodableLdapResult();
+    }
+
+    public void encodeValues(Object[] values) {
+        result.encodeValues(values);
+        values[4] = Utils.getBytes(oid);
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/mock/DisconnectResponse.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/mock/MockLdapServer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/mock/MockLdapServer.java?rev=651215&r1=651214&r2=651215&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/mock/MockLdapServer.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/mock/MockLdapServer.java
Thu Apr 24 03:16:47 2008
@@ -42,7 +42,7 @@
 
     private Socket socket;
 
-	private LinkedList<LdapMessage> responses = new LinkedList<LdapMessage>();
+    private LinkedList<LdapMessage> responses = new LinkedList<LdapMessage>();
 
     private int port;
 
@@ -97,12 +97,12 @@
         return port;
     }
 
-	public void setResponseSeq(LdapMessage[] msges) {
-		synchronized (responses) {
-			for (LdapMessage message : msges) {
-				responses.addLast(message);
-			}
-		}
+    public void setResponseSeq(LdapMessage[] msges) {
+        synchronized (responses) {
+            for (LdapMessage message : msges) {
+                responses.addLast(message);
+            }
+        }
 
         synchronized (lock) {
             lock.notify();
@@ -194,6 +194,15 @@
                 // ignore
             }
         }
+    }
+
+    public void disconnectNotify() throws IOException {
+        MockLdapMessage message = new MockLdapMessage(new LdapMessage(
+                LdapASN1Constant.OP_EXTENDED_RESPONSE,
+                new DisconnectResponse(), null));
+        message.setMessageId(0);
+        OutputStream out = socket.getOutputStream();
+        out.write(message.encode());
     }
 
     public String getURL() {



Mime
View raw message