Mercurial > hg > release > thermostat-2.0
changeset 2606:f898d30b7b1c
Agent fails to start when -Duser.name is set but not to current OS user
Reviewed-by: jerboaa
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-February/022239.html
PR3233
line wrap: on
line diff
--- a/agent/ipc/client/pom.xml Thu Mar 02 15:00:42 2017 -0500 +++ b/agent/ipc/client/pom.xml Thu Mar 02 17:20:48 2017 -0500 @@ -77,17 +77,6 @@ so we override parent pom's configuration --> <configuration combine.self="override" /> </plugin> - <!-- This is a dependency of the Byteman helper and that needs source - level JDK 6 in order to be able to use the helper for JVMs running - on JDK 6. --> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <configuration> - <source>1.6</source> - <target>1.6</target> - </configuration> - </plugin> </plugins> </build>
--- a/agent/ipc/common/pom.xml Thu Mar 02 15:00:42 2017 -0500 +++ b/agent/ipc/common/pom.xml Thu Mar 02 17:20:48 2017 -0500 @@ -89,17 +89,6 @@ so we override parent pom's configuration --> <configuration combine.self="override" /> </plugin> - <!-- This is a dependency of the Byteman helper and that needs source - level JDK 6 in order to be able to use the helper for JVMs running - on JDK 6. --> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <configuration> - <source>1.6</source> - <target>1.6</target> - </configuration> - </plugin> </plugins> </build>
--- a/agent/ipc/tcp-socket/client/pom.xml Thu Mar 02 15:00:42 2017 -0500 +++ b/agent/ipc/tcp-socket/client/pom.xml Thu Mar 02 17:20:48 2017 -0500 @@ -82,17 +82,6 @@ so we override parent pom's configuration --> <configuration combine.self="override" /> </plugin> - <!-- This is a dependency of the Byteman helper and that needs source - level JDK 6 in order to be able to use the helper for JVMs running - on JDK 6. --> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <configuration> - <source>1.6</source> - <target>1.6</target> - </configuration> - </plugin> </plugins> </build>
--- a/agent/ipc/tcp-socket/common/pom.xml Thu Mar 02 15:00:42 2017 -0500 +++ b/agent/ipc/tcp-socket/common/pom.xml Thu Mar 02 17:20:48 2017 -0500 @@ -94,17 +94,6 @@ so we override parent pom's configuration --> <configuration combine.self="override" /> </plugin> - <!-- This is a dependency of the Byteman helper and that needs source - level JDK 6 in order to be able to use the helper for JVMs running - on JDK 6. --> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <configuration> - <source>1.6</source> - <target>1.6</target> - </configuration> - </plugin> </plugins> </build>
--- a/agent/ipc/unix-socket/client/pom.xml Thu Mar 02 15:00:42 2017 -0500 +++ b/agent/ipc/unix-socket/client/pom.xml Thu Mar 02 17:20:48 2017 -0500 @@ -86,17 +86,6 @@ so we override parent pom's configuration --> <configuration combine.self="override" /> </plugin> - <!-- This is a dependency of the Byteman helper and that needs source - level JDK 6 in order to be able to use the helper for JVMs running - on JDK 6. --> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <configuration> - <source>1.6</source> - <target>1.6</target> - </configuration> - </plugin> </plugins> </build>
--- a/agent/ipc/unix-socket/client/src/main/java/com/redhat/thermostat/agent/ipc/unixsocket/client/internal/UnixSocketTransportImpl.java Thu Mar 02 15:00:42 2017 -0500 +++ b/agent/ipc/unix-socket/client/src/main/java/com/redhat/thermostat/agent/ipc/unixsocket/client/internal/UnixSocketTransportImpl.java Thu Mar 02 17:20:48 2017 -0500 @@ -38,28 +38,33 @@ import java.io.File; import java.io.IOException; +import java.nio.file.attribute.UserPrincipal; import com.redhat.thermostat.agent.ipc.client.IPCMessageChannel; import com.redhat.thermostat.agent.ipc.client.internal.ClientTransport; import com.redhat.thermostat.agent.ipc.common.internal.IPCProperties; import com.redhat.thermostat.agent.ipc.unixsocket.common.internal.ThermostatLocalSocketChannelImpl; import com.redhat.thermostat.agent.ipc.unixsocket.common.internal.UnixSocketIPCProperties; +import com.redhat.thermostat.agent.ipc.unixsocket.common.internal.UserPrincipalUtils; public class UnixSocketTransportImpl implements ClientTransport { private final UnixSocketIPCProperties socketProps; private final SocketHelper sockHelper; + private final UserPrincipalUtils userUtils; UnixSocketTransportImpl(IPCProperties props) throws IOException { - this(props, new SocketHelper()); + this(props, new SocketHelper(), new UserPrincipalUtils()); } - UnixSocketTransportImpl(IPCProperties props, SocketHelper sockHelper) throws IOException { + UnixSocketTransportImpl(IPCProperties props, SocketHelper sockHelper, + UserPrincipalUtils userUtils) throws IOException { if (!(props instanceof UnixSocketIPCProperties)) { throw new IOException("Unexpected IPC properties for 'socket' type"); } this.socketProps = (UnixSocketIPCProperties) props; this.sockHelper = sockHelper; + this.userUtils = userUtils; } @Override @@ -77,7 +82,8 @@ } // Get subdirectory for current user - String username = sockHelper.getUsername(); + UserPrincipal currentUser = userUtils.getCurrentUser(); + String username = currentUser.getName(); File socketFile = socketProps.getSocketFile(name, username); if (!socketFile.exists()) { throw new IOException("IPC server with name \"" + name + "\" does not exist"); @@ -105,10 +111,6 @@ File getFile(File socketDir, String name) { return new File(socketDir, name); } - - String getUsername() { - return System.getProperty("user.name"); - } } }
--- a/agent/ipc/unix-socket/client/src/test/java/com/redhat/thermostat/agent/ipc/unixsocket/client/internal/UnixSocketTransportImplTest.java Thu Mar 02 15:00:42 2017 -0500 +++ b/agent/ipc/unix-socket/client/src/test/java/com/redhat/thermostat/agent/ipc/unixsocket/client/internal/UnixSocketTransportImplTest.java Thu Mar 02 17:20:48 2017 -0500 @@ -46,6 +46,7 @@ import java.io.File; import java.io.IOException; +import java.nio.file.attribute.UserPrincipal; import org.junit.Before; import org.junit.Test; @@ -55,6 +56,7 @@ import com.redhat.thermostat.agent.ipc.unixsocket.client.internal.UnixSocketTransportImpl.SocketHelper; import com.redhat.thermostat.agent.ipc.unixsocket.common.internal.ThermostatLocalSocketChannelImpl; import com.redhat.thermostat.agent.ipc.unixsocket.common.internal.UnixSocketIPCProperties; +import com.redhat.thermostat.agent.ipc.unixsocket.common.internal.UserPrincipalUtils; public class UnixSocketTransportImplTest { @@ -65,6 +67,7 @@ private SocketHelper sockHelper; private UnixSocketMessageChannel messageChannel; private UnixSocketIPCProperties props; + private UserPrincipalUtils userUtils; @Before public void setUp() throws Exception { @@ -77,7 +80,10 @@ ThermostatLocalSocketChannelImpl sockChannel = mock(ThermostatLocalSocketChannelImpl.class); when(sockHelper.openSocketChannel(eq(SERVER_NAME), eq(socketFile))).thenReturn(sockChannel); when(sockHelper.createMessageChannel(sockChannel)).thenReturn(messageChannel); - when(sockHelper.getUsername()).thenReturn(USERNAME); + userUtils = mock(UserPrincipalUtils.class); + UserPrincipal currentUser = mock(UserPrincipal.class); + when(currentUser.getName()).thenReturn(USERNAME); + when(userUtils.getCurrentUser()).thenReturn(currentUser); props = mock(UnixSocketIPCProperties.class); when(props.getSocketDirectory()).thenReturn(socketDir); @@ -86,7 +92,7 @@ @Test public void testConnectToServer() throws Exception { - UnixSocketTransportImpl service = new UnixSocketTransportImpl(props, sockHelper); + UnixSocketTransportImpl service = new UnixSocketTransportImpl(props, sockHelper, userUtils); IPCMessageChannel result = service.connect(SERVER_NAME); assertEquals(messageChannel, result); verify(socketDir).exists(); @@ -97,13 +103,13 @@ public void testBadProperties() throws Exception { // Not UnixSocketIPCProperties IPCProperties props = mock(IPCProperties.class); - new UnixSocketTransportImpl(props, sockHelper); + new UnixSocketTransportImpl(props, sockHelper, userUtils); } @Test public void testConnectToServerDirNotExist() throws Exception { when(socketDir.exists()).thenReturn(false); - UnixSocketTransportImpl service = new UnixSocketTransportImpl(props, sockHelper); + UnixSocketTransportImpl service = new UnixSocketTransportImpl(props, sockHelper, userUtils); try { service.connect(SERVER_NAME); @@ -118,7 +124,7 @@ @Test public void testConnectToServerFileNotExist() throws Exception { when(socketFile.exists()).thenReturn(false); - UnixSocketTransportImpl service = new UnixSocketTransportImpl(props, sockHelper); + UnixSocketTransportImpl service = new UnixSocketTransportImpl(props, sockHelper, userUtils); try { service.connect(SERVER_NAME); @@ -133,7 +139,7 @@ @Test public void testConnectToServerBadSocket() throws Exception { when(sockHelper.openSocketChannel(SERVER_NAME, socketFile)).thenThrow(new IOException()); - UnixSocketTransportImpl service = new UnixSocketTransportImpl(props, sockHelper); + UnixSocketTransportImpl service = new UnixSocketTransportImpl(props, sockHelper, userUtils); try { service.connect(SERVER_NAME);
--- a/agent/ipc/unix-socket/common/pom.xml Thu Mar 02 15:00:42 2017 -0500 +++ b/agent/ipc/unix-socket/common/pom.xml Thu Mar 02 17:20:48 2017 -0500 @@ -98,17 +98,6 @@ so we override parent pom's configuration --> <configuration combine.self="override" /> </plugin> - <!-- This is a dependency of the Byteman helper and that needs source - level JDK 6 in order to be able to use the helper for JVMs running - on JDK 6. --> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <configuration> - <source>1.6</source> - <target>1.6</target> - </configuration> - </plugin> </plugins> </build>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/agent/ipc/unix-socket/common/src/main/java/com/redhat/thermostat/agent/ipc/unixsocket/common/internal/UserPrincipalUtils.java Thu Mar 02 17:20:48 2017 -0500 @@ -0,0 +1,103 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.agent.ipc.unixsocket.common.internal; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.UserPrincipal; + +public class UserPrincipalUtils { + + private final SystemHelper helper; + + public UserPrincipalUtils() { + this(new SystemHelper()); + } + + UserPrincipalUtils(SystemHelper helper) { + this.helper = helper; + } + + public UserPrincipal getCurrentUser() throws IOException { + // Use OS means to create a file and determine the owner after. + // This matches what we do in the agent process itself. There is a + // problem otherwise if Thermostat agent runs as user X, but + // the "user.name" property is set to user Y. + UserPrincipal principal = null; + Path fileToTest = null; + String usernameCandidate = helper.getSystemProperty("user.name"); + try { + fileToTest = helper.createTempFile("thermostat_uds", usernameCandidate); + principal = helper.getOwner(fileToTest); + } catch (Exception e) { + throw new IOException("Failed to determine current user via OS. User was: " + usernameCandidate, e); + } finally { + if (fileToTest != null) { + // Clean up temp file once we have the UserPrincipal + helper.deleteFile(fileToTest); + } + } + + if (principal == null) { + throw new IOException("Failed to determine current user via OS. User was: " + usernameCandidate); + } + return principal; + } + + // Helper class for testing static methods that cannot be easily mocked + static class SystemHelper { + + UserPrincipal getOwner(Path fileToTest) throws IOException { + return Files.getOwner(fileToTest); + } + + Path createTempFile(String prefix, String suffix) throws IOException { + return Files.createTempFile(prefix, suffix); + } + + void deleteFile(Path file) throws IOException { + Files.delete(file); + } + + String getSystemProperty(String name) { + return System.getProperty(name); + } + + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/agent/ipc/unix-socket/common/src/test/java/com/redhat/thermostat/agent/ipc/unixsocket/common/internal/UserPrincipalUtilsTest.java Thu Mar 02 17:20:48 2017 -0500 @@ -0,0 +1,121 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.agent.ipc.unixsocket.common.internal; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.attribute.UserPrincipal; + +import org.junit.Before; +import org.junit.Test; + +import com.redhat.thermostat.agent.ipc.unixsocket.common.internal.UserPrincipalUtils.SystemHelper; + +public class UserPrincipalUtilsTest { + + private static final String PROP_USER_NAME = "test"; + + private SystemHelper helper; + private UserPrincipal principal; + private Path tempFilePath; + + private UserPrincipalUtils userUtils; + + @Before + public void setup() throws Exception { + helper = mock(SystemHelper.class); + tempFilePath = mock(Path.class); + principal = mock(UserPrincipal.class); + + when(helper.getSystemProperty("user.name")).thenReturn(PROP_USER_NAME); + when(helper.createTempFile("thermostat_uds", PROP_USER_NAME)).thenReturn(tempFilePath); + when(helper.getOwner(tempFilePath)).thenReturn(principal); + userUtils = new UserPrincipalUtils(helper); + } + + @Test + public void testGetCurrentUser() throws Exception { + UserPrincipal result = userUtils.getCurrentUser(); + + assertEquals(principal, result); + verify(helper).deleteFile(tempFilePath); + } + + @Test + public void testGetCurrentUserCreateFileException() throws Exception { + when(helper.createTempFile(anyString(), anyString())).thenThrow(new IOException("TEST")); + try { + userUtils.getCurrentUser(); + fail("Expected IOException"); + } catch (IOException expected) { + // No file to delete + verify(helper, never()).deleteFile(any(Path.class)); + } + } + + @Test + public void testGetCurrentUserGetOwnerException() throws Exception { + when(helper.getOwner(tempFilePath)).thenThrow(new IOException("TEST")); + try { + userUtils.getCurrentUser(); + fail("Expected IOException"); + } catch (IOException expected) { + verify(helper).deleteFile(any(Path.class)); + } + } + + @Test + public void testGetCurrentUserGetOwnerNull() throws Exception { + when(helper.getOwner(tempFilePath)).thenReturn(null); + try { + userUtils.getCurrentUser(); + fail("Expected IOException"); + } catch (IOException expected) { + verify(helper).deleteFile(any(Path.class)); + } + } + +}
--- a/agent/ipc/unix-socket/server/src/main/java/com/redhat/thermostat/agent/ipc/unixsocket/server/internal/UnixSocketServerTransport.java Thu Mar 02 15:00:42 2017 -0500 +++ b/agent/ipc/unix-socket/server/src/main/java/com/redhat/thermostat/agent/ipc/unixsocket/server/internal/UnixSocketServerTransport.java Thu Mar 02 17:20:48 2017 -0500 @@ -40,7 +40,6 @@ import java.io.IOException; import java.nio.channels.Selector; import java.nio.channels.spi.SelectorProvider; -import java.nio.file.FileSystems; import java.nio.file.FileVisitOption; import java.nio.file.FileVisitResult; import java.nio.file.FileVisitor; @@ -53,7 +52,6 @@ import java.nio.file.attribute.PosixFilePermission; import java.nio.file.attribute.PosixFilePermissions; import java.nio.file.attribute.UserPrincipal; -import java.nio.file.attribute.UserPrincipalLookupService; import java.util.Collections; import java.util.EnumSet; import java.util.HashMap; @@ -72,6 +70,7 @@ import com.redhat.thermostat.agent.ipc.server.ServerTransport; import com.redhat.thermostat.agent.ipc.server.ThermostatIPCCallbacks; import com.redhat.thermostat.agent.ipc.unixsocket.common.internal.UnixSocketIPCProperties; +import com.redhat.thermostat.agent.ipc.unixsocket.common.internal.UserPrincipalUtils; import com.redhat.thermostat.common.utils.LoggingUtils; class UnixSocketServerTransport implements ServerTransport { @@ -108,6 +107,7 @@ private final FileUtils fileUtils; private final ChannelUtils channelUtils; private final ThreadCreator threadCreator; + private final UserPrincipalUtils userUtils; private UnixSocketIPCProperties props; private AcceptThread acceptThread; @@ -117,11 +117,11 @@ UnixSocketServerTransport(SelectorProvider selectorProvider) { this(selectorProvider, Executors.newFixedThreadPool(determineDefaultThreadPoolSize(), new CountingThreadFactory()), - new FilenameValidator(), new FileUtils(), new ThreadCreator(), new ChannelUtils()); + new FilenameValidator(), new FileUtils(), new ThreadCreator(), new ChannelUtils(), new UserPrincipalUtils()); } UnixSocketServerTransport(SelectorProvider selectorProvider, ExecutorService execService, FilenameValidator validator, - FileUtils fileUtils, ThreadCreator threadCreator, ChannelUtils channelCreator) { + FileUtils fileUtils, ThreadCreator threadCreator, ChannelUtils channelCreator, UserPrincipalUtils userUtils) { this.selectorProvider = selectorProvider; this.sockets = new HashMap<>(); this.validator = validator; @@ -129,6 +129,7 @@ this.fileUtils = fileUtils; this.channelUtils = channelCreator; this.threadCreator = threadCreator; + this.userUtils = userUtils; } @Override @@ -140,7 +141,7 @@ this.props = (UnixSocketIPCProperties) props; // Get UserPrincipal for currently logged-in user - this.currentUser = getCurrentUser(); + this.currentUser = userUtils.getCurrentUser(); // Prepare socket directory with strict permissions, which will contain the socket file when bound File sockDirFile = ((UnixSocketIPCProperties) props).getSocketDirectory(); @@ -271,16 +272,6 @@ } } - private UserPrincipal getCurrentUser() throws IOException { - String username = fileUtils.getUsername(); - UserPrincipalLookupService lookup = fileUtils.getUserPrincipalLookupService(); - UserPrincipal principal = lookup.lookupPrincipalByName(username); - if (principal == null) { - throw new IOException("No Principal found for user: " + username); - } - return principal; - } - private void prepareSocketDir(Path path) throws IOException { Path parent = path.getParent(); if (parent != null) { @@ -420,14 +411,6 @@ return Files.walkFileTree(start, options, maxDepth, visitor); } - UserPrincipalLookupService getUserPrincipalLookupService() { - return FileSystems.getDefault().getUserPrincipalLookupService(); - } - - String getUsername() { - return System.getProperty("user.name"); - } - UserPrincipal getOwner(Path path) throws IOException { return Files.getOwner(path); }
--- a/agent/ipc/unix-socket/server/src/test/java/com/redhat/thermostat/agent/ipc/unixsocket/server/internal/UnixSocketServerTransportTest.java Thu Mar 02 15:00:42 2017 -0500 +++ b/agent/ipc/unix-socket/server/src/test/java/com/redhat/thermostat/agent/ipc/unixsocket/server/internal/UnixSocketServerTransportTest.java Thu Mar 02 17:20:48 2017 -0500 @@ -46,9 +46,9 @@ import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.Mockito.times; import java.io.File; import java.io.IOException; @@ -62,7 +62,6 @@ import java.nio.file.attribute.PosixFilePermission; import java.nio.file.attribute.PosixFilePermissions; import java.nio.file.attribute.UserPrincipal; -import java.nio.file.attribute.UserPrincipalLookupService; import java.util.Set; import java.util.concurrent.ExecutorService; @@ -76,6 +75,7 @@ import com.redhat.thermostat.agent.ipc.common.internal.IPCType; import com.redhat.thermostat.agent.ipc.server.ThermostatIPCCallbacks; import com.redhat.thermostat.agent.ipc.unixsocket.common.internal.UnixSocketIPCProperties; +import com.redhat.thermostat.agent.ipc.unixsocket.common.internal.UserPrincipalUtils; import com.redhat.thermostat.agent.ipc.unixsocket.server.internal.UnixSocketServerTransport.ChannelUtils; import com.redhat.thermostat.agent.ipc.unixsocket.server.internal.UnixSocketServerTransport.FileUtils; import com.redhat.thermostat.agent.ipc.unixsocket.server.internal.UnixSocketServerTransport.ThreadCreator; @@ -101,7 +101,7 @@ private ChannelUtils channelUtils; private ThermostatLocalServerSocketChannelImpl channel; private UnixSocketIPCProperties props; - private UserPrincipalLookupService lookup; + private UserPrincipalUtils userUtils; private UserPrincipal currentUser; @SuppressWarnings("unchecked") @@ -133,12 +133,10 @@ fileAttr = mock(FileAttribute.class); when(fileUtils.toFileAttribute(any(Set.class))).thenReturn(fileAttr); - lookup = mock(UserPrincipalLookupService.class); - when(fileUtils.getUserPrincipalLookupService()).thenReturn(lookup); - when(fileUtils.getUsername()).thenReturn(USERNAME); + userUtils = mock(UserPrincipalUtils.class); currentUser = mock(UserPrincipal.class); when(currentUser.getName()).thenReturn(USERNAME); - when(lookup.lookupPrincipalByName(USERNAME)).thenReturn(currentUser); + when(userUtils.getCurrentUser()).thenReturn(currentUser); when(fileUtils.getOwner(socketDirPath)).thenReturn(currentUser); when(fileUtils.getOwner(ownerDirPath)).thenReturn(currentUser); @@ -159,7 +157,7 @@ when(channelUtils.createServerSocketChannel(SERVER_NAME, socketPath, callbacks, props, selector)).thenReturn(channel); transport = new UnixSocketServerTransport(provider, execService, validator, fileUtils, - threadCreator, channelUtils); + threadCreator, channelUtils, userUtils); } @Test @@ -176,7 +174,7 @@ IPCProperties badProps = mock(IPCProperties.class); when(badProps.getType()).thenReturn(IPCType.UNKNOWN); transport = new UnixSocketServerTransport(provider, execService, validator, fileUtils, - threadCreator, channelUtils); + threadCreator, channelUtils, userUtils); transport.start(badProps); } @@ -184,7 +182,7 @@ public void testInitBadPath() throws Exception { when(socketDirPath.normalize()).thenThrow(new InvalidPathException("TEST", "TEST")); transport = new UnixSocketServerTransport(provider, execService, validator, fileUtils, - threadCreator, channelUtils); + threadCreator, channelUtils, userUtils); transport.start(props); } @@ -279,12 +277,6 @@ transport.start(props); } - @Test(expected=IOException.class) - public void testStartOwnerCheckNullLookup() throws Exception { - when(lookup.lookupPrincipalByName(USERNAME)).thenReturn(null); - transport.start(props); - } - @Test public void testStartFailsBadPerm() throws Exception { when(fileUtils.exists(socketDirPath)).thenReturn(true);
--- a/vm-byteman/byteman-helper/pom.xml Thu Mar 02 15:00:42 2017 -0500 +++ b/vm-byteman/byteman-helper/pom.xml Thu Mar 02 17:20:48 2017 -0500 @@ -51,14 +51,6 @@ <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <configuration> - <source>1.6</source> - <target>1.6</target> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <configuration> <shadedArtifactAttached>true</shadedArtifactAttached>