throw new CredStashGetCredentialFailedException(String.format("Failed to obtain credential from credstash.%s " + "credStashAwsRegion=%s credStashTableName=%s credStashEncryptionContext=%s credentialName=%s", StringUtils.isNotBlank(errorMessage) ? " Reason: " + errorMessage : "", credStashAwsRegion, credStashTableName, credStashEncryptionContext,
throw new CredStashGetCredentialFailedException(String.format("Failed to obtain credential from credstash.%s " + "credStashAwsRegion=%s credStashTableName=%s credStashEncryptionContext=%s credentialName=%s", StringUtils.isNotBlank(errorMessage) ? " Reason: " + errorMessage : "", credStashAwsRegion, credStashTableName, credStashEncryptionContext,
@Test public void testGetPasswordCredStashException() throws Exception { // Mock the external calls. when(configurationHelper.getProperty(ConfigurationValue.CREDSTASH_RELATIONAL_STORAGE_ENCRYPTION_CONTEXT)).thenReturn(CREDSTASH_ENCRYPTION_CONTEXT); when(credStashHelper.getCredentialFromCredStash(CREDSTASH_ENCRYPTION_CONTEXT, USER_CREDENTIAL_NAME)) .thenThrow(new CredStashGetCredentialFailedException(ERROR_MESSAGE)); // Try to call the method under test. try { relationalTableRegistrationHelperServiceImpl.getPassword(new RelationalStorageAttributesDto(JDBC_URL, USERNAME, USER_CREDENTIAL_NAME)); fail(); } catch (IllegalStateException e) { assertEquals(String.format("%s: %s", CredStashGetCredentialFailedException.class.getName(), ERROR_MESSAGE), e.getMessage()); } // Verify the external calls. verify(configurationHelper).getProperty(ConfigurationValue.CREDSTASH_RELATIONAL_STORAGE_ENCRYPTION_CONTEXT); verify(credStashHelper).getCredentialFromCredStash(CREDSTASH_ENCRYPTION_CONTEXT, USER_CREDENTIAL_NAME); verifyNoMoreInteractionsHelper(); }
@Test public void testGetSubjectMatterExpertByKeyCredStashGetCredentialFailedException() throws Exception { // Create a subject matter expert key. SubjectMatterExpertKey subjectMatterExpertKey = new SubjectMatterExpertKey(USER_ID); // Create subject matter expert contact details initialised with test data. SubjectMatterExpertContactDetails subjectMatterExpertContactDetails = new SubjectMatterExpertContactDetails(USER_FULL_NAME, USER_JOB_TITLE, USER_EMAIL_ADDRESS, USER_TELEPHONE_NUMBER); // Mock the external calls. when(configurationHelper.getProperty(ConfigurationValue.LDAP_URL)).thenReturn(LDAP_URL); when(configurationHelper.getProperty(ConfigurationValue.LDAP_BASE)).thenReturn(LDAP_BASE); when(configurationHelper.getProperty(ConfigurationValue.LDAP_USER_DN)).thenReturn(LDAP_USER_DN); when(configurationHelper.getProperty(ConfigurationValue.CREDSTASH_HERD_ENCRYPTION_CONTEXT)).thenReturn(CREDSTASH_ENCRYPTION_CONTEXT); when(configurationHelper.getProperty(ConfigurationValue.LDAP_USER_CREDENTIAL_NAME)).thenReturn(USER_CREDENTIAL_NAME); when(credStashHelper.getCredentialFromCredStash(CREDSTASH_ENCRYPTION_CONTEXT, USER_CREDENTIAL_NAME)) .thenThrow(new CredStashGetCredentialFailedException(ERROR_MESSAGE)); // Specify the expected exception. expectedException.expect(IllegalStateException.class); expectedException.expectMessage(ERROR_MESSAGE); // Try to call the method under test. subjectMatterExpertDaoImpl.getSubjectMatterExpertByKey(subjectMatterExpertKey); // Verify the external calls. verify(configurationHelper).getProperty(ConfigurationValue.LDAP_URL); verify(configurationHelper).getProperty(ConfigurationValue.LDAP_BASE); verify(configurationHelper).getProperty(ConfigurationValue.LDAP_USER_DN); verify(configurationHelper).getProperty(ConfigurationValue.CREDSTASH_HERD_ENCRYPTION_CONTEXT); verify(configurationHelper).getProperty(ConfigurationValue.LDAP_USER_CREDENTIAL_NAME); verify(credStashHelper).getCredentialFromCredStash(CREDSTASH_ENCRYPTION_CONTEXT, USER_CREDENTIAL_NAME); verifyNoMoreInteractionsHelper(); }