accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject [1/3] accumulo git commit: ACCUMULO-3512 Create a testing user for the test case.
Date Thu, 22 Jan 2015 23:22:33 GMT
Repository: accumulo
Updated Branches:
  refs/heads/master a139e7a75 -> 57caccf26


ACCUMULO-3512 Create a testing user for the test case.


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

Branch: refs/heads/master
Commit: 57caccf26f61e86ea2ab7f152c37fd04d923db8f
Parents: 6d1469e
Author: Josh Elser <elserj@apache.org>
Authored: Thu Jan 22 15:18:57 2015 -0500
Committer: Josh Elser <elserj@apache.org>
Committed: Thu Jan 22 18:22:01 2015 -0500

----------------------------------------------------------------------
 .../core/rpc/SaslConnectionParamsTest.java      | 93 +++++++++++--------
 .../server/AccumuloServerContextTest.java       | 95 +++++++++++---------
 2 files changed, 107 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/57caccf2/core/src/test/java/org/apache/accumulo/core/rpc/SaslConnectionParamsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/rpc/SaslConnectionParamsTest.java
b/core/src/test/java/org/apache/accumulo/core/rpc/SaslConnectionParamsTest.java
index 1f80d50..3910f34 100644
--- a/core/src/test/java/org/apache/accumulo/core/rpc/SaslConnectionParamsTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/rpc/SaslConnectionParamsTest.java
@@ -19,6 +19,7 @@ package org.apache.accumulo.core.rpc;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 
+import java.security.PrivilegedExceptionAction;
 import java.util.Map;
 
 import javax.security.sasl.Sasl;
@@ -37,7 +38,8 @@ import org.junit.Test;
 
 public class SaslConnectionParamsTest {
 
-  private String user;
+  private UserGroupInformation testUser;
+  private String username;
 
   @Before
   public void setup() throws Exception {
@@ -46,7 +48,8 @@ public class SaslConnectionParamsTest {
     Configuration conf = new Configuration(false);
     conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
     UserGroupInformation.setConfiguration(conf);
-    user = UserGroupInformation.getCurrentUser().getUserName();
+    testUser = UserGroupInformation.createUserForTesting("test_user", new String[0]);
+    username = testUser.getUserName();
   }
 
   @Test
@@ -59,47 +62,59 @@ public class SaslConnectionParamsTest {
 
   @Test
   public void testDefaultParamsAsClient() throws Exception {
-    final ClientConfiguration clientConf = ClientConfiguration.loadDefault();
-
-    // The primary is the first component of the principal
-    final String primary = "accumulo";
-    clientConf.withSasl(true, primary);
-
-    assertEquals("true", clientConf.get(ClientProperty.INSTANCE_RPC_SASL_ENABLED));
-
-    final SaslConnectionParams saslParams = SaslConnectionParams.forConfig(clientConf);
-    assertEquals(primary, saslParams.getKerberosServerPrimary());
-
-    final QualityOfProtection defaultQop = QualityOfProtection.get(Property.RPC_SASL_QOP.getDefaultValue());
-    assertEquals(defaultQop, saslParams.getQualityOfProtection());
-
-    Map<String,String> properties = saslParams.getSaslProperties();
-    assertEquals(1, properties.size());
-    assertEquals(defaultQop.getQuality(), properties.get(Sasl.QOP));
-    assertEquals(user, saslParams.getPrincipal());
+    testUser.doAs(new PrivilegedExceptionAction<Void>() {
+      @Override
+      public Void run() throws Exception {
+        final ClientConfiguration clientConf = ClientConfiguration.loadDefault();
+
+        // The primary is the first component of the principal
+        final String primary = "accumulo";
+        clientConf.withSasl(true, primary);
+
+        assertEquals("true", clientConf.get(ClientProperty.INSTANCE_RPC_SASL_ENABLED));
+
+        final SaslConnectionParams saslParams = SaslConnectionParams.forConfig(clientConf);
+        assertEquals(primary, saslParams.getKerberosServerPrimary());
+
+        final QualityOfProtection defaultQop = QualityOfProtection.get(Property.RPC_SASL_QOP.getDefaultValue());
+        assertEquals(defaultQop, saslParams.getQualityOfProtection());
+
+        Map<String,String> properties = saslParams.getSaslProperties();
+        assertEquals(1, properties.size());
+        assertEquals(defaultQop.getQuality(), properties.get(Sasl.QOP));
+        assertEquals(username, saslParams.getPrincipal());
+        return null;
+      }
+    });
   }
 
   @Test
   public void testDefaultParamsAsServer() throws Exception {
-    final ClientConfiguration clientConf = ClientConfiguration.loadDefault();
-
-    // The primary is the first component of the principal
-    final String primary = "accumulo";
-    clientConf.withSasl(true, primary);
-
-    final AccumuloConfiguration rpcConf = ClientContext.convertClientConfig(clientConf);
-    assertEquals("true", clientConf.get(ClientProperty.INSTANCE_RPC_SASL_ENABLED));
-
-    final SaslConnectionParams saslParams = SaslConnectionParams.forConfig(rpcConf);
-    assertEquals(primary, saslParams.getKerberosServerPrimary());
-
-    final QualityOfProtection defaultQop = QualityOfProtection.get(Property.RPC_SASL_QOP.getDefaultValue());
-    assertEquals(defaultQop, saslParams.getQualityOfProtection());
-
-    Map<String,String> properties = saslParams.getSaslProperties();
-    assertEquals(1, properties.size());
-    assertEquals(defaultQop.getQuality(), properties.get(Sasl.QOP));
-    assertEquals(user, saslParams.getPrincipal());
+    testUser.doAs(new PrivilegedExceptionAction<Void>() {
+      @Override
+      public Void run() throws Exception {
+        final ClientConfiguration clientConf = ClientConfiguration.loadDefault();
+
+        // The primary is the first component of the principal
+        final String primary = "accumulo";
+        clientConf.withSasl(true, primary);
+
+        final AccumuloConfiguration rpcConf = ClientContext.convertClientConfig(clientConf);
+        assertEquals("true", clientConf.get(ClientProperty.INSTANCE_RPC_SASL_ENABLED));
+
+        final SaslConnectionParams saslParams = SaslConnectionParams.forConfig(rpcConf);
+        assertEquals(primary, saslParams.getKerberosServerPrimary());
+
+        final QualityOfProtection defaultQop = QualityOfProtection.get(Property.RPC_SASL_QOP.getDefaultValue());
+        assertEquals(defaultQop, saslParams.getQualityOfProtection());
+
+        Map<String,String> properties = saslParams.getSaslProperties();
+        assertEquals(1, properties.size());
+        assertEquals(defaultQop.getQuality(), properties.get(Sasl.QOP));
+        assertEquals(username, saslParams.getPrincipal());
+        return null;
+      }
+    });
   }
 
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/57caccf2/server/base/src/test/java/org/apache/accumulo/server/AccumuloServerContextTest.java
----------------------------------------------------------------------
diff --git a/server/base/src/test/java/org/apache/accumulo/server/AccumuloServerContextTest.java
b/server/base/src/test/java/org/apache/accumulo/server/AccumuloServerContextTest.java
index a596065..49a60a6 100644
--- a/server/base/src/test/java/org/apache/accumulo/server/AccumuloServerContextTest.java
+++ b/server/base/src/test/java/org/apache/accumulo/server/AccumuloServerContextTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.accumulo.server;
 
+import java.security.PrivilegedExceptionAction;
 import java.util.Iterator;
 import java.util.Map.Entry;
 
@@ -40,7 +41,8 @@ import org.junit.Test;
 
 public class AccumuloServerContextTest {
 
-  private String user;
+  private UserGroupInformation testUser;
+  private String username;
 
   @Before
   public void setup() throws Exception {
@@ -49,56 +51,65 @@ public class AccumuloServerContextTest {
     Configuration conf = new Configuration(false);
     conf.set(CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
     UserGroupInformation.setConfiguration(conf);
-    user = UserGroupInformation.getCurrentUser().getUserName();
+    testUser = UserGroupInformation.createUserForTesting("test_user", new String[0]);
+    username = testUser.getUserName();
   }
 
   @Test
   public void testSasl() throws Exception {
-    MockInstance instance = new MockInstance();
-
-    ClientConfiguration clientConf = ClientConfiguration.loadDefault();
-    clientConf.setProperty(ClientProperty.INSTANCE_RPC_SASL_ENABLED, "true");
-    clientConf.setProperty(ClientProperty.KERBEROS_SERVER_PRIMARY, "accumulo");
-    final AccumuloConfiguration conf = ClientContext.convertClientConfig(clientConf);
-    SiteConfiguration siteConfig = EasyMock.createMock(SiteConfiguration.class);
-
-    ServerConfigurationFactory factory = EasyMock.createMock(ServerConfigurationFactory.class);
-    EasyMock.expect(factory.getConfiguration()).andReturn(conf).anyTimes();
-    EasyMock.expect(factory.getSiteConfiguration()).andReturn(siteConfig).anyTimes();
-    EasyMock.expect(factory.getInstance()).andReturn(instance).anyTimes();
-
-    AccumuloServerContext context = EasyMock.createMockBuilder(AccumuloServerContext.class).addMockedMethod("enforceKerberosLogin")
-        .addMockedMethod("getConfiguration").addMockedMethod("getServerConfigurationFactory").createMock();
-    context.enforceKerberosLogin();
-    EasyMock.expectLastCall().anyTimes();
-    EasyMock.expect(context.getConfiguration()).andReturn(conf).anyTimes();
-    EasyMock.expect(context.getServerConfigurationFactory()).andReturn(factory).anyTimes();
-
-    // Just make the SiteConfiguration delegate to our ClientConfiguration (by way of the
AccumuloConfiguration)
-    // Presently, we only need get(Property) and iterator().
-    EasyMock.expect(siteConfig.get(EasyMock.anyObject(Property.class))).andAnswer(new IAnswer<String>()
{
-      @Override
-      public String answer() {
-        Object[] args = EasyMock.getCurrentArguments();
-        return conf.get((Property) args[0]);
-      }
-    }).anyTimes();
 
-    EasyMock.expect(siteConfig.iterator()).andAnswer(new IAnswer<Iterator<Entry<String,String>>>()
{
+    testUser.doAs(new PrivilegedExceptionAction<Void>() {
       @Override
-      public Iterator<Entry<String,String>> answer() {
-        return conf.iterator();
-      }
-    }).anyTimes();
+      public Void run() throws Exception {
+        MockInstance instance = new MockInstance();
+
+        ClientConfiguration clientConf = ClientConfiguration.loadDefault();
+        clientConf.setProperty(ClientProperty.INSTANCE_RPC_SASL_ENABLED, "true");
+        clientConf.setProperty(ClientProperty.KERBEROS_SERVER_PRIMARY, "accumulo");
+        final AccumuloConfiguration conf = ClientContext.convertClientConfig(clientConf);
+        SiteConfiguration siteConfig = EasyMock.createMock(SiteConfiguration.class);
+
+        ServerConfigurationFactory factory = EasyMock.createMock(ServerConfigurationFactory.class);
+        EasyMock.expect(factory.getConfiguration()).andReturn(conf).anyTimes();
+        EasyMock.expect(factory.getSiteConfiguration()).andReturn(siteConfig).anyTimes();
+        EasyMock.expect(factory.getInstance()).andReturn(instance).anyTimes();
 
-    EasyMock.replay(factory, context, siteConfig);
+        AccumuloServerContext context = EasyMock.createMockBuilder(AccumuloServerContext.class).addMockedMethod("enforceKerberosLogin")
+            .addMockedMethod("getConfiguration").addMockedMethod("getServerConfigurationFactory").createMock();
+        context.enforceKerberosLogin();
+        EasyMock.expectLastCall().anyTimes();
+        EasyMock.expect(context.getConfiguration()).andReturn(conf).anyTimes();
+        EasyMock.expect(context.getServerConfigurationFactory()).andReturn(factory).anyTimes();
 
-    Assert.assertEquals(ThriftServerType.SASL, context.getThriftServerType());
-    SaslConnectionParams saslParams = context.getServerSaslParams();
-    Assert.assertEquals(SaslConnectionParams.forConfig(conf), saslParams);
-    Assert.assertEquals(user, saslParams.getPrincipal());
+        // Just make the SiteConfiguration delegate to our ClientConfiguration (by way of
the AccumuloConfiguration)
+        // Presently, we only need get(Property) and iterator().
+        EasyMock.expect(siteConfig.get(EasyMock.anyObject(Property.class))).andAnswer(new
IAnswer<String>() {
+          @Override
+          public String answer() {
+            Object[] args = EasyMock.getCurrentArguments();
+            return conf.get((Property) args[0]);
+          }
+        }).anyTimes();
 
-    EasyMock.verify(factory, context, siteConfig);
+        EasyMock.expect(siteConfig.iterator()).andAnswer(new IAnswer<Iterator<Entry<String,String>>>()
{
+          @Override
+          public Iterator<Entry<String,String>> answer() {
+            return conf.iterator();
+          }
+        }).anyTimes();
+
+        EasyMock.replay(factory, context, siteConfig);
+
+        Assert.assertEquals(ThriftServerType.SASL, context.getThriftServerType());
+        SaslConnectionParams saslParams = context.getServerSaslParams();
+        Assert.assertEquals(SaslConnectionParams.forConfig(conf), saslParams);
+        Assert.assertEquals(username, saslParams.getPrincipal());
+
+        EasyMock.verify(factory, context, siteConfig);
+
+        return null;
+      }
+    });
   }
 
 }


Mime
View raw message