1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements.  See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership.  The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License.  You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 package org.apache.hadoop.fs;
20 
21 import java.io.IOException;
22 import java.net.URISyntaxException;
23 
24 import javax.security.auth.login.LoginException;
25 
26 import org.apache.hadoop.conf.Configuration;
27 import org.apache.hadoop.fs.permission.FsPermission;
28 import org.apache.hadoop.hdfs.HdfsConfiguration;
29 import org.apache.hadoop.hdfs.MiniDFSCluster;
30 import org.apache.hadoop.security.UserGroupInformation;
31 import org.junit.After;
32 import org.junit.AfterClass;
33 import org.junit.Before;
34 import org.junit.BeforeClass;
35 
36 public class TestFcHdfsPermission extends FileContextPermissionBase {
37 
38   private static final FileContextTestHelper fileContextTestHelper =
39       new FileContextTestHelper("/tmp/TestFcHdfsPermission");
40   private static FileContext fc;
41 
42   private static MiniDFSCluster cluster;
43   private static Path defaultWorkingDirectory;
44 
45   @Override
getFileContextHelper()46   protected FileContextTestHelper getFileContextHelper() {
47     return fileContextTestHelper;
48   }
49 
50   @Override
getFileContext()51   protected FileContext getFileContext() {
52     return fc;
53   }
54 
55   @BeforeClass
clusterSetupAtBegining()56   public static void clusterSetupAtBegining()
57                                     throws IOException, LoginException, URISyntaxException  {
58     Configuration conf = new HdfsConfiguration();
59     cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build();
60     fc = FileContext.getFileContext(cluster.getURI(0), conf);
61     defaultWorkingDirectory = fc.makeQualified( new Path("/user/" +
62         UserGroupInformation.getCurrentUser().getShortUserName()));
63     fc.mkdir(defaultWorkingDirectory, FileContext.DEFAULT_PERM, true);
64   }
65 
66 
67   @AfterClass
ClusterShutdownAtEnd()68   public static void ClusterShutdownAtEnd() throws Exception {
69     cluster.shutdown();
70   }
71 
72   @Override
73   @Before
setUp()74   public void setUp() throws Exception {
75     super.setUp();
76   }
77 
78   @Override
79   @After
tearDown()80   public void tearDown() throws Exception {
81     super.tearDown();
82   }
83 }
84