use of com.walmartlabs.concord.sdk.MockContext in project concord-plugins by walmartlabs.
the class PuppetTaskTest method testSelfSignedCertWithSecret.
@Test
public void testSelfSignedCertWithSecret() throws Exception {
MockContext ctx = new MockContext(buildDbQueryConfig());
UtilsTest.injectVariable(task, "action", "pql");
ctx.setVariable("queryString", "inventory[certname]{ limit 10 }");
ctx.setVariable(Constants.Keys.DATABASE_URL_KEY, httpsRule.baseUrl());
// Self-signed cert will fail unless we provide a cert to trust
try {
task.execute(ctx);
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;
}
Map<String, Object> certificate = new HashMap<>();
Map<String, Object> secret = new HashMap<>();
secret.put(Constants.Keys.CERTIFICATE_ORG_KEY, "org");
secret.put(Constants.Keys.CERTIFICATE_NAME_KEY, "name");
secret.put(Constants.Keys.CERTIFICATE_PASSWORD_KEY, null);
certificate.put("secret", secret);
ctx.setVariable("certificate", certificate);
// now it should work
task.execute(ctx);
Map result = (Map) ctx.getVariable("result");
assertNotNull(result);
assertTrue((boolean) result.get("ok"));
List data = (List) result.get("data");
assertEquals(10, data.size());
}
use of com.walmartlabs.concord.sdk.MockContext in project concord-plugins by walmartlabs.
the class PuppetTaskTest method testQuery.
@Test
public void testQuery() throws Exception {
MockContext ctx = new MockContext(buildDbQueryConfig());
UtilsTest.injectVariable(task, "action", "pql");
ctx.setVariable("queryString", "inventory[certname]{ limit 10 }");
task.execute(ctx);
Map result = (Map) ctx.getVariable("result");
assertNotNull(result);
assertTrue((boolean) result.get("ok"));
List data = (List) result.get("data");
assertEquals(10, data.size());
}
use of com.walmartlabs.concord.sdk.MockContext in project concord-plugins by walmartlabs.
the class PuppetTaskTest method testSelfSignedCertWithText.
@Test
public void testSelfSignedCertWithText() throws Exception {
MockContext ctx = new MockContext(buildDbQueryConfig());
UtilsTest.injectVariable(task, "action", "pql");
ctx.setVariable("queryString", "inventory[certname]{ limit 10 }");
ctx.setVariable(Constants.Keys.DATABASE_URL_KEY, httpsRule.baseUrl());
// Self-signed cert will fail unless we provide a cert to trust
try {
task.execute(ctx);
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;
}
Map<String, Object> certificate = new HashMap<>();
certificate.put("text", getWiremockCertString());
ctx.setVariable("certificate", certificate);
// now it should work
task.execute(ctx);
Map result = (Map) ctx.getVariable("result");
assertNotNull(result);
assertTrue((boolean) result.get("ok"));
List data = (List) result.get("data");
assertEquals(10, data.size());
}
use of com.walmartlabs.concord.sdk.MockContext in project concord-plugins by walmartlabs.
the class PuppetTaskTest method testTokenCreate.
@Test
public void testTokenCreate() throws Exception {
MockContext ctx = new MockContext(buildRbacCfg());
UtilsTest.injectVariable(task, "action", "createApiToken");
task.execute(ctx);
Map result = (Map) ctx.getVariable("result");
assertTrue((Boolean) result.get("ok"));
String token = (String) result.get("data");
assertNotNull(token);
}
use of com.walmartlabs.concord.sdk.MockContext in project concord-plugins by walmartlabs.
the class S3TaskTest method test.
@Test
@SuppressWarnings("unchecked")
public void test() throws Exception {
String data = "Hello!";
Path p = Files.createTempFile("test", ".txt");
Files.write(p, data.getBytes());
Map<String, Object> auth = new HashMap<>();
auth.put("accessKey", System.getenv("AWS_ACCESS_KEY"));
auth.put("secretKey", System.getenv("AWS_SECRET_KEY"));
Map<String, Object> args = new HashMap<>();
args.put(com.walmartlabs.concord.sdk.Constants.Context.WORK_DIR_KEY, p.getParent().toAbsolutePath().toString());
args.put(ACTION_KEY, TaskParams.Action.PUTOBJECT.name());
args.put(PutObjectParams.BUCKET_NAME_KEY, "ibodrov-test");
args.put(PutObjectParams.OBJECT_KEY, "xyz");
args.put(PutObjectParams.SRC_KEY, p.getFileName().toString());
args.put(PutObjectParams.ENDPOINT_KEY, System.getenv("AWS_ENDPOINT"));
args.put(PutObjectParams.REGION_KEY, System.getenv("AWS_REGION"));
args.put(PutObjectParams.PATH_STYLE_ACCESS_KEY, true);
args.put(PutObjectParams.AUTH_KEY, Collections.singletonMap("basic", auth));
MockContext ctx = new MockContext(args);
Task t = new S3Task();
t.execute(ctx);
Map<String, Object> r = (Map<String, Object>) ctx.getVariable(Constants.RESULT_KEY);
assertTrue((Boolean) r.get("ok"));
// ---
args.put(Constants.ACTION_KEY, TaskParams.Action.GETOBJECT.name());
ctx = new MockContext(args);
t.execute(ctx);
r = (Map<String, Object>) ctx.getVariable(Constants.RESULT_KEY);
assertTrue((Boolean) r.get("ok"));
String storedObject = (String) r.get("path");
String s = new String(Files.readAllBytes(p.getParent().resolve(storedObject)));
assertEquals(data, s);
}
Aggregations