Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8610,7 +8610,7 @@ void checkAccess(String src, FsAction mode) throws IOException {
src = iip.getPath();
INode inode = iip.getLastINode();
if (inode == null) {
throw new FileNotFoundException("Path not found");
throw new FileNotFoundException("Path not found: " + src);
}
if (isPermissionEnabled) {
dir.checkPathAccess(pc, iip, mode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Map;
import java.util.Random;

import org.apache.hadoop.test.GenericTestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hadoop.conf.Configuration;
Expand Down Expand Up @@ -260,6 +261,33 @@ private void createAndCheckPermission(OpType op, Path name, short umask,
checkPermission(name, expectedPermission, delete);
}

@Test
public void testFSNamesystemCheckAccess() throws Exception {
Path testValidDir = new Path("/test1");
Path testValidFile = new Path("/test1/file1");
Path testInvalidPath = new Path("/test2");
fs = FileSystem.get(conf);

fs.mkdirs(testValidDir);
fs.create(testValidFile);

fs.access(testValidDir, FsAction.READ);
fs.access(testValidFile, FsAction.READ);

assertTrue(fs.exists(testValidDir));
assertTrue(fs.exists(testValidFile));

try {
fs.access(testInvalidPath, FsAction.READ);
fail("Failed to get expected FileNotFoundException");
} catch (FileNotFoundException e) {
GenericTestUtils.assertExceptionContains(
"Path not found: " + testInvalidPath, e);
} finally {
fs.delete(testValidDir, true);
}
}

/* Check if the permission of a file/directory is the same as the
* expected permission; If the delete flag is true, delete the
* file/directory afterwards.
Expand Down Expand Up @@ -289,7 +317,7 @@ public void testImmutableFsPermission() throws IOException {
fs.setPermission(new Path("/"),
FsPermission.createImmutable((short)0777));
}

@Test(timeout=30000)
public void testTrashPermission() throws Exception {
// /BSS user1:group2 777
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.junit.Assert.*;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.InetAddress;
import java.net.URI;
Expand All @@ -34,6 +35,7 @@
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.fs.permission.FsAction;
import org.apache.hadoop.ha.HAServiceProtocol;
import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.DFSTestUtil;
Expand All @@ -46,6 +48,7 @@
import org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot;
import org.apache.hadoop.hdfs.server.namenode.top.TopAuditLogger;
import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.test.Whitebox;
import org.junit.After;
import org.junit.Test;
Expand Down Expand Up @@ -120,6 +123,23 @@ public void testStartupSafemode() throws IOException {
+ "isInSafeMode still returned false", fsn.isInSafeMode());
}

@Test
public void testCheckAccess() throws IOException {
Configuration conf = new Configuration();
FSImage fsImage = Mockito.mock(FSImage.class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this, one test is enough, we need not to mock and try

FSEditLog fsEditLog = Mockito.mock(FSEditLog.class);
Mockito.when(fsImage.getEditLog()).thenReturn(fsEditLog);
String src = "/test1";
FSNamesystem fsn = new FSNamesystem(conf, fsImage);
try {
fsn.checkAccess(src, FsAction.READ);
fail("Failed to get expected FileNotFoundException");
} catch (FileNotFoundException e) {
GenericTestUtils.assertExceptionContains(
"Path not found: " + src, e);
}
}

@Test
public void testReplQueuesActiveAfterStartupSafemode() throws IOException, InterruptedException{
Configuration conf = new Configuration();
Expand Down