@BeforeClass
  public static void beforeClass() throws Exception {

    VaultRule vaultRule = new VaultRule();
    vaultRule.before();

    assumeTrue(vaultRule.prepare().getVersion().isGreaterThanOrEqualTo(Version.parse("0.6.1")));

    VaultProperties vaultProperties = Settings.createVaultProperties();

    if (!vaultRule.prepare().hasAuth(vaultProperties.getAppRole().getAppRolePath())) {
      vaultRule.prepare().mountAuth(vaultProperties.getAppRole().getAppRolePath());
    }

    VaultOperations vaultOperations = vaultRule.prepare().getVaultOperations();

    String rules =
        "{ \"name\": \"testpolicy\",\n" //
            + "  \"path\": {\n" //
            + "    \"*\": {  \"policy\": \"read\" }\n" //
            + "  }\n" //
            + "}";

    vaultOperations.write("sys/policy/testpolicy", Collections.singletonMap("rules", rules));

    String appId = VaultConfigAppRoleTests.class.getSimpleName();

    vaultOperations.write(
        "secret/" + VaultConfigAppRoleTests.class.getSimpleName(),
        Collections.singletonMap("vault.value", "foo"));

    Map<String, String> withSecretId = new HashMap<String, String>();
    withSecretId.put("policies", "testpolicy"); // policy
    withSecretId.put("bound_cidr_list", "0.0.0.0/0");
    withSecretId.put("bind_secret_id", "true");

    vaultOperations.write("auth/approle/role/with-secret-id", withSecretId);

    String roleId =
        (String)
            vaultOperations
                .read("auth/approle/role/with-secret-id/role-id")
                .getData()
                .get("role_id");
    String secretId =
        (String)
            vaultOperations
                .write(
                    String.format("auth/approle/role/with-secret-id/secret-id", "with-secret-id"),
                    null)
                .getData()
                .get("secret_id");

    System.setProperty("spring.cloud.vault.app-role.role-id", roleId);
    System.setProperty("spring.cloud.vault.app-role.secret-id", secretId);
  }
Ejemplo n.º 2
0
 @Test
 public void testRemoteClient() throws Exception {
   assumeTrue(
       "Test requires a Spark installation in SPARK_HOME.", System.getenv("SPARK_HOME") != null);
   runTest(
       false,
       new TestFunction() {
         @Override
         public void call(LivyClient client) throws Exception {
           JobHandle<Long> handle = client.submit(new SparkJob());
           assertEquals(Long.valueOf(5L), handle.get(TIMEOUT, TimeUnit.SECONDS));
         }
       });
 }
Ejemplo n.º 3
0
  private Properties createConf(boolean local) {
    Properties conf = new Properties();
    if (local) {
      conf.put(CLIENT_IN_PROCESS.key, "true");
      conf.put("spark.master", "local");
      conf.put("spark.app.name", "SparkClientSuite Local App");
    } else {
      String classpath = System.getProperty("java.class.path");
      conf.put("spark.master", "local");
      conf.put("spark.app.name", "SparkClientSuite Remote App");
      conf.put("spark.driver.extraClassPath", classpath);
      conf.put("spark.executor.extraClassPath", classpath);
      conf.put(LIVY_JARS.key, "");
    }

    return conf;
  }
Ejemplo n.º 4
0
 protected static void checkRunTurtleTests() {
   assumeTrue(ObjectUtils.equals("true", System.getProperty("runTurtleTests")));
 }