|
@@ -20,6 +20,8 @@ package org.apache.hadoop.hdfs.server.datanode.web.webhdfs;
|
|
|
|
|
|
import static org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod.KERBEROS;
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
+import static org.mockito.Mockito.spy;
|
|
|
+import static org.mockito.Mockito.verify;
|
|
|
import io.netty.handler.codec.http.QueryStringDecoder;
|
|
|
|
|
|
import java.io.IOException;
|
|
@@ -31,6 +33,7 @@ import org.apache.hadoop.fs.FileSystem;
|
|
|
import org.apache.hadoop.hdfs.DFSConfigKeys;
|
|
|
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier;
|
|
|
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenSecretManager;
|
|
|
+import org.apache.hadoop.hdfs.server.common.JspHelper;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
|
|
|
import org.apache.hadoop.hdfs.web.WebHdfsConstants;
|
|
|
import org.apache.hadoop.hdfs.web.WebHdfsFileSystem;
|
|
@@ -186,6 +189,35 @@ public class TestDataNodeUGIProvider {
|
|
|
ugi11, url22);
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testUGINullTokenSecure() throws IOException {
|
|
|
+ SecurityUtil.setAuthenticationMethod(KERBEROS, conf);
|
|
|
+ UserGroupInformation.setConfiguration(conf);
|
|
|
+
|
|
|
+ String uri1 = WebHdfsFileSystem.PATH_PREFIX
|
|
|
+ + PATH
|
|
|
+ + "?op=OPEN"
|
|
|
+ + Param.toSortedString("&", new OffsetParam((long) OFFSET),
|
|
|
+ new LengthParam((long) LENGTH), new UserParam("root"));
|
|
|
+
|
|
|
+ ParameterParser params = new ParameterParser(
|
|
|
+ new QueryStringDecoder(URI.create(uri1)), conf);
|
|
|
+
|
|
|
+ DataNodeUGIProvider ugiProvider = new DataNodeUGIProvider(params);
|
|
|
+
|
|
|
+ String usernameFromQuery = params.userName();
|
|
|
+ String doAsUserFromQuery = params.doAsUser();
|
|
|
+ String remoteUser = usernameFromQuery == null ? JspHelper
|
|
|
+ .getDefaultWebUserName(params.conf())
|
|
|
+ : usernameFromQuery;
|
|
|
+
|
|
|
+ DataNodeUGIProvider spiedUGIProvider = spy(ugiProvider);
|
|
|
+ spiedUGIProvider.ugi();
|
|
|
+
|
|
|
+ verify(spiedUGIProvider).nonTokenUGI(usernameFromQuery, doAsUserFromQuery,
|
|
|
+ remoteUser);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Wait for expiration of entries from the UGI cache. We need to be careful
|
|
|
* not to touch the entries in the cache while we're waiting for expiration.
|