ConfigurationServerImpl extends ManagerBase implements ConfigurationServer { static String getBase64Keystore(String keystorePath) throws IOException { byte[] storeBytes = FileUtils.readFileToByteArray(new File(keystorePath)); if (storeBytes.length > 3000) { throw new IOException("KeyStore is too big for database! Length " + storeBytes.length); } return new String(Base64.encodeBase64(storeBytes)); } ConfigurationServerImpl(); @Override boolean configure(String name, Map<String, Object> params); @Override void persistDefaultValues(); @DB void saveUser(); @Override @DB void updateKeyPairs(); @Override List<ConfigurationVO> getConfigListByScope(String scope, Long resourceId); @DB void updateResourceCount(); Map<String, String> getServicesAndProvidersForNetwork(long networkOfferingId); static final Logger s_logger; }
@Test(expected = IOException.class) public void testGetBase64KeystoreNoSuchFile() throws IOException { ConfigurationServerImpl.getBase64Keystore("notexisting" + System.currentTimeMillis()); }
@Test(expected = IOException.class) public void testGetBase64KeystoreTooBigFile() throws IOException { File temp = File.createTempFile("keystore", ""); StringBuilder builder = new StringBuilder(); for (int i = 0; i < 1000; i++) { builder.append("way too long...\n"); } FileUtils.writeStringToFile(temp, builder.toString()); try { ConfigurationServerImpl.getBase64Keystore(temp.getPath()); } finally { temp.delete(); } }
@Test public void testGetBase64Keystore() throws IOException { File temp = File.createTempFile("keystore", ""); try { FileUtils.writeStringToFile(temp, Base64.encodeBase64String(TEST.getBytes())); final String keystore = ConfigurationServerImpl.getBase64Keystore(temp.getPath()); Base64.decodeBase64(keystore); } finally { temp.delete(); } }