use of com.walmartlabs.concord.sdk.MockContext in project concord-plugins by walmartlabs.
the class PuppetTaskTest method test503.
/**
* 503 errors are retried. The resulting exception will be due to retry max
* being reached, not the 503 error itself.
*/
@Test
public void test503() {
stubFor503();
MockContext ctx = new MockContext(buildDbQueryConfig());
UtilsTest.injectVariable(task, "action", "pql");
ctx.setVariable("queryString", "inventory[certname]{ limit 10 }");
try {
task.execute(ctx);
throw new Exception("No exception was thrown in task.");
} catch (ApiException expected) {
assertTrue(expected.getMessage().contains("Retry max reached"));
} catch (Exception e) {
fail("404 error should cause API exception");
}
}
use of com.walmartlabs.concord.sdk.MockContext in project concord-plugins by walmartlabs.
the class PuppetTaskTest method testTokenCreateAllParams.
@Test
public void testTokenCreateAllParams() throws Exception {
MockContext ctx = new MockContext(buildRbacCfg());
UtilsTest.injectVariable(task, "action", "createApiToken");
ctx.setVariable("tokenDescription", "token description");
ctx.setVariable("tokenLabel", "token label");
ctx.setVariable("tokenLife", "5h");
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 PuppetTaskTest method testTokenPayload.
@Test
public void testTokenPayload() throws Exception {
MockContext ctx = new MockContext(buildRbacCfg());
ctx.setVariable("tokenDescription", "token description");
ctx.setVariable("tokenLabel", "token label");
ctx.setVariable("tokenLife", "5h");
RbacCfg cfg = Utils.createCfg(ctx, secretService, ctx.toMap(), RbacCfg.class);
TokenPayload payload = new TokenPayload(cfg);
assertEquals("token description", payload.getDescription());
assertEquals("token label", payload.getLabel());
assertEquals("5h", payload.getLifetime());
}
use of com.walmartlabs.concord.sdk.MockContext in project concord-plugins by walmartlabs.
the class PuppetTaskTest method testBadUrl.
@Test
public void testBadUrl() {
MockContext ctx = new MockContext(buildDbQueryConfig());
UtilsTest.injectVariable(task, "action", "pql");
ctx.setVariable("queryString", "inventory[certname]{ limit 10 }");
// Empty URL
ctx.setVariable("databaseUrl", "");
try {
task.execute(ctx);
fail("Bad url should cause an exception");
} catch (MissingParameterException expected) {
assert (expected.getMessage().contains("Cannot find value for databaseUrl"));
} catch (Exception e) {
fail("Unexpected exception with bad URL: " + e.getMessage());
}
// Invalid URL
ctx.setVariable("databaseUrl", "notaurl");
try {
task.execute(ctx);
fail("Bad url should cause an exception");
} catch (IllegalArgumentException expected) {
assert (expected.getMessage().contains("Invalid URL"));
} catch (Exception e) {
fail("Unexpected exception with bad URL: " + e.getMessage());
}
}
use of com.walmartlabs.concord.sdk.MockContext in project concord-plugins by walmartlabs.
the class PuppetTaskTest method testNoCertValidation.
@Test
public void testNoCertValidation() 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;
}
ctx.setVariable(Constants.Keys.VALIDATE_CERTS_KEY, false);
// 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());
}
Aggregations