@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); }
@Test public void systemProperty() throws IOException { System.setProperty("p1", "sys"); PropertiesLoader pl = new PropertiesLoader("classpath:/test1.properties", "classpath:/test2.properties"); assertThat(pl.getProperty("p1")).isEqualTo("sys"); System.clearProperty("p1"); }