hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From weic...@apache.org
Subject hadoop git commit: HADOOP-13353. LdapGroupsMapping getPassward shouldn't return null when IOException throws. Contributed by Zhaohao Liang and Wei-Chiu Chuang.
Date Fri, 05 Aug 2016 23:36:53 GMT
Repository: hadoop
Updated Branches:
  refs/heads/branch-2 0e48f2993 -> d875dfef3


HADOOP-13353. LdapGroupsMapping getPassward shouldn't return null when IOException throws.
Contributed by Zhaohao Liang and Wei-Chiu Chuang.

(cherry picked from commit 49ba09a9221ad1e25e89800f6c455bbaad41483b)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/d875dfef
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/d875dfef
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/d875dfef

Branch: refs/heads/branch-2
Commit: d875dfef3dfa91c3af6a90830a6d9c28df490db3
Parents: 0e48f29
Author: Wei-Chiu Chuang <weichiu@apache.org>
Authored: Fri Aug 5 16:32:44 2016 -0700
Committer: Wei-Chiu Chuang <weichiu@apache.org>
Committed: Fri Aug 5 16:35:28 2016 -0700

----------------------------------------------------------------------
 .../hadoop/security/LdapGroupsMapping.java      | 12 ++++-------
 .../hadoop/security/TestLdapGroupsMapping.java  | 21 ++++++++++++++++++++
 2 files changed, 25 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/d875dfef/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/LdapGroupsMapping.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/LdapGroupsMapping.java
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/LdapGroupsMapping.java
index 4b941ef..24d07c6 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/LdapGroupsMapping.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/LdapGroupsMapping.java
@@ -616,19 +616,15 @@ public class LdapGroupsMapping
   }
 
   String getPassword(Configuration conf, String alias, String defaultPass) {
-    String password = null;
+    String password = defaultPass;
     try {
       char[] passchars = conf.getPassword(alias);
       if (passchars != null) {
         password = new String(passchars);
       }
-      else {
-        password = defaultPass;
-      }
-    }
-    catch (IOException ioe) {
-      LOG.warn("Exception while trying to password for alias " + alias + ": "
-          + ioe.getMessage());
+    } catch (IOException ioe) {
+      LOG.warn("Exception while trying to get password for alias " + alias
+              + ": ", ioe);
     }
     return password;
   }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/d875dfef/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMapping.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMapping.java
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMapping.java
index 131b4e6..9e9f5a5 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMapping.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMapping.java
@@ -57,6 +57,7 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
+import org.mockito.Mockito;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -364,4 +365,24 @@ public class TestLdapGroupsMapping extends TestLdapGroupsMappingBase
{
     }
   }
 
+  /**
+   * Make sure that when
+   * {@link Configuration#getPassword(String)} throws an IOException,
+   * {@link LdapGroupsMapping#setConf(Configuration)} does not throw an NPE.
+   *
+   * @throws Exception
+   */
+  @Test(timeout = 10000)
+  public void testSetConf() throws Exception {
+    Configuration conf = new Configuration();
+    Configuration mockConf = Mockito.spy(conf);
+    when(mockConf.getPassword(anyString()))
+        .thenThrow(new IOException("injected IOException"));
+    // Set a dummy LDAP server URL.
+    mockConf.set(LdapGroupsMapping.LDAP_URL_KEY, "ldap://test");
+
+    LdapGroupsMapping groupsMapping = getGroupsMapping();
+    groupsMapping.setConf(mockConf);
+  }
+
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message