use of org.cloudfoundry.credhub.credential.RsaCredentialValue 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));
}
use of org.cloudfoundry.credhub.credential.RsaCredentialValue 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);
}
use of org.cloudfoundry.credhub.credential.RsaCredentialValue in project credhub by cloudfoundry-incubator.
the class CredentialFactoryTest method makeCredentialFromRequest_givenRsaType_andNoExisting_returnsRsaCredential.
@Test
public void makeCredentialFromRequest_givenRsaType_andNoExisting_returnsRsaCredential() throws Exception {
RsaCredentialValue rsaValue = new RsaCredentialValue("public-key", PLAINTEXT_VALUE);
RsaCredentialVersion credential = (RsaCredentialVersion) subject.makeNewCredentialVersion(CredentialType.valueOf("rsa"), CREDENTIAL_NAME, rsaValue, null, null);
MatcherAssert.assertThat(credential.getCredential().getName(), equalTo(CREDENTIAL_NAME));
assertThat(credential.getPublicKey(), equalTo("public-key"));
assertThat(credential.getPrivateKey(), equalTo(PLAINTEXT_VALUE));
}
use of org.cloudfoundry.credhub.credential.RsaCredentialValue in project credhub by cloudfoundry-incubator.
the class RsaGeneratorTest method generateCredential_shouldReturnAGeneratedCredential.
@Test
public void generateCredential_shouldReturnAGeneratedCredential() throws Exception {
final RsaCredentialValue rsa = subject.generateCredential(new RsaGenerationParameters());
verify(keyPairGenerator).generateKeyPair(2048);
assertThat(rsa.getPublicKey(), equalTo(CertificateFormatter.pemOf(keyPair.getPublic())));
assertThat(rsa.getPrivateKey(), equalTo(CertificateFormatter.pemOf(keyPair.getPrivate())));
}
Aggregations