Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8296718: Refactor bootstrap Test Common Functionalities to test/lib/Utils #11029

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -21,6 +21,8 @@
* questions.
*/

import jdk.test.lib.Utils;

import sun.management.jmxremote.ConnectorBootstrap;

import java.io.File;
Expand Down
47 changes: 5 additions & 42 deletions test/jdk/sun/management/jmxremote/bootstrap/RmiTestBase.java
Expand Up @@ -26,6 +26,7 @@
* */

import jdk.test.lib.Platform;
import jdk.test.lib.Utils;

import java.io.File;
import java.io.FilenameFilter;
Expand Down Expand Up @@ -144,55 +145,17 @@ static List<Path> prepareTestFiles(String filenamePattern) throws IOException {
return Collections.unmodifiableList(propertyFiles);
}

/**
* Grant file access.
*
* @param file file to grant access
* @param access user access or full access
* @throws IOException if error occurs
*/
static void grantAccess(Path file, AccessControl access) throws IOException {
Set<String> attr = file.getFileSystem().supportedFileAttributeViews();
if (attr.contains("posix")) {
String perms = access == AccessControl.OWNER ? "rw-------" : "rwxrwxrwx";
Files.setPosixFilePermissions(file, PosixFilePermissions.fromString(perms));
} else if (attr.contains("acl")) {
AclFileAttributeView view = Files.getFileAttributeView(file, AclFileAttributeView.class);
List<AclEntry> acl = new ArrayList<>();
for (AclEntry thisEntry : view.getAcl()) {
if (access == AccessControl.OWNER) {
if (thisEntry.principal().getName().equals(view.getOwner().getName())) {
acl.add(Utils.allowAccess(thisEntry));
} else if (thisEntry.type() == AclEntryType.ALLOW) {
acl.add(Utils.revokeAccess(thisEntry));
} else {
acl.add(thisEntry);
}
} else {
if (!thisEntry.principal().getName().contains("NULL SID")
&& thisEntry.type() != AclEntryType.ALLOW) {
acl.add(Utils.allowAccess(thisEntry));
} else {
acl.add(thisEntry);
}
}
}
view.setAcl(acl);
} else {
throw new RuntimeException("Unsupported file attributes: " + attr);
}
}

/**
* Grant files' access.
*
* @param files files to grant access
* @param access user access or full access
* @throws IOException if error occurs
*/
static void grantFilesAccess(List<Path> files, AccessControl access) throws IOException {
static void grantFilesAccess(List<Path> files, AccessControl access)
throws IOException {
for (Path thisFile : files) {
grantAccess(thisFile, access);
Utils.grantFileAccess(thisFile, access == AccessControl.OWNER);
}
}

Expand All @@ -209,7 +172,7 @@ static void copySsl() throws IOException {
Utils.copyFiles(files, sslTarget, StandardCopyOption.REPLACE_EXISTING);

for (Path file : files) {
grantAccess(sslTarget.resolve(file.getFileName()), AccessControl.EVERYONE);
Utils.fullAccess(sslTarget.resolve(file.getFileName()));
}
}

Expand Down
195 changes: 0 additions & 195 deletions test/jdk/sun/management/jmxremote/bootstrap/Utils.java

This file was deleted.