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());
}
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));
}
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));
}
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));
}
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");
}
Aggregations