Search in sources :

Example 41 with Credential

use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.

the class PermissionDataServiceTest method setAccessControlEntries_whenGivenANewAce_returnsTheAcl.

@Test
public void setAccessControlEntries_whenGivenANewAce_returnsTheAcl() {
    final ValueCredentialVersionData valueCredentialData2 = new ValueCredentialVersionData("lightsaber2");
    final Credential credential2 = valueCredentialData2.getCredential();
    credentialDataService.save(credential2);
    aces = singletonList(new PermissionEntry(LUKE, singletonList(READ)));
    subject.savePermissions(credential2, aces);
    List<PermissionEntry> response = subject.getPermissions(credential2);
    final PermissionEntry permissionEntry = response.get(0);
    assertThat(response, hasSize(1));
    assertThat(permissionEntry.getActor(), equalTo(LUKE));
    assertThat(permissionEntry.getAllowedOperations(), hasSize(1));
    assertThat(permissionEntry.getAllowedOperations(), hasItem(READ));
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) PermissionEntry(org.cloudfoundry.credhub.request.PermissionEntry) ValueCredentialVersionData(org.cloudfoundry.credhub.entity.ValueCredentialVersionData) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 42 with Credential

use of org.cloudfoundry.credhub.entity.Credential 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 43 with Credential

use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.

the class CredentialDataServiceTest method save_setsTheUuidOnTheCredential.

@Test
public void save_setsTheUuidOnTheCredential() {
    final Credential credential = credentialRepository.save(new Credential(CREDENTIAL_NAME));
    assertThat(credential.getUuid(), instanceOf(UUID.class));
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) UUID(java.util.UUID) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 44 with Credential

use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.

the class CredentialDataServiceTest method delete_whenTheCredentialExists_deletesTheCredential_andReturnsTrue.

@Test
public void delete_whenTheCredentialExists_deletesTheCredential_andReturnsTrue() {
    credentialRepository.save(new Credential(CREDENTIAL_NAME));
    assertThat(subject.delete(CREDENTIAL_NAME), equalTo(true));
    assertThat(credentialRepository.count(), equalTo(0L));
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 45 with Credential

use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.

the class CredentialDataServiceTest method delete_isCaseInsensitive.

@Test
public void delete_isCaseInsensitive() {
    credentialRepository.save(new Credential(CREDENTIAL_NAME.toUpperCase()));
    assertThat(subject.delete(CREDENTIAL_NAME.toLowerCase()), equalTo(true));
    assertThat(credentialRepository.count(), equalTo(0L));
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Credential (org.cloudfoundry.credhub.entity.Credential)49 Test (org.junit.Test)30 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)15 UUID (java.util.UUID)13 UserContext (org.cloudfoundry.credhub.auth.UserContext)13 CertificateCredentialVersion (org.cloudfoundry.credhub.domain.CertificateCredentialVersion)13 EventAuditRecordParameters (org.cloudfoundry.credhub.audit.EventAuditRecordParameters)9 CredentialVersion (org.cloudfoundry.credhub.domain.CredentialVersion)9 EntryNotFoundException (org.cloudfoundry.credhub.exceptions.EntryNotFoundException)9 EncryptedValue (org.cloudfoundry.credhub.entity.EncryptedValue)7 CertificateCredentialVersionData (org.cloudfoundry.credhub.entity.CertificateCredentialVersionData)5 PasswordCredentialVersionData (org.cloudfoundry.credhub.entity.PasswordCredentialVersionData)5 CertificateCredentialValue (org.cloudfoundry.credhub.credential.CertificateCredentialValue)4 CredentialVersionData (org.cloudfoundry.credhub.entity.CredentialVersionData)4 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 AuditingOperationCode (org.cloudfoundry.credhub.audit.AuditingOperationCode)3 UserContextHolder (org.cloudfoundry.credhub.auth.UserContextHolder)3 ValueCredentialVersionData (org.cloudfoundry.credhub.entity.ValueCredentialVersionData)3 ParameterizedValidationException (org.cloudfoundry.credhub.exceptions.ParameterizedValidationException)3