HADOOP-13240. TestAclCommands.testSetfaclValidations fail. Contributed by John Zhuge.

(cherry picked from commit 43cf6b101d)
(cherry picked from commit 382bcf21e7)
This commit is contained in:
Chris Nauroth 2016-07-21 14:12:31 -07:00
parent 9442e1d48e
commit af3c860bb1
2 changed files with 24 additions and 14 deletions

View File

@ -213,6 +213,10 @@ class AclCommands extends FsCommand {
"Missing either <acl_spec> or <path>"); "Missing either <acl_spec> or <path>");
} }
aclEntries = AclEntry.parseAclSpec(args.removeFirst(), !cf.getOpt("x")); aclEntries = AclEntry.parseAclSpec(args.removeFirst(), !cf.getOpt("x"));
if (aclEntries.isEmpty()) {
throw new HadoopIllegalArgumentException(
"Missing <acl_spec> entry");
}
} }
if (args.isEmpty()) { if (args.isEmpty()) {

View File

@ -43,48 +43,54 @@ import org.apache.hadoop.ipc.RpcNoSuchMethodException;
import org.apache.hadoop.util.Progressable; import org.apache.hadoop.util.Progressable;
import org.apache.hadoop.util.ToolRunner; import org.apache.hadoop.util.ToolRunner;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder;
public class TestAclCommands { public class TestAclCommands {
@Rule
public TemporaryFolder testFolder = new TemporaryFolder();
private String path;
private Configuration conf = null; private Configuration conf = null;
@Before @Before
public void setup() throws IOException { public void setup() throws IOException {
conf = new Configuration(); conf = new Configuration();
path = testFolder.newFile("file").getPath();
} }
@Test @Test
public void testGetfaclValidations() throws Exception { public void testGetfaclValidations() throws Exception {
assertFalse("getfacl should fail without path", assertFalse("getfacl should fail without path",
0 == runCommand(new String[] { "-getfacl" })); 0 == runCommand(new String[] {"-getfacl"}));
assertFalse("getfacl should fail with extra argument", assertFalse("getfacl should fail with extra argument",
0 == runCommand(new String[] { "-getfacl", "/test", "extraArg" })); 0 == runCommand(new String[] {"-getfacl", path, "extraArg"}));
} }
@Test @Test
public void testSetfaclValidations() throws Exception { public void testSetfaclValidations() throws Exception {
assertFalse("setfacl should fail without options", assertFalse("setfacl should fail without options",
0 == runCommand(new String[] { "-setfacl", "/" })); 0 == runCommand(new String[] {"-setfacl", path}));
assertFalse("setfacl should fail without options -b, -k, -m, -x or --set", assertFalse("setfacl should fail without options -b, -k, -m, -x or --set",
0 == runCommand(new String[] { "-setfacl", "-R", "/" })); 0 == runCommand(new String[] {"-setfacl", "-R", path}));
assertFalse("setfacl should fail without path", assertFalse("setfacl should fail without path",
0 == runCommand(new String[] { "-setfacl" })); 0 == runCommand(new String[] {"-setfacl"}));
assertFalse("setfacl should fail without aclSpec", assertFalse("setfacl should fail without aclSpec",
0 == runCommand(new String[] { "-setfacl", "-m", "/path" })); 0 == runCommand(new String[] {"-setfacl", "-m", path}));
assertFalse("setfacl should fail with conflicting options", assertFalse("setfacl should fail with conflicting options",
0 == runCommand(new String[] { "-setfacl", "-m", "/path" })); 0 == runCommand(new String[] {"-setfacl", "-m", path}));
assertFalse("setfacl should fail with extra arguments", assertFalse("setfacl should fail with extra arguments",
0 == runCommand(new String[] { "-setfacl", "/path", "extra" })); 0 == runCommand(new String[] {"-setfacl", path, "extra"}));
assertFalse("setfacl should fail with extra arguments", assertFalse("setfacl should fail with extra arguments",
0 == runCommand(new String[] { "-setfacl", "--set", 0 == runCommand(new String[] {"-setfacl", "--set",
"default:user::rwx", "/path", "extra" })); "default:user::rwx", path, "extra"}));
assertFalse("setfacl should fail with permissions for -x", assertFalse("setfacl should fail with permissions for -x",
0 == runCommand(new String[] { "-setfacl", "-x", "user:user1:rwx", 0 == runCommand(new String[] {"-setfacl", "-x", "user:user1:rwx",
"/path" })); path}));
assertFalse("setfacl should fail ACL spec missing", assertFalse("setfacl should fail ACL spec missing",
0 == runCommand(new String[] { "-setfacl", "-m", 0 == runCommand(new String[] {"-setfacl", "-m", "", path}));
"", "/path" }));
} }
@Test @Test