DataLoader { public void load(InputStream inputStream) { final Yaml yaml = new Yaml(); final Object load = yaml.load(inputStream); if (areOnlySecrets(load)) { final List<Map<String, Map<String, Object>>> secrets = (List) load; insertTokens(secrets); insertSecrets(secrets); } } DataLoader(VaultConnection vault); void load(InputStream inputStream);  }
@Test public void should_read_simple_secrets_definition() throws FileNotFoundException, VaultException { final DataLoader dataLoader = new DataLoader(vaultConnection); dataLoader.load(new FileInputStream("src/test/resources/only_secrets.yml")); final Map<String, Object> fooSecret = new HashMap<>(); fooSecret.put("zip", "zap"); fooSecret.put("a", "b"); final Map<String, Object> barSecret = new HashMap<>(); barSecret.put("zap", "zip"); barSecret.put("b", "a"); verify(vaultConnection).writeLogical("secret/foo", fooSecret); verify(vaultConnection).writeLogical("secret/bar", barSecret); }
@Test public void should_insert_tokens() throws FileNotFoundException, VaultException { when(vaultConnection.createToken()).thenReturn(new VaultConnection.TokenCreator(vault)); when(vault.auth()).thenReturn(auth); when(response.getAuthClientToken()).thenReturn("aa-bb-cc-dd"); when(auth.createToken(anyObject(), anyObject(), anyObject(), anyObject(), anyObject(), anyObject(), anyObject(), anyObject())) .thenReturn(response); final DataLoader dataLoader = new DataLoader(vaultConnection); dataLoader.load(new FileInputStream("src/test/resources/tokens_and_secrets.yml")); verify(vaultConnection, times(2)).createToken(); verify(vaultConnection, times(2)).updateToken("aa-bb-cc-dd"); verify(vaultConnection, times(2)).reconnectToOriginal(); final Map<String, Object> fooSecret = new HashMap<>(); fooSecret.put("zip", "zap"); fooSecret.put("a", "b"); verify(vaultConnection).writeLogical("secret/foo", fooSecret); verify(vaultConnection).writeLogical("secret/bar", fooSecret); }