Search in sources :

Example 21 with Task

use of com.walmartlabs.concord.runtime.v2.sdk.Task in project concord-plugins by walmartlabs.

the class PuppetTaskV2Test method testSelfSignedCertWithSecret.

@Test
public void testSelfSignedCertWithSecret() throws Exception {
    // -- Task in-vars
    variables.put("action", "pql");
    variables.put("queryString", "inventory[certname]{ limit 10 }");
    variables.put("databaseUrl", httpsRule.baseUrl());
    // Self-signed cert will fail unless we provide a cert to trust
    try {
        task.execute(input);
        fail("Task should fail when self-signed cert is used without a provided certificate to trust.");
    } catch (SSLHandshakeException expected) {
        // that's fine
        log.info("hit expected ssl exception. Not a problem");
    } catch (Exception e) {
        log.error(e.getMessage());
        throw e;
    }
    // -- Task in-vars - add certificate info (secret)
    Map<String, Object> certificate = new HashMap<>();
    Map<String, Object> secret = new HashMap<>();
    secret.put("org", "org");
    secret.put("name", "name");
    secret.put("password", null);
    certificate.put("secret", secret);
    variables.put("certificate", certificate);
    // -- Execute - now it should work
    TaskResult.SimpleResult result = task.execute(input);
    assertNotNull(result);
    assertTrue(result.ok());
    List data = (List) result.values().get("data");
    assertEquals(10, data.size());
}
Also used : HashMap(java.util.HashMap) TaskResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult) List(java.util.List) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) MissingParameterException(com.walmartlabs.concord.plugins.puppet.model.exception.MissingParameterException) Test(org.junit.Test)

Example 22 with Task

use of com.walmartlabs.concord.runtime.v2.sdk.Task in project concord-plugins by walmartlabs.

the class PuppetTaskV2Test method testSelfSignedCertWithPath.

@Test
public void testSelfSignedCertWithPath() throws Exception {
    // -- Task in-vars
    variables.put("action", "pql");
    variables.put("queryString", "inventory[certname]{ limit 10 }");
    variables.put("databaseUrl", httpsRule.baseUrl());
    // Self-signed cert will fail unless we provide a cert to trust
    try {
        task.execute(input);
        throw new Exception("Task should fail when self-signed cert is used without a provided certificate to trust.");
    } catch (SSLHandshakeException expected) {
        // that's fine
        log.info("hit expected ssl exception. Not a problem");
    } catch (Exception e) {
        log.error(e.getMessage());
        throw e;
    }
    // -- Task in-vars - add certificate info (file path)
    Map<String, Object> certificate = new HashMap<>();
    certificate.put("path", getWiremockCertFile().toString());
    variables.put("certificate", certificate);
    // -- Execute - now it should work
    TaskResult.SimpleResult result = task.execute(input);
    assertNotNull(result);
    assertTrue(result.ok());
    List data = (List) result.values().get("data");
    assertEquals(10, data.size());
}
Also used : HashMap(java.util.HashMap) TaskResult(com.walmartlabs.concord.runtime.v2.sdk.TaskResult) List(java.util.List) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) MissingParameterException(com.walmartlabs.concord.plugins.puppet.model.exception.MissingParameterException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) Test(org.junit.Test)

Aggregations

TaskResult (com.walmartlabs.concord.runtime.v2.sdk.TaskResult)7 Test (org.junit.Test)7 TaskProviders (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders)6 HashMap (java.util.HashMap)5 List (java.util.List)5 MissingParameterException (com.walmartlabs.concord.plugins.puppet.model.exception.MissingParameterException)4 MapBackedVariables (com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables)4 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)4 Step (com.walmartlabs.concord.runtime.v2.model.Step)3 TaskCallInterceptor (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Test (org.junit.jupiter.api.Test)3 TaskCall (com.walmartlabs.concord.runtime.v2.model.TaskCall)2 TaskCallOptions (com.walmartlabs.concord.runtime.v2.model.TaskCallOptions)2 CallContext (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor.CallContext)2 TaskException (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskException)2 Task (com.walmartlabs.concord.runtime.v2.sdk.Task)2 Variables (com.walmartlabs.concord.runtime.v2.sdk.Variables)2 Frame (com.walmartlabs.concord.svm.Frame)2 AbstractModule (com.google.inject.AbstractModule)1