Search in sources :

Example 1 with StringCredentialValue

use of org.cloudfoundry.credhub.credential.StringCredentialValue in project credhub by cloudfoundry-incubator.

the class SetHandlerTest method handleSetRequest_whenPasswordSetRequest_passesCorrectParametersIncludingGeneration.

@Test
public void handleSetRequest_whenPasswordSetRequest_passesCorrectParametersIncludingGeneration() {
    StringCredentialValue password = new StringCredentialValue("federation");
    PasswordSetRequest setRequest = new PasswordSetRequest();
    final ArrayList<EventAuditRecordParameters> eventAuditRecordParameters = new ArrayList<>();
    setRequest.setType("password");
    setRequest.setGenerationParameters(generationParameters);
    setRequest.setPassword(password);
    setRequest.setName("/captain");
    setRequest.setAdditionalPermissions(accessControlEntries);
    setRequest.setOverwrite(false);
    subject.handle(setRequest, eventAuditRecordParameters);
    verify(credentialService).save(null, password, setRequest, eventAuditRecordParameters);
    verify(permissionService).savePermissions(credentialVersion, accessControlEntries, eventAuditRecordParameters, true, "/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) Test(org.junit.Test)

Example 2 with StringCredentialValue

use of org.cloudfoundry.credhub.credential.StringCredentialValue in project credhub by cloudfoundry-incubator.

the class CredentialsControllerGenerateTest method beforeEach.

@Before
public void beforeEach() {
    Consumer<Long> fakeTimeSetter = mockOutCurrentTimeProvider(mockCurrentTimeProvider);
    userContext = mock(UserContext.class);
    fakeTimeSetter.accept(FROZEN_TIME.toEpochMilli());
    mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
    when(credentialGenerator.generateCredential(any(StringGenerationParameters.class))).thenReturn(new StringCredentialValue(FAKE_PASSWORD_NAME));
    when(sshGenerator.generateCredential(any(SshGenerationParameters.class))).thenReturn(new SshCredentialValue(PUBLIC_KEY, PRIVATE_KEY, null));
    when(rsaGenerator.generateCredential(any(RsaGenerationParameters.class))).thenReturn(new RsaCredentialValue(PUBLIC_KEY, PRIVATE_KEY));
    when(certificateGenerator.generateCredential(any(CertificateGenerationParameters.class))).thenReturn(new CertificateCredentialValue("ca_cert", CERT, PRIVATE_KEY, null));
}
Also used : RsaGenerationParameters(org.cloudfoundry.credhub.request.RsaGenerationParameters) CertificateGenerationParameters(org.cloudfoundry.credhub.domain.CertificateGenerationParameters) UserContext(org.cloudfoundry.credhub.auth.UserContext) CertificateCredentialValue(org.cloudfoundry.credhub.credential.CertificateCredentialValue) StringCredentialValue(org.cloudfoundry.credhub.credential.StringCredentialValue) RsaCredentialValue(org.cloudfoundry.credhub.credential.RsaCredentialValue) SshGenerationParameters(org.cloudfoundry.credhub.request.SshGenerationParameters) SshCredentialValue(org.cloudfoundry.credhub.credential.SshCredentialValue) StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters) Before(org.junit.Before)

Example 3 with StringCredentialValue

use of org.cloudfoundry.credhub.credential.StringCredentialValue in project credhub by cloudfoundry-incubator.

the class CredentialsControllerTypeSpecificGenerateTest method setup.

@Before
public void setup() throws Exception {
    String fakeSalt = cryptSaltFactory.generateSalt(FAKE_PASSWORD);
    Consumer<Long> fakeTimeSetter = mockOutCurrentTimeProvider(mockCurrentTimeProvider);
    fakeTimeSetter.accept(FROZEN_TIME.toEpochMilli());
    mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
    when(passwordGenerator.generateCredential(any(GenerationParameters.class))).thenReturn(new StringCredentialValue(FAKE_PASSWORD));
    when(certificateGenerator.generateCredential(any(GenerationParameters.class))).thenReturn(new CertificateCredentialValue(CA, CERTIFICATE, PRIVATE_KEY, null));
    when(sshGenerator.generateCredential(any(GenerationParameters.class))).thenReturn(new SshCredentialValue(PUBLIC_KEY, PRIVATE_KEY, null));
    when(rsaGenerator.generateCredential(any(GenerationParameters.class))).thenReturn(new RsaCredentialValue(PUBLIC_KEY, PRIVATE_KEY));
    when(userGenerator.generateCredential(any(GenerationParameters.class))).thenReturn(new UserCredentialValue(USERNAME, FAKE_PASSWORD, fakeSalt));
    auditingHelper = new AuditingHelper(requestAuditRecordRepository, eventAuditRecordRepository);
}
Also used : CertificateCredentialValue(org.cloudfoundry.credhub.credential.CertificateCredentialValue) StringCredentialValue(org.cloudfoundry.credhub.credential.StringCredentialValue) RsaCredentialValue(org.cloudfoundry.credhub.credential.RsaCredentialValue) GenerationParameters(org.cloudfoundry.credhub.request.GenerationParameters) StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters) Matchers.anyString(org.mockito.Matchers.anyString) AuditingHelper(org.cloudfoundry.credhub.helper.AuditingHelper) UserCredentialValue(org.cloudfoundry.credhub.credential.UserCredentialValue) SshCredentialValue(org.cloudfoundry.credhub.credential.SshCredentialValue) Before(org.junit.Before)

Example 4 with StringCredentialValue

use of org.cloudfoundry.credhub.credential.StringCredentialValue in project credhub by cloudfoundry-incubator.

the class CredentialFactoryTest method makeCredentialFromRequest_givenPasswordType_andNoExisting_returnsPasswordCredential.

@Test
public void makeCredentialFromRequest_givenPasswordType_andNoExisting_returnsPasswordCredential() throws Exception {
    StringCredentialValue passwordValue = new StringCredentialValue(PLAINTEXT_VALUE);
    PasswordCredentialVersion credential = (PasswordCredentialVersion) subject.makeNewCredentialVersion(CredentialType.valueOf("password"), CREDENTIAL_NAME, passwordValue, null, generationParameters);
    MatcherAssert.assertThat(credential.getCredential().getName(), equalTo(CREDENTIAL_NAME));
    assertThat(credential.getPassword(), equalTo(PLAINTEXT_VALUE));
    assertThat(credential.getGenerationParameters(), samePropertyValuesAs(generationParameters));
}
Also used : StringCredentialValue(org.cloudfoundry.credhub.credential.StringCredentialValue) Test(org.junit.Test)

Example 5 with StringCredentialValue

use of org.cloudfoundry.credhub.credential.StringCredentialValue in project credhub by cloudfoundry-incubator.

the class CredentialFactoryTest method makeCredentialFromRequest_givenValueType_andNoExisting_returnsValueCredential.

@Test
public void makeCredentialFromRequest_givenValueType_andNoExisting_returnsValueCredential() throws Exception {
    StringCredentialValue passwordValue = new StringCredentialValue(PLAINTEXT_VALUE);
    ValueCredentialVersion credential = (ValueCredentialVersion) subject.makeNewCredentialVersion(CredentialType.valueOf("value"), CREDENTIAL_NAME, passwordValue, null, null);
    MatcherAssert.assertThat(credential.getCredential().getName(), equalTo(CREDENTIAL_NAME));
    assertThat(credential.getValue(), equalTo(PLAINTEXT_VALUE));
}
Also used : StringCredentialValue(org.cloudfoundry.credhub.credential.StringCredentialValue) 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