Cubbyhole { public Map<String, String> getUsernameAndPassword(String tempToken) { this.vaultConfig.token(tempToken); Vault vault = new Vault(this.vaultConfig); try { final Map<String, String> data = vault.logical().read("cubbyhole/" + cubbyholeName).getData(); final String permToken = data.get("permtoken"); this.vaultConfig.token(permToken); vault = new Vault(this.vaultConfig); return vault.logical().read("secret/bar").getData(); } catch (VaultException e) { throw new RuntimeException(e); } } Cubbyhole(VaultConfig vaultConfig, String cubbyholeName); Map<String, String> getUsernameAndPassword(String tempToken);  }
@Test @UsingDataSet(locations = "cubbyhole-setup.yml", loadStrategy = LoadStrategyEnum.INSERT) public void should_get_username_password_in_secured_way() { VaultConfig vaultConfig = new VaultConfig(); vaultConfig.address("http: Cubbyhole cubbyhole = new Cubbyhole(vaultConfig, "temp"); final Map<String, String> usernameAndPassword = cubbyhole.getUsernameAndPassword(tempToken); assertThat(usernameAndPassword.get("username"), CoreMatchers.is("ada")); assertThat(usernameAndPassword.get("password"), CoreMatchers.is("alexandra")); }