test/jdk/tools/jpackage/share/InstallDirTest.java
author herrick
Tue, 01 Oct 2019 18:22:34 -0400
branchJDK-8200758-branch
changeset 58434 b00cbf427368
parent 58416 f09bf58c1f17
child 58464 d82489644b15
permissions -rw-r--r--
8231721 : jpackage --install-dir should reject system dirs on Linux Submitted-by: asemenyuk Reviewed-by: kcr, herrick
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
     1
/*
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
     4
 *
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
     7
 * published by the Free Software Foundation.
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
     8
 *
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    13
 * accompanied this code).
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    14
 *
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    18
 *
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    21
 * questions.
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    22
 */
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    23
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    24
import java.nio.file.Path;
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    25
import java.util.HashMap;
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    26
import java.util.Map;
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    27
import java.util.function.Supplier;
58416
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    28
import jdk.jpackage.test.TKit;
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    29
import jdk.jpackage.test.PackageTest;
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    30
import jdk.jpackage.test.PackageType;
58416
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    31
import jdk.jpackage.test.Functional;
58434
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    32
import jdk.jpackage.test.JPackageCommand;
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    33
import jdk.jpackage.test.Annotations.Parameter;
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    34
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    35
/**
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    36
 * Test --install-dir parameter. Output of the test should be installdirtest*.*
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    37
 * package bundle. The output package should provide the same functionality as
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    38
 * the default package but install test application in specified directory.
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    39
 *
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    40
 * Linux:
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    41
 *
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    42
 * Application should be installed in /opt/jpackage/installdirtest folder.
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    43
 *
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    44
 * Mac:
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    45
 *
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    46
 * Application should be installed in /Applications/jpackage/installdirtest.app
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    47
 * folder.
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    48
 *
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    49
 * Windows:
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    50
 *
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    51
 * Application should be installed in %ProgramFiles%/TestVendor/InstallDirTest1234
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    52
 * folder.
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    53
 */
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    54
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    55
/*
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    56
 * @test
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    57
 * @summary jpackage with --install-dir
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    58
 * @library ../helpers
58416
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    59
 * @build jdk.jpackage.test.*
58434
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    60
 * @compile InstallDirTest.java
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    61
 * @modules jdk.jpackage/jdk.jpackage.internal
58434
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    62
 * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    63
 *  --jpt-run=InstallDirTest.testCommon
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    64
 */
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    65
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    66
/*
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    67
 * @test
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    68
 * @summary jpackage with --install-dir
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    69
 * @library ../helpers
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    70
 * @build jdk.jpackage.test.*
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    71
 * @compile InstallDirTest.java
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    72
 * @modules jdk.jpackage/jdk.jpackage.internal
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    73
 * @requires (os.family == "linux")
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    74
 * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    75
 *  --jpt-run=InstallDirTest.testLinuxInvalid,testLinuxUnsupported
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    76
 */
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    77
public class InstallDirTest {
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    78
58434
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    79
    public static void testCommon() {
58416
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    80
        final Map<PackageType, Path> INSTALL_DIRS = Functional.identity(() -> {
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    81
            Map<PackageType, Path> reply = new HashMap<>();
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    82
            reply.put(PackageType.WIN_MSI, Path.of("TestVendor\\InstallDirTest1234"));
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    83
            reply.put(PackageType.WIN_EXE, reply.get(PackageType.WIN_MSI));
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    84
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    85
            reply.put(PackageType.LINUX_DEB, Path.of("/opt/jpackage"));
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    86
            reply.put(PackageType.LINUX_RPM, reply.get(PackageType.LINUX_DEB));
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    87
58416
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    88
            reply.put(PackageType.MAC_PKG, Path.of("/Application/jpackage"));
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    89
            reply.put(PackageType.MAC_DMG, reply.get(PackageType.MAC_PKG));
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    90
58416
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    91
            return reply;
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58301
diff changeset
    92
        }).get();
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
    93
58434
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    94
        new PackageTest().configureHelloApp()
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    95
        .addInitializer(cmd -> {
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    96
            cmd.addArguments("--install-dir", INSTALL_DIRS.get(
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    97
                    cmd.packageType()));
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    98
        }).run();
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
    99
    }
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   100
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   101
    @Parameter("/")
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   102
    @Parameter(".")
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   103
    @Parameter("foo")
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   104
    @Parameter("/opt/foo/.././.")
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   105
    public static void testLinuxInvalid(String installDir) {
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   106
        testLinuxBad(installDir, "Invalid installation directory");
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   107
    }
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   108
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   109
    @Parameter("/usr")
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   110
    @Parameter("/usr/local")
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   111
    @Parameter("/usr/foo")
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   112
    public static void testLinuxUnsupported(String installDir) {
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   113
        testLinuxBad(installDir, "currently unsupported");
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   114
    }
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   115
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   116
    private static void testLinuxBad(String installDir,
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   117
            String errorMessageSubstring) {
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   118
        new PackageTest().configureHelloApp()
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   119
                .setExpectedExitCode(1)
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   120
                .forTypes(PackageType.LINUX)
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   121
                .addInitializer(cmd -> {
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   122
                    cmd.addArguments("--install-dir", installDir);
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   123
                    cmd.saveConsoleOutput(true);
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   124
                })
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   125
                .addBundleVerifier((cmd, result) -> {
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   126
                    String errorMessage = JPackageCommand.filterOutput(result.
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   127
                            getOutput().stream()).filter(line -> line.contains(
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   128
                            errorMessageSubstring)).findFirst().orElse(null);
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   129
                    TKit.assertNotNull(errorMessage, String.format(
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   130
                            "Check output contains [%s] substring",
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   131
                            errorMessageSubstring));
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   132
                })
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58416
diff changeset
   133
                .run();
58113
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
   134
    }
885b0543f6e4 8230726: Improve jpackage jtreg tests
herrick
parents:
diff changeset
   135
}