View Javadoc
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,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.codehaus.plexus.archiver.util;
20  
21  import org.junit.jupiter.api.Test;
22  import org.slf4j.Logger;
23  import org.slf4j.LoggerFactory;
24  
25  import static org.junit.jupiter.api.Assertions.assertFalse;
26  import static org.junit.jupiter.api.Assertions.assertTrue;
27  
28  /**
29   * @author Olivier Lamy
30   */
31  class FilePermissionUtilsTest {
32  
33      Logger getLogger() {
34          return LoggerFactory.getLogger("foo");
35      }
36  
37      @Test
38      void testOnlyWritableOnlyUser() throws Exception {
39          FilePermission fp = FilePermissionUtils.getFilePermissionFromMode("200", getLogger());
40          assertTrue(fp.isWritable());
41          assertTrue(fp.isOwnerOnlyWritable());
42          assertFalse(fp.isExecutable());
43          assertTrue(fp.isOwnerOnlyExecutable());
44          assertFalse(fp.isReadable());
45      }
46  
47      @Test
48      void testExecAndRead() {
49          FilePermission fp = FilePermissionUtils.getFilePermissionFromMode("500", getLogger());
50          assertFalse(fp.isWritable());
51          assertTrue(fp.isOwnerOnlyWritable());
52          assertTrue(fp.isExecutable());
53          assertTrue(fp.isOwnerOnlyExecutable());
54          assertTrue(fp.isReadable());
55      }
56  
57      @Test
58      void testAllUser() {
59          FilePermission fp = FilePermissionUtils.getFilePermissionFromMode("700", getLogger());
60          assertTrue(fp.isWritable());
61          assertTrue(fp.isOwnerOnlyWritable());
62          assertTrue(fp.isExecutable());
63          assertTrue(fp.isOwnerOnlyExecutable());
64          assertTrue(fp.isReadable());
65      }
66  
67      @Test
68      void testAllAllUser() {
69          FilePermission fp = FilePermissionUtils.getFilePermissionFromMode("707", getLogger());
70          assertTrue(fp.isWritable());
71          assertFalse(fp.isOwnerOnlyWritable());
72          assertTrue(fp.isExecutable());
73          assertFalse(fp.isOwnerOnlyExecutable());
74          assertTrue(fp.isReadable());
75          assertFalse(fp.isOwnerOnlyReadable());
76      }
77  }