brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahgittin <...@git.apache.org>
Subject [GitHub] incubator-brooklyn pull request: Jclouds tidy
Date Mon, 26 Jan 2015 12:19:29 GMT
Github user ahgittin commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/465#discussion_r23526262
  
    --- Diff: core/src/test/java/brooklyn/location/basic/LocationConfigUtilsTest.java ---
    @@ -21,77 +21,134 @@
     import static org.testng.Assert.assertEquals;
     import static org.testng.Assert.assertTrue;
     
    +import org.testng.Assert;
     import org.testng.annotations.Test;
     
    +import brooklyn.location.basic.LocationConfigUtils.OsCredential;
     import brooklyn.util.config.ConfigBag;
     
    +@Test
     public class LocationConfigUtilsTest {
     
    -    public static final String SSH_PRIVATE_KEY_FILE = System.getProperty("sshPrivateKey",
"~/.ssh/id_rsa");
    -    public static final String SSH_PUBLIC_KEY_FILE = System.getProperty("sshPrivateKey",
"~/.ssh/id_rsa.pub");
    +    // set these system properties differently if needed to fix your tests
    +    public static final String SSH_PRIVATE_KEY_FILE_WITH_TILDE = System.getProperty("sshPrivateKey",
"~/.ssh/id_rsa");
    +    public static final String SSH_PUBLIC_KEY_FILE_WITH_TILDE = System.getProperty("sshPublicKey",
"~/.ssh/id_rsa.pub");
    +    // these should work as they are on classpath
    +    public static final String SSH_PRIVATE_KEY_FILE_WITH_PASSPHRASE = System.getProperty("sshPrivateKeyWithPassphrase",
"/brooklyn/util/crypto/sample_rsa_passphrase.pem");
    +    public static final String SSH_PRIVATE_KEY_FILE = System.getProperty("sshPrivateKeySample",
"/brooklyn/location/basic/sample_id_rsa");
    +    public static final String SSH_PUBLIC_KEY_FILE = System.getProperty("sshPublicKeySample",
"/brooklyn/location/basic/sample_id_rsa.pub");
         
    -    @Test(groups="Integration")
         public void testPreferPrivateKeyDataOverFile() throws Exception {
             ConfigBag config = ConfigBag.newInstance();
             config.put(LocationConfigKeys.PRIVATE_KEY_DATA, "mydata");
             config.put(LocationConfigKeys.PRIVATE_KEY_FILE, SSH_PRIVATE_KEY_FILE);
             
    -        String data = LocationConfigUtils.getPrivateKeyData(config);
    +        OsCredential creds = LocationConfigUtils.getOsCredential(config).doKeyValidation(false);
    +        Assert.assertTrue(creds.hasKey());
    +        // warnings, as it is malformed
    +        Assert.assertFalse(creds.getWarningMessages().isEmpty());
    +
    +        String data = creds.getPrivateKeyData();
             assertEquals(data, "mydata");
         }
    -    
    -    @Test(groups="Integration")
    -    public void testPreferPubilcKeyDataOverFile() throws Exception {
    +
    +    @Test(expectedExceptions=IllegalStateException.class)
    +    public void testInvalidKeyData() throws Exception {
    +        ConfigBag config = ConfigBag.newInstance();
    +        config.put(LocationConfigKeys.PRIVATE_KEY_DATA, "mydata");
    +        
    +        OsCredential creds = LocationConfigUtils.getOsCredential(config).doKeyValidation(false);
    +        Assert.assertTrue(creds.hasKey());
    +        Assert.assertFalse(creds.getWarningMessages().isEmpty());
    +        
    +        creds.checkNoErrors();
    +    }
    +
    +    public void testPreferPublicKeyDataOverFileAndNoPrivateKeyRequired() throws Exception
{
             ConfigBag config = ConfigBag.newInstance();
             config.put(LocationConfigKeys.PUBLIC_KEY_DATA, "mydata");
             config.put(LocationConfigKeys.PUBLIC_KEY_FILE, SSH_PUBLIC_KEY_FILE);
    +        config.put(LocationConfigKeys.PRIVATE_KEY_FILE, "");
             
    -        String data = LocationConfigUtils.getPublicKeyData(config);
    +        OsCredential creds = LocationConfigUtils.getOsCredential(config);
    +        String data = creds.getPublicKeyData();
             assertEquals(data, "mydata");
    +        Assert.assertNull(creds.get());
    +        Assert.assertFalse(creds.hasPassword());
    +        Assert.assertFalse(creds.hasKey());
    +        // and not even any warnings here
    +        Assert.assertTrue(creds.getWarningMessages().isEmpty());
         }
         
    -    @Test(groups="Integration")
    -    public void testReadsPrivateKeyFileWithTildaPath() throws Exception {
    +    @Test(groups="Integration")  // requires ~/.ssh/id_rsa
    +    public void testReadsPrivateKeyFileWithTildePath() throws Exception {
             ConfigBag config = ConfigBag.newInstance();
    -        config.put(LocationConfigKeys.PRIVATE_KEY_FILE, SSH_PRIVATE_KEY_FILE);
    -        
    -        String data = LocationConfigUtils.getPrivateKeyData(config);
    +        config.put(LocationConfigKeys.PRIVATE_KEY_FILE, SSH_PRIVATE_KEY_FILE_WITH_TILDE);
    +
    +        // don't mind if it has a passphrase
    +        String data = LocationConfigUtils.getOsCredential(config).doKeyValidation(false).get();
             assertTrue(data != null && data.length() > 0);
         }
         
    -    @Test(groups="Integration")
    +    @Test(groups="Integration")  // requires ~/.ssh/passphrase-id_rsa
    --- End diff --
    
    comment was wrong, it uses a key that is added to classpath


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message