Return-Path: X-Original-To: apmail-accumulo-commits-archive@www.apache.org Delivered-To: apmail-accumulo-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6AB8717512 for ; Thu, 22 Jan 2015 23:22:33 +0000 (UTC) Received: (qmail 19559 invoked by uid 500); 22 Jan 2015 23:22:33 -0000 Delivered-To: apmail-accumulo-commits-archive@accumulo.apache.org Received: (qmail 19524 invoked by uid 500); 22 Jan 2015 23:22:33 -0000 Mailing-List: contact commits-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list commits@accumulo.apache.org Received: (qmail 19514 invoked by uid 99); 22 Jan 2015 23:22:33 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Jan 2015 23:22:33 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 58B8FE03A3; Thu, 22 Jan 2015 23:22:33 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: elserj@apache.org To: commits@accumulo.apache.org Date: Thu, 22 Jan 2015 23:22:33 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/3] accumulo git commit: ACCUMULO-3512 Create a testing user for the test case. 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 Authored: Thu Jan 22 15:18:57 2015 -0500 Committer: Josh Elser 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 properties = saslParams.getSaslProperties(); - assertEquals(1, properties.size()); - assertEquals(defaultQop.getQuality(), properties.get(Sasl.QOP)); - assertEquals(user, saslParams.getPrincipal()); + testUser.doAs(new PrivilegedExceptionAction() { + @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 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 properties = saslParams.getSaslProperties(); - assertEquals(1, properties.size()); - assertEquals(defaultQop.getQuality(), properties.get(Sasl.QOP)); - assertEquals(user, saslParams.getPrincipal()); + testUser.doAs(new PrivilegedExceptionAction() { + @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 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() { - @Override - public String answer() { - Object[] args = EasyMock.getCurrentArguments(); - return conf.get((Property) args[0]); - } - }).anyTimes(); - EasyMock.expect(siteConfig.iterator()).andAnswer(new IAnswer>>() { + testUser.doAs(new PrivilegedExceptionAction() { @Override - public Iterator> 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() { + @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>>() { + @Override + public Iterator> 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; + } + }); } }