@Test public void getEncryptedPassword_BasicTest() throws Exception { final TGTService tgtService = context.mock(TGTService.class); final BlockStorageUtilSvc blockStorageUtilSvc = context.mock(BlockStorageUtilSvc.class); context.checking(new Expectations() { { oneOf(blockStorageUtilSvc).decryptSCTargetPassword("foo"); will(returnValue("foo")); oneOf(blockStorageUtilSvc).getPartitionForLocalService(Storage.class); will(returnValue(null)); oneOf(blockStorageUtilSvc).encryptNodeTargetPassword("foo", null); will(returnValue("foo")); } }); try (TransactionResource tran = Entities.transactionFor(CHAPUserInfo.class)) { Entities.persist(new CHAPUserInfo("eucalyptus", "foo")); tran.commit(); } ISCSIManager iscsiManager = new ISCSIManager(tgtService, blockStorageUtilSvc); String foo = iscsiManager.getEncryptedPassword(); assertTrue("expected result to be 'foo' but was - " + foo, foo != null && "foo".equals(foo)); }
public String getEncryptedPassword() throws EucalyptusCloudException { try (TransactionResource tran = Entities.transactionFor(CHAPUserInfo.class)) { CHAPUserInfo userInfo = Entities.uniqueResult(new CHAPUserInfo("eucalyptus")); String encryptedPassword = userInfo.getEncryptedPassword(); tran.commit(); return blockStorageUtilSvc.encryptNodeTargetPassword(blockStorageUtilSvc.decryptSCTargetPassword(encryptedPassword), blockStorageUtilSvc.getPartitionForLocalService(Storage.class)); } catch (TransactionException | NoSuchElementException ex) { throw new EucalyptusCloudException("Unable to get CHAP password for: " + "eucalyptus"); } }
ISCSIManager implements StorageExportManager { public String getEncryptedPassword() throws EucalyptusCloudException { try (TransactionResource tran = Entities.transactionFor(CHAPUserInfo.class)) { CHAPUserInfo userInfo = Entities.uniqueResult(new CHAPUserInfo("eucalyptus")); String encryptedPassword = userInfo.getEncryptedPassword(); tran.commit(); return blockStorageUtilSvc.encryptNodeTargetPassword(blockStorageUtilSvc.decryptSCTargetPassword(encryptedPassword), blockStorageUtilSvc.getPartitionForLocalService(Storage.class)); } catch (TransactionException | NoSuchElementException ex) { throw new EucalyptusCloudException("Unable to get CHAP password for: " + "eucalyptus"); } } }
ISCSIManager implements StorageExportManager { public String getEncryptedPassword() throws EucalyptusCloudException { try (TransactionResource tran = Entities.transactionFor(CHAPUserInfo.class)) { CHAPUserInfo userInfo = Entities.uniqueResult(new CHAPUserInfo("eucalyptus")); String encryptedPassword = userInfo.getEncryptedPassword(); tran.commit(); return blockStorageUtilSvc.encryptNodeTargetPassword(blockStorageUtilSvc.decryptSCTargetPassword(encryptedPassword), blockStorageUtilSvc.getPartitionForLocalService(Storage.class)); } catch (TransactionException | NoSuchElementException ex) { throw new EucalyptusCloudException("Unable to get CHAP password for: " + "eucalyptus"); } } ISCSIManager();  ISCSIManager(TGTService tgtService, BlockStorageUtilSvc blockStorageUtilSvc); }
ISCSIManager implements StorageExportManager { public String getEncryptedPassword() throws EucalyptusCloudException { try (TransactionResource tran = Entities.transactionFor(CHAPUserInfo.class)) { CHAPUserInfo userInfo = Entities.uniqueResult(new CHAPUserInfo("eucalyptus")); String encryptedPassword = userInfo.getEncryptedPassword(); tran.commit(); return blockStorageUtilSvc.encryptNodeTargetPassword(blockStorageUtilSvc.decryptSCTargetPassword(encryptedPassword), blockStorageUtilSvc.getPartitionForLocalService(Storage.class)); } catch (TransactionException | NoSuchElementException ex) { throw new EucalyptusCloudException("Unable to get CHAP password for: " + "eucalyptus"); } } ISCSIManager();  ISCSIManager(TGTService tgtService, BlockStorageUtilSvc blockStorageUtilSvc); @Override void checkPreconditions(); @Override void check(); void addUser(String username, String password); void deleteUser(String username); void exportTarget(String volumeId, int tid, String name, int lun, String path, String user); void unexportTarget(String volumeId, int tid, int lun, String path); @Override void configure(); @Override synchronized void allocateTarget(LVMVolumeInfo volumeInfo); String getEncryptedPassword(); void cleanup(LVMVolumeInfo volumeInfo); @Override void stop(); @Override boolean isExported(LVMVolumeInfo volumeInfo); }
ISCSIManager implements StorageExportManager { public String getEncryptedPassword() throws EucalyptusCloudException { try (TransactionResource tran = Entities.transactionFor(CHAPUserInfo.class)) { CHAPUserInfo userInfo = Entities.uniqueResult(new CHAPUserInfo("eucalyptus")); String encryptedPassword = userInfo.getEncryptedPassword(); tran.commit(); return blockStorageUtilSvc.encryptNodeTargetPassword(blockStorageUtilSvc.decryptSCTargetPassword(encryptedPassword), blockStorageUtilSvc.getPartitionForLocalService(Storage.class)); } catch (TransactionException | NoSuchElementException ex) { throw new EucalyptusCloudException("Unable to get CHAP password for: " + "eucalyptus"); } } ISCSIManager();  ISCSIManager(TGTService tgtService, BlockStorageUtilSvc blockStorageUtilSvc); @Override void checkPreconditions(); @Override void check(); void addUser(String username, String password); void deleteUser(String username); void exportTarget(String volumeId, int tid, String name, int lun, String path, String user); void unexportTarget(String volumeId, int tid, int lun, String path); @Override void configure(); @Override synchronized void allocateTarget(LVMVolumeInfo volumeInfo); String getEncryptedPassword(); void cleanup(LVMVolumeInfo volumeInfo); @Override void stop(); @Override boolean isExported(LVMVolumeInfo volumeInfo);  }