hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From naganarasimha...@apache.org
Subject hadoop git commit: HADOOP-13353. LdapGroupsMapping getPassward shouldn't return null when IOException throws. Contributed by Wei-Chiu Chuang
Date Sat, 06 Aug 2016 17:50:18 GMT
Repository: hadoop
Updated Branches:
  refs/heads/branch-2.8 e1684f84e -> 8055ff1c3


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


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

Branch: refs/heads/branch-2.8
Commit: 8055ff1c3ca22c25779ca67cf866964d50c5c26e
Parents: e1684f8
Author: Naganarasimha <naganarasimha_gr@apache.org>
Authored: Sat Aug 6 23:18:53 2016 +0530
Committer: Naganarasimha <naganarasimha_gr@apache.org>
Committed: Sat Aug 6 23:18:53 2016 +0530

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


http://git-wip-us.apache.org/repos/asf/hadoop/blob/8055ff1c/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 0369d21..78f9ff7 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
@@ -398,19 +398,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/8055ff1c/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 0a448b4..c9324bd 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
@@ -52,6 +52,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;
 
@@ -314,4 +315,23 @@ 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");
+
+    mappingSpy.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