Search in sources :

Example 11 with StringCredentialValue

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");
}
Also used : StringCredentialValue(org.cloudfoundry.credhub.credential.StringCredentialValue) CryptSaltFactory(org.cloudfoundry.credhub.credential.CryptSaltFactory) StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters) Before(org.junit.Before)

Example 12 with StringCredentialValue

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));
}
Also used : StringCredentialValue(org.cloudfoundry.credhub.credential.StringCredentialValue) StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters) Test(org.junit.Test)

Example 13 with StringCredentialValue

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));
}
Also used : StringCredentialValue(org.cloudfoundry.credhub.credential.StringCredentialValue) StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters) Test(org.junit.Test)

Example 14 with StringCredentialValue

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");
}
Also used : StringCredentialValue(org.cloudfoundry.credhub.credential.StringCredentialValue) ArrayList(java.util.ArrayList) PasswordGenerateRequest(org.cloudfoundry.credhub.request.PasswordGenerateRequest) EventAuditRecordParameters(org.cloudfoundry.credhub.audit.EventAuditRecordParameters) Test(org.junit.Test)

Example 15 with StringCredentialValue

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");
}
Also used : StringCredentialValue(org.cloudfoundry.credhub.credential.StringCredentialValue) ArrayList(java.util.ArrayList) PasswordSetRequest(org.cloudfoundry.credhub.request.PasswordSetRequest) EventAuditRecordParameters(org.cloudfoundry.credhub.audit.EventAuditRecordParameters) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) Test(org.junit.Test)

Aggregations

StringCredentialValue (org.cloudfoundry.credhub.credential.StringCredentialValue)15 Test (org.junit.Test)12 StringGenerationParameters (org.cloudfoundry.credhub.request.StringGenerationParameters)9 ArrayList (java.util.ArrayList)3 EventAuditRecordParameters (org.cloudfoundry.credhub.audit.EventAuditRecordParameters)3 Before (org.junit.Before)3 CertificateCredentialValue (org.cloudfoundry.credhub.credential.CertificateCredentialValue)2 RsaCredentialValue (org.cloudfoundry.credhub.credential.RsaCredentialValue)2 SshCredentialValue (org.cloudfoundry.credhub.credential.SshCredentialValue)2 PasswordSetRequest (org.cloudfoundry.credhub.request.PasswordSetRequest)2 List (java.util.List)1 UserContext (org.cloudfoundry.credhub.auth.UserContext)1 CryptSaltFactory (org.cloudfoundry.credhub.credential.CryptSaltFactory)1 UserCredentialValue (org.cloudfoundry.credhub.credential.UserCredentialValue)1 CertificateGenerationParameters (org.cloudfoundry.credhub.domain.CertificateGenerationParameters)1 CredentialVersion (org.cloudfoundry.credhub.domain.CredentialVersion)1 PasswordCredentialVersion (org.cloudfoundry.credhub.domain.PasswordCredentialVersion)1 AuditingHelper (org.cloudfoundry.credhub.helper.AuditingHelper)1 GenerationParameters (org.cloudfoundry.credhub.request.GenerationParameters)1 PasswordGenerateRequest (org.cloudfoundry.credhub.request.PasswordGenerateRequest)1