Provisioner { List<ProvisionPlaintext> extractProvisionsPlaintext(List<File> files) { List<ProvisionPlaintext> result = new ArrayList<>(); if (files != null) { for (File file : files) { ProvisionPlaintext plain = new ProvisionPlaintext(); plain.setProvisionPath(file.getAbsolutePath()); ZipInputStream in = null; try { in = new ZipInputStream(new FileInputStream(file)); ZipEntry zipEntry; while ((zipEntry = in.getNextEntry()) != null) { String name = zipEntry.getName(); if ("repo_provision.json".equals(name)) { if (plain.getRepositoryProvision() != null) { throw new IOException("provision malformed: contains more than one repo provision file."); } plain.setRepositoryProvision(IOUtils.toString(in, Charset.forName("UTF-8"))); } else if ("repo_provision.ojson".equals(name)) { if (plain.getRepositoryProvision() != null) { throw new IOException("provision malformed: contains more than one repo provision file."); } plain.setRepositoryProvision(deobfuscate(IOUtils.toString(in, Charset.forName("UTF-8")))); } } } catch (FileNotFoundException e) { Utils.debugLog(TAG, String.format("finding provision '%s' failed", file.getPath()), e); continue; } catch (IOException e) { Utils.debugLog(TAG, String.format("reading provision '%s' failed", file.getPath()), e); continue; } finally { IOUtils.closeQuietly(in); } result.add(plain); } } return result; } protected  Provisioner();  static final String TAG; }
@Test public void extractProvisionsPlaintextUnobfuscated() throws IOException { Provisioner p = new Provisioner(); List<File> files = Arrays.asList(getResourceFile("demo_credentials_user2.fdrp")); List<Provisioner.ProvisionPlaintext> result = p.extractProvisionsPlaintext(files); Assert.assertEquals(result.size(), 1); Assert.assertEquals("{\"username\": \"user2\", \"password\": \"other secret\", \"name\": \"Example Repo\", \"url\": \"https: Assert.assertTrue(String.valueOf(result.get(0).getProvisionPath()).endsWith("demo_credentials_user2.fdrp")); }
@Test public void extractProvisionsPlaintextObfuscated() throws IOException { Provisioner p = new Provisioner(); List<File> files = Arrays.asList(getResourceFile("demo_credentials_user1.fdrp")); List<Provisioner.ProvisionPlaintext> result = p.extractProvisionsPlaintext(files); Assert.assertEquals(result.size(), 1); Assert.assertEquals("{\"sigfp\": \"1111222233334444555566667777888899990000aaaabbbbccccddddeeeeffff\", \"name\": \"Example Repo\", \"password\": \"secret1\", \"url\": \"https: Assert.assertTrue(String.valueOf(result.get(0).getProvisionPath()).endsWith("demo_credentials_user1.fdrp")); }