[ https://issues.apache.org/jira/browse/BROOKLYN-405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15712282#comment-15712282 ]
ASF GitHub Bot commented on BROOKLYN-405: ----------------------------------------- Github user grkvlt commented on a diff in the pull request: https://github.com/apache/brooklyn-server/pull/475#discussion_r90471366 --- Diff: core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationIntegrationTest.java --- @@ -19,53 +19,206 @@ package org.apache.brooklyn.location.ssh; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.OutputStream; +import java.net.InetAddress; import java.security.KeyPair; import java.util.Arrays; import java.util.Map; +import java.util.concurrent.Callable; import org.apache.brooklyn.api.location.Location; import org.apache.brooklyn.api.location.LocationSpec; -import org.apache.brooklyn.api.mgmt.ManagementContext; -import org.apache.brooklyn.core.entity.Entities; -import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests; -import org.apache.brooklyn.core.test.entity.TestApplication; +import org.apache.brooklyn.api.location.MachineDetails; +import org.apache.brooklyn.core.entity.AbstractEntity; +import org.apache.brooklyn.core.internal.BrooklynProperties; import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation; +import org.apache.brooklyn.test.Asserts; import org.apache.brooklyn.util.collections.MutableMap; import org.apache.brooklyn.util.core.crypto.SecureKeys; +import org.apache.brooklyn.util.core.file.ArchiveUtils; +import org.apache.brooklyn.util.core.internal.ssh.SshException; import org.apache.brooklyn.util.core.internal.ssh.SshTool; import org.apache.brooklyn.util.core.internal.ssh.sshj.SshjTool; import org.apache.brooklyn.util.core.internal.ssh.sshj.SshjTool.SshjToolBuilder; +import org.apache.brooklyn.util.core.task.BasicExecutionContext; +import org.apache.brooklyn.util.core.task.BasicExecutionManager; import org.apache.brooklyn.util.guava.Maybe; +import org.apache.brooklyn.util.net.Networking; +import org.apache.brooklyn.util.net.Urls; +import org.apache.brooklyn.util.os.Os; +import org.apache.brooklyn.util.stream.Streams; +import org.apache.brooklyn.util.time.Duration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import com.google.common.base.Charsets; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.common.io.Files; -public class SshMachineLocationIntegrationTest { +public class SshMachineLocationIntegrationTest extends SshMachineLocationTest { - protected TestApplication app; - protected ManagementContext mgmt; + private static final Logger LOG = LoggerFactory.getLogger(AbstractEntity.class); - @BeforeMethod(alwaysRun=true) - public void setup() throws Exception { - mgmt = LocalManagementContextForTests.builder(true) - .useDefaultProperties() - .build(); - app = TestApplication.Factory.newManagedInstanceForTests(mgmt); + @Override + protected BrooklynProperties getBrooklynProperties() { + // Requires location named "localhost-passphrase", which it expects to find in local + // brooklyn.properties (or brooklyn.cfg in karaf). + return BrooklynProperties.Factory.newDefault(); + } + + @Override + protected SshMachineLocation newHost() { + return mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class) + .configure("address", Networking.getLocalHost())); } - @AfterMethod(alwaysRun=true) - public void tearDown() throws Exception { - if (mgmt != null) Entities.destroyAll(mgmt); - mgmt = null; + // Overridden just to make it integration (because `newHost()` returns a real ssh'ing host) + @Test(groups="Integration") + @Override + public void testSshExecScript() throws Exception { + super.testSshExecScript(); + } + + // Overridden just to make it integration (because `newHost()` returns a real ssh'ing host) + @Test(groups="Integration") + @Override + public void testSshExecCommands() throws Exception { + super.testSshExecCommands(); + } + + // Overridden just to make it integration (because `newHost()` returns a real ssh'ing host) + @Test(groups="Integration") + @Override + public void testIsSshableWhenTrue() throws Exception { + super.testIsSshableWhenTrue(); + } + + // Overridden just to make it integration (because `newHost()` returns a real ssh'ing host) + @Test(groups="Integration") + @Override + public void testDoesNotLogPasswordsInEnvironmentVariables() { + super.testDoesNotLogPasswordsInEnvironmentVariables(); + } + + // Overrides super, because expect real machine details (rather than asserting our stub data) + @Test(groups = "Integration") + @Override + public void testGetMachineDetails() throws Exception { + BasicExecutionManager execManager = new BasicExecutionManager("mycontextid"); + BasicExecutionContext execContext = new BasicExecutionContext(execManager); + try { + MachineDetails details = execContext.submit(new Callable<MachineDetails>() { + public MachineDetails call() { + return host.getMachineDetails(); + }}).get(); + LOG.info("machineDetails="+details); + assertNotNull(details); + } finally { + execManager.shutdownNow(); + } + } + + @Test(groups = "Integration") + public void testCopyFileTo() throws Exception { + File dest = Os.newTempFile(getClass(), ".dest.tmp"); + File src = Os.newTempFile(getClass(), ".src.tmp"); + try { + Files.write("abc", src, Charsets.UTF_8); + host.copyTo(src, dest); + assertEquals("abc", Files.readFirstLine(dest, Charsets.UTF_8)); + } finally { + src.delete(); + dest.delete(); + } + } + + // Note: requires `ssh localhost` to be setup such that no password is required + @Test(groups = "Integration") + public void testCopyStreamTo() throws Exception { + String contents = "abc"; + File dest = new File(Os.tmp(), "sshMachineLocationTest_dest.tmp"); + try { + host.copyTo(Streams.newInputStreamWithContents(contents), dest.getAbsolutePath()); + assertEquals("abc", Files.readFirstLine(dest, Charsets.UTF_8)); + } finally { + dest.delete(); + } } + // Requires internet connectivity; on guest wifi etc can fail with things like + // "Welcome to Virgin Trains" etc. + @Test(groups = "Integration") + public void testInstallUrlTo() throws Exception { + File dest = new File(Os.tmp(), "sshMachineLocationTest_dir/"); + dest.mkdir(); + try { + int result = host.installTo("https://raw.github.com/brooklyncentral/brooklyn/master/README.md", Urls.mergePaths(dest.getAbsolutePath(), "README.md")); + assertEquals(result, 0); + String contents = ArchiveUtils.readFullyString(new File(dest, "README.md")); + assertTrue(contents.contains("http://brooklyncentral.github.com"), "contents missing expected phrase; contains:\n"+contents); + } finally { + dest.delete(); + } + } + + @Test(groups = "Integration") + public void testInstallClasspathCopyTo() throws Exception { + File dest = new File(Os.tmp(), "sshMachineLocationTest_dir/"); + dest.mkdir(); + try { + int result = host.installTo("classpath://brooklyn/config/sample.properties", Urls.mergePaths(dest.getAbsolutePath(), "sample.properties")); + assertEquals(result, 0); + String contents = ArchiveUtils.readFullyString(new File(dest, "sample.properties")); + assertTrue(contents.contains("Property 1"), "contents missing expected phrase; contains:\n"+contents); + } finally { + dest.delete(); + } + } + + // Note: on some (home/airport) networks, `ssh 123.123.123.123` hangs seemingly forever. + // Make sure we fail, waiting for longer than the 70 second TCP timeout. + // + // Times out in 2m7s on Ubuntu Vivid (syn retries set to 6) + @Test(groups = "Integration") + public void testIsSshableWhenFalse() throws Exception { + byte[] unreachableIp = new byte[] {123,123,123,123}; --- End diff -- From http://superuser.com/questions/698244/ip-address-that-is-the-equivalent-of-dev-null > There's specifically a blackhole prefix in IPV6, as described in RFC 6666, it's 100::/64. IP4 does not have an explicit black hole like that, but a non-existent host on one of the reserved blocks would have that effect. (e.g., 240.0.0.0/4 is "reserved for future use" and will not be routed by anything.) > Passwords in environment variables logged by brooklyn.SSH debug > --------------------------------------------------------------- > > Key: BROOKLYN-405 > URL: https://issues.apache.org/jira/browse/BROOKLYN-405 > Project: Brooklyn > Issue Type: Bug > Reporter: Aled Sage > > In Brooklyn 0.10.0-SNAPSHOT > Passwords that are set in {{shell.env}} (and thus passed into > {{check-running}} etc) are being logged in plain-text. > Admittedly I'm not using an external credential store, but I suspect that > even if I was then this would still happen. > We should be calling {{Sanitizer.sanitize(env)}} for our logging. > {noformat} > 2016-11-30 11:25:43,520 DEBUG 117 b.SSH [ger-Lh7ezXs6-213] check-running > VanillaSoftwareProcessImpl{id=enztuvtelc}, initiating ssh on machine > SshMachineLocation[10.104.0.67:amp@10.104.0.67/10.104.0.67:22(id=l409fq0xsa)] > (env {ADMIN_PASSWORD=GoXcLbqo6Oxg, DB_USER=micro-user, ADMIN_USER=admin, DB_UR > L=mysql://10.104.0.68:3306/, DB_PASSWORD=tZdPPP9tBSfRTrt, > HOST_ADDRESS=10.104.0.67, > PID_FILE=/home/users/amp/brooklyn-managed-processes/apps/bv6tlh58aw/entities/VanillaSoftwareProcess_enztuvtelc/pid.txt}): > #!/bin/bash -e > ; export > INSTALL_DIR="/home/users/amp/brooklyn-managed-processes/installs/VanillaSoftwareProcess_0.0.0_bFlJaB" > ; export > RUN_DIR="/home/users/amp/brooklyn-managed-processes/apps/bv6tlh58aw/entities/VanillaSoftwareProcess_enztuvtelc" > ; mkdir -p $RUN_DIR ; cd $RUN_DIR ; counter=`wget -T 15 -q -O- ${ > HOST_ADDRESS}:8080/health --http-user=${ADMIN_USER} > --http-password=${ADMIN_PASSWORD} | grep -c "status.:.UP"` > if [ $counter -eq 0 ]; then > exit 1; > fi > {noformat} -- This message was sent by Atlassian JIRA (v6.3.4#6332)