use of org.cloudfoundry.credhub.credential.StringCredentialValue in project credhub by cloudfoundry-incubator.
the class UserGeneratorTest method beforeEach.
@Before
public void beforeEach() {
UsernameGenerator usernameGenerator = mock(UsernameGenerator.class);
PasswordCredentialGenerator passwordGenerator = mock(PasswordCredentialGenerator.class);
CryptSaltFactory cryptSaltFactory = mock(CryptSaltFactory.class);
passwordParameters = new StringGenerationParameters();
userContext = null;
subject = new UserGenerator(usernameGenerator, passwordGenerator, cryptSaltFactory);
StringCredentialValue generatedUsername = new StringCredentialValue("fake-generated-username");
StringCredentialValue generatedPassword = new StringCredentialValue("fake-generated-password");
when(usernameGenerator.generateCredential()).thenReturn(generatedUsername);
when(passwordGenerator.generateCredential(eq(passwordParameters))).thenReturn(generatedPassword);
when(cryptSaltFactory.generateSalt(generatedPassword.getStringCredential())).thenReturn("fake-generated-salt");
}
use of org.cloudfoundry.credhub.credential.StringCredentialValue in project credhub by cloudfoundry-incubator.
the class UsernameGeneratorTest method generateCredential_generatesACredential.
@Test
public void generateCredential_generatesACredential() {
final StringCredentialValue expected = new StringCredentialValue("fake-credential");
when(passayStringCredentialGenerator.generateCredential(any(StringGenerationParameters.class))).thenReturn(expected);
final StringCredentialValue credential = subject.generateCredential();
assertThat(credential, equalTo(expected));
}
use of org.cloudfoundry.credhub.credential.StringCredentialValue in project credhub by cloudfoundry-incubator.
the class PasswordGeneratorTest method generateCredential_usesTheParametersToGenerateAPassword.
@Test
public void generateCredential_usesTheParametersToGenerateAPassword() {
final StringGenerationParameters stringGenerationParameters = mock(StringGenerationParameters.class);
final StringCredentialValue credential = new StringCredentialValue("fake-generated-password");
when(passayStringCredentialGenerator.generateCredential(stringGenerationParameters)).thenReturn(credential);
assertThat(subject.generateCredential(stringGenerationParameters), equalTo(credential));
}
use of org.cloudfoundry.credhub.credential.StringCredentialValue in project credhub by cloudfoundry-incubator.
the class GenerateHandlerTest method handleGenerateRequest_whenPasswordGenerateRequest_passesCorrectParametersIncludingGeneration.
@Test
public void handleGenerateRequest_whenPasswordGenerateRequest_passesCorrectParametersIncludingGeneration() {
StringCredentialValue password = new StringCredentialValue("federation");
PasswordGenerateRequest generateRequest = new PasswordGenerateRequest();
final ArrayList<EventAuditRecordParameters> eventAuditRecordParameters = new ArrayList<>();
generateRequest.setType("password");
generateRequest.setGenerationParameters(generationParameters);
generateRequest.setName("/captain");
generateRequest.setAdditionalPermissions(accessControlEntries);
generateRequest.setOverwrite(false);
subject.handle(generateRequest, eventAuditRecordParameters);
verify(credentialService).save(null, null, generateRequest, eventAuditRecordParameters);
verify(permissionService).savePermissions(credentialVersion, accessControlEntries, eventAuditRecordParameters, true, "/captain");
}
use of org.cloudfoundry.credhub.credential.StringCredentialValue in project credhub by cloudfoundry-incubator.
the class SetHandlerTest method handleSetRequest_whenOverwriteIsTrue_shouldSaveAccessControlEntries.
@Test
public void handleSetRequest_whenOverwriteIsTrue_shouldSaveAccessControlEntries() {
StringCredentialValue password = new StringCredentialValue("federation");
PasswordSetRequest setRequest = new PasswordSetRequest();
CredentialVersion existingCredMock = mock(CredentialVersion.class);
when(credentialService.findMostRecent("/captain")).thenReturn(existingCredMock);
final ArrayList<EventAuditRecordParameters> eventAuditRecordParameters = new ArrayList<>();
setRequest.setType("password");
setRequest.setGenerationParameters(generationParameters);
setRequest.setPassword(password);
setRequest.setName("/captain");
setRequest.setAdditionalPermissions(accessControlEntries);
setRequest.setOverwrite(true);
subject.handle(setRequest, eventAuditRecordParameters);
verify(credentialService).save(existingCredMock, password, setRequest, eventAuditRecordParameters);
verify(permissionService).savePermissions(credentialVersion, accessControlEntries, eventAuditRecordParameters, false, "/captain");
}
Aggregations