mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

dugan
08.50.2009 6705948cf506af3d9fcc7bb5b1bf8bbb08c18093
Add finally close contex blocks in attempt to keep JNDI from hanging in test.
1 files modified
28 ■■■■ changed files
opends/tests/unit-tests-testng/src/server/org/opends/server/extensions/SASLOverTLSTestCase.java 28 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/extensions/SASLOverTLSTestCase.java
@@ -176,6 +176,8 @@
  */
  private void
  sslTest(int size, String qop) throws NamingException, IOException {
    LdapContext ctx = null;
    try {
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, factory);
    String url = "ldaps://localhost:" + TestCaseUtils.getServerLdapsPort();
@@ -185,7 +187,7 @@
    env.put(Context.SECURITY_CREDENTIALS, "password");
    env.put("java.naming.ldap.attributes.binary", "jpegPhoto");
    env.put("javax.security.sasl.qop", qop);
    LdapContext ctx = new InitialLdapContext(env, null);
      ctx = new InitialLdapContext(env, null);
    byte[] jpegBytes = getRandomBytes(size);
    ModificationItem[] mods = new ModificationItem[1];
    Attribute jpegPhoto = new BasicAttribute("jpegPhoto", jpegBytes);
@@ -195,8 +197,11 @@
    Attribute jpegPhoto1 = testAttributes.get("jpegPhoto");
    byte[] jpegBytes1 = (byte[]) jpegPhoto1.get();
    Assert.assertTrue(Arrays.equals(jpegBytes, jpegBytes1));
    } finally {
      if(ctx != null)
    ctx.close();
  }
  }
  /**
   * This test was originally testing DIGEST-MD5 confidentiality over StartTLS,
@@ -208,12 +213,14 @@
   */
  @Test(dataProvider = "kiloBytes")
  public void StartTLS(int size) throws NamingException, IOException {
    LdapContext ctx = null;
    try {
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, factory);
    String url = "ldap://localhost:" + TestCaseUtils.getServerLdapPort();
    env.put(Context.PROVIDER_URL, url);
    env.put("java.naming.ldap.attributes.binary", "jpegPhoto");
    LdapContext ctx = new InitialLdapContext(env, null);
      ctx = new InitialLdapContext(env, null);
    StartTlsResponse tls =
      (StartTlsResponse) ctx.extendedOperation(new StartTlsRequest());
    tls.setHostnameVerifier(new SampleVerifier());
@@ -230,8 +237,11 @@
    Attribute jpegPhoto1 = testAttributes.get("jpegPhoto");
    byte[] jpegBytes1 = (byte[]) jpegPhoto1.get();
    Assert.assertTrue(Arrays.equals(jpegBytes, jpegBytes1));
    } finally {
      if(ctx != null)
    ctx.close();
  }
  }
  /**
   * Add the entry we will use. It has it's own password
@@ -240,6 +250,8 @@
   * @throws NamingException If the entry cannot be added.
   */
  private void addTestEntry() throws NamingException {
    DirContext ctx = null;
    try {
    Attribute objectClass = new BasicAttribute("objectclass");
    objectClass.add("top");
    objectClass.add("person");
@@ -262,14 +274,17 @@
    env.put(Context.SECURITY_PRINCIPAL, dirMgr);
    env.put(Context.SECURITY_CREDENTIALS, "password");
    env.put(Context.SECURITY_AUTHENTICATION, simple);
    DirContext ctx = new InitialDirContext(env);
      ctx = new InitialDirContext(env);
    ctx.createSubcontext(testUserDN, entryAttrs);
    ModificationItem[] mods = new ModificationItem[1];
    Attribute pwd = new BasicAttribute("userPassword", "password");
    mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE, pwd);
    ctx.modifyAttributes(testUserDN, mods);
    } finally {
      if (ctx != null)
    ctx.close();
  }
  }
  /**
   * Get a byte buffer with a random set of bytes.
@@ -292,6 +307,8 @@
 * @throws NamingException If the entry cannot be deleted.
 */
  private void deleteTestEntry() throws NamingException {
    DirContext ctx = null;
    try {
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, factory);
    String url = "ldaps://localhost:" + TestCaseUtils.getServerLdapsPort();
@@ -299,10 +316,13 @@
    env.put(Context.SECURITY_PRINCIPAL, dirMgr);
    env.put(Context.SECURITY_CREDENTIALS, "password");
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    DirContext ctx = new InitialDirContext(env);
      ctx = new InitialDirContext(env);
    ctx.destroySubcontext(testUserDN);
    } finally {
      if(ctx != null)
    ctx.close();
  }
  }
  /**
   * Verifier class so JNDI startTLS will work with "localhost" host name.