hadoop-hdfs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bor...@apache.org
Subject svn commit: r950726 - in /hadoop/hdfs/trunk: CHANGES.txt src/test/hdfs/org/apache/hadoop/hdfs/server/common/TestJspHelper.java
Date Wed, 02 Jun 2010 19:09:39 GMT
Author: boryas
Date: Wed Jun  2 19:09:39 2010
New Revision: 950726

URL: http://svn.apache.org/viewvc?rev=950726&view=rev
Log:
HDFS-1039. Adding test for  JspHelper.getUGI

Added:
    hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/server/common/TestJspHelper.java
Modified:
    hadoop/hdfs/trunk/CHANGES.txt

Modified: hadoop/hdfs/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/CHANGES.txt?rev=950726&r1=950725&r2=950726&view=diff
==============================================================================
--- hadoop/hdfs/trunk/CHANGES.txt (original)
+++ hadoop/hdfs/trunk/CHANGES.txt Wed Jun  2 19:09:39 2010
@@ -29,6 +29,8 @@ Trunk (unreleased changes)
 
   BUG FIXES
 
+    HDFS-1039. Adding test for  JspHelper.getUGI(jnp via boryas)
+
     HDFS-1019. Incorrect default values for delegation tokens in 
     hdfs-default.xml (jnp via boryas)
 

Added: hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/server/common/TestJspHelper.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/server/common/TestJspHelper.java?rev=950726&view=auto
==============================================================================
--- hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/server/common/TestJspHelper.java
(added)
+++ hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/server/common/TestJspHelper.java
Wed Jun  2 19:09:39 2010
@@ -0,0 +1,94 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hdfs.server.common;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hdfs.DFSConfigKeys;
+import org.apache.hadoop.hdfs.HdfsConfiguration;
+import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier;
+import org.apache.hadoop.hdfs.server.namenode.NameNode;
+import org.apache.hadoop.io.Text;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.security.token.Token;
+import org.apache.hadoop.security.token.TokenIdentifier;
+import org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSecretManager;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestJspHelper {
+
+  private Configuration conf = new HdfsConfiguration();
+
+  public static class DummySecretManager extends
+      AbstractDelegationTokenSecretManager<DelegationTokenIdentifier> {
+
+    public DummySecretManager(long delegationKeyUpdateInterval,
+        long delegationTokenMaxLifetime, long delegationTokenRenewInterval,
+        long delegationTokenRemoverScanInterval) {
+      super(delegationKeyUpdateInterval, delegationTokenMaxLifetime,
+          delegationTokenRenewInterval, delegationTokenRemoverScanInterval);
+    }
+
+    @Override
+    public DelegationTokenIdentifier createIdentifier() {
+      return null;
+    }
+
+    @Override
+    public byte[] createPassword(DelegationTokenIdentifier dtId) {
+      return new byte[1];
+    }
+  }
+
+  @Test
+  public void testGetUgi() throws IOException {
+    conf.set(DFSConfigKeys.FS_DEFAULT_NAME_KEY, "hdfs://localhost:4321/");
+    HttpServletRequest request = mock(HttpServletRequest.class);
+    String user = "TheDoctor";
+    Text userText = new Text(user);
+    DelegationTokenIdentifier dtId = new DelegationTokenIdentifier(userText,
+        userText, null);
+    Token<DelegationTokenIdentifier> token = new Token<DelegationTokenIdentifier>(
+        dtId, new DummySecretManager(0, 0, 0, 0));
+    String tokenString = token.encodeToUrlString();
+    when(request.getParameter(JspHelper.DELEGATION_PARAMETER_NAME)).thenReturn(
+        tokenString);
+    when(request.getRemoteUser()).thenReturn(user);
+
+    conf.set(DFSConfigKeys.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
+    UserGroupInformation.setConfiguration(conf);
+
+    InetSocketAddress serviceAddr = NameNode.getAddress(conf);
+    Text tokenService = new Text(serviceAddr.getAddress().getHostAddress()
+        + ":" + serviceAddr.getPort());
+
+    UserGroupInformation ugi = JspHelper.getUGI(request, conf);
+    Token<? extends TokenIdentifier> tokenInUgi = ugi.getTokens().iterator()
+        .next();
+    Assert.assertEquals(tokenInUgi.getService(), tokenService);
+  }
+
+}



Mime
View raw message