Search in sources :

Example 46 with CredentialVersion

use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.

the class CredentialVersionDataServiceTest method findNByName_whenProvidedANameAndCount_findsCountMatchingCredentials.

@Test
public void findNByName_whenProvidedANameAndCount_findsCountMatchingCredentials() {
    PasswordCredentialVersion credential1 = savePassword(2000000000125L, "/secret1");
    PasswordCredentialVersion credential2 = savePassword(2000000000124L, "/seCret1");
    PasswordCredentialVersion credential3 = savePassword(2000000000123L, "/secret1");
    savePassword(3000000000123L, "/Secret2");
    List<CredentialVersion> credentialVersions = subject.findNByName("/Secret1", 2);
    assertThat(credentialVersions, containsInAnyOrder(hasProperty("uuid", equalTo(credential1.getUuid())), hasProperty("uuid", equalTo(credential2.getUuid()))));
    assertThat("returns empty list when no credential matches", subject.findNByName("does/NOT/exist", 12), empty());
}
Also used : PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) ValueCredentialVersion(org.cloudfoundry.credhub.domain.ValueCredentialVersion) SshCredentialVersion(org.cloudfoundry.credhub.domain.SshCredentialVersion) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 47 with CredentialVersion

use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.

the class CredentialVersionDataServiceTest method findNByName_whenAskedForANegativeNumberOfVersions_throws.

@Test(expected = IllegalArgumentException.class)
public void findNByName_whenAskedForANegativeNumberOfVersions_throws() {
    PasswordCredentialVersion credential1 = savePassword(2000000000123L, "/secret1");
    List<CredentialVersion> credentialVersions = subject.findNByName("/Secret1", -2);
    assertThat(credentialVersions.size(), equalTo(0));
}
Also used : PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) ValueCredentialVersion(org.cloudfoundry.credhub.domain.ValueCredentialVersion) SshCredentialVersion(org.cloudfoundry.credhub.domain.SshCredentialVersion) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 48 with CredentialVersion

use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.

the class CertificateVersionDataServiceTest method findActiveWithTransitional_findsMostRecentNonTransitionalAndTransitionalCredentialVersions.

@Test
public void findActiveWithTransitional_findsMostRecentNonTransitionalAndTransitionalCredentialVersions() throws Exception {
    Credential certificate = mock(Credential.class);
    when(dataService.find("/some-cert-name")).thenReturn(certificate);
    CredentialVersionData activeCert = mock(CredentialVersionData.class);
    when(versionRepository.findLatestNonTransitionalCertificateVersion(any())).thenReturn(activeCert);
    CredentialVersionData transitionalCert = mock(CredentialVersionData.class);
    when(versionRepository.findTransitionalCertificateVersion(any())).thenReturn(transitionalCert);
    CredentialVersion expectedActive = mock(CredentialVersion.class);
    when(factory.makeCredentialFromEntity(activeCert)).thenReturn(expectedActive);
    CredentialVersion expectedTransitional = mock(CredentialVersion.class);
    when(factory.makeCredentialFromEntity(transitionalCert)).thenReturn(expectedTransitional);
    List<CredentialVersion> credentialVersions = subject.findActiveWithTransitional("/some-cert-name");
    assertThat(credentialVersions, hasSize(2));
    assertThat(credentialVersions, containsInAnyOrder(expectedActive, expectedTransitional));
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) CredentialVersionData(org.cloudfoundry.credhub.entity.CredentialVersionData) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) Test(org.junit.Test)

Example 49 with CredentialVersion

use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.

the class CertificatesHandlerTest method handleGetAllVersionsRequest_returnsListOfCertificateViews.

@Test
public void handleGetAllVersionsRequest_returnsListOfCertificateViews() {
    UUID uuid = UUID.randomUUID();
    String certificateName = "some certificate";
    CredentialVersion credentialVersion = new CertificateCredentialVersion(certificateName);
    when(permissionedCertificateService.getVersions(uuid, false, Collections.emptyList())).thenReturn(Collections.singletonList(credentialVersion));
    List<CertificateView> certificateViews = subject.handleGetAllVersionsRequest(uuid.toString(), Collections.emptyList(), false);
    assertThat(certificateViews.size(), equalTo(1));
    assertThat(certificateViews.get(0).getName(), equalTo(certificateName));
}
Also used : UUID(java.util.UUID) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) CertificateView(org.cloudfoundry.credhub.view.CertificateView) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) Test(org.junit.Test)

Example 50 with CredentialVersion

use of org.cloudfoundry.credhub.domain.CredentialVersion 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

CredentialVersion (org.cloudfoundry.credhub.domain.CredentialVersion)50 CertificateCredentialVersion (org.cloudfoundry.credhub.domain.CertificateCredentialVersion)35 Test (org.junit.Test)33 PasswordCredentialVersion (org.cloudfoundry.credhub.domain.PasswordCredentialVersion)27 SshCredentialVersion (org.cloudfoundry.credhub.domain.SshCredentialVersion)22 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)19 ValueCredentialVersion (org.cloudfoundry.credhub.domain.ValueCredentialVersion)17 RsaCredentialVersion (org.cloudfoundry.credhub.domain.RsaCredentialVersion)14 UserCredentialVersion (org.cloudfoundry.credhub.domain.UserCredentialVersion)13 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)11 JsonCredentialVersion (org.cloudfoundry.credhub.domain.JsonCredentialVersion)10 Credential (org.cloudfoundry.credhub.entity.Credential)8 EntryNotFoundException (org.cloudfoundry.credhub.exceptions.EntryNotFoundException)7 EventAuditRecordParameters (org.cloudfoundry.credhub.audit.EventAuditRecordParameters)6 ArrayList (java.util.ArrayList)5 UUID (java.util.UUID)5 CredentialVersionData (org.cloudfoundry.credhub.entity.CredentialVersionData)5 ResultActions (org.springframework.test.web.servlet.ResultActions)5 CertificateCredentialValue (org.cloudfoundry.credhub.credential.CertificateCredentialValue)4 UserContext (org.cloudfoundry.credhub.auth.UserContext)3