use of org.cloudfoundry.credhub.request.StringGenerationParameters in project credhub by cloudfoundry-incubator.
the class CredentialRegenerateTest method regeneratingAPasswordWithParametersThatCannotBeDecrypted_returnsAnError.
@Test
public void regeneratingAPasswordWithParametersThatCannotBeDecrypted_returnsAnError() throws Exception {
EncryptionKeyCanary encryptionKeyCanary = new EncryptionKeyCanary();
canaryDataService.save(encryptionKeyCanary);
PasswordCredentialVersionData passwordCredentialData = new PasswordCredentialVersionData("/my-password");
PasswordCredentialVersion originalCredential = new PasswordCredentialVersion(passwordCredentialData);
originalCredential.setEncryptor(encryptor);
originalCredential.setPasswordAndGenerationParameters("abcde", new StringGenerationParameters());
passwordCredentialData.getEncryptedValueData().setEncryptionKeyUuid(encryptionKeyCanary.getUuid());
credentialVersionDataService.save(originalCredential);
// language=JSON
String cannotRegenerate = "{\n" + " \"error\": \"The credential could not be accessed with the provided encryption keys. You must update your deployment configuration to continue" + ".\"\n" + "}";
MockHttpServletRequestBuilder request = post("/api/v1/data").header("Authorization", "Bearer " + AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content("{\"regenerate\":true,\"name\":\"my-password\"}");
mockMvc.perform(request).andDo(print()).andExpect(status().isInternalServerError()).andExpect(content().json(cannotRegenerate));
}
use of org.cloudfoundry.credhub.request.StringGenerationParameters in project credhub by cloudfoundry-incubator.
the class CredentialRegenerateTest method regeneratingAPassword_regeneratesThePassword_andPersistsAnAuditEntry.
@Test
public void regeneratingAPassword_regeneratesThePassword_andPersistsAnAuditEntry() throws Exception {
PasswordCredentialVersion originalCredential = new PasswordCredentialVersion("/my-password");
originalCredential.setEncryptor(encryptor);
StringGenerationParameters generationParameters = new StringGenerationParameters();
generationParameters.setExcludeNumber(true);
originalCredential.setPasswordAndGenerationParameters("original-password", generationParameters);
originalCredential.setVersionCreatedAt(FROZEN_TIME.plusSeconds(1));
credentialVersionDataService.save(originalCredential);
fakeTimeSetter.accept(FROZEN_TIME.plusSeconds(10).toEpochMilli());
MockHttpServletRequestBuilder request = post("/api/v1/data").header("Authorization", "Bearer " + AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content("{\"regenerate\":true,\"name\":\"my-password\"}");
mockMvc.perform(request).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)).andExpect(jsonPath("$.type").value("password")).andExpect(jsonPath("$.version_created_at").value(FROZEN_TIME.plusSeconds(10).toString()));
final PasswordCredentialVersion newPassword = (PasswordCredentialVersion) credentialVersionDataService.findMostRecent("/my-password");
assertThat(newPassword.getPassword(), not(equalTo("original-credential")));
assertThat(newPassword.getGenerationParameters().isExcludeNumber(), equalTo(true));
auditingHelper.verifyAuditing(CREDENTIAL_UPDATE, "/my-password", AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_ACTOR_ID, "/api/v1/data", 200);
}
use of org.cloudfoundry.credhub.request.StringGenerationParameters in project credhub by cloudfoundry-incubator.
the class PasswordGeneratorTest method generateCredential_usesTheParametersToGenerateAPassword.
@Test
public void generateCredential_usesTheParametersToGenerateAPassword() {
final StringGenerationParameters stringGenerationParameters = mock(StringGenerationParameters.class);
final StringCredentialValue credential = new StringCredentialValue("fake-generated-password");
when(passayStringCredentialGenerator.generateCredential(stringGenerationParameters)).thenReturn(credential);
assertThat(subject.generateCredential(stringGenerationParameters), equalTo(credential));
}
use of org.cloudfoundry.credhub.request.StringGenerationParameters in project credhub by cloudfoundry-incubator.
the class UsernameGeneratorTest method generateCredential_usesAppropriateGenerationParameters.
@Test
public void generateCredential_usesAppropriateGenerationParameters() {
ArgumentCaptor<StringGenerationParameters> captor = ArgumentCaptor.forClass(StringGenerationParameters.class);
subject.generateCredential();
verify(passayStringCredentialGenerator, times(1)).generateCredential(captor.capture());
final StringGenerationParameters actual = captor.getValue();
assertThat(actual.getLength(), equalTo(20));
assertThat(actual.isExcludeLower(), equalTo(false));
assertThat(actual.isExcludeUpper(), equalTo(false));
assertThat(actual.isExcludeNumber(), equalTo(true));
assertThat(actual.isIncludeSpecial(), equalTo(false));
}
use of org.cloudfoundry.credhub.request.StringGenerationParameters in project credhub by cloudfoundry-incubator.
the class SetHandlerTest method setUp.
@Before
public void setUp() throws Exception {
TestHelper.getBouncyCastleProvider();
credentialService = mock(PermissionedCredentialService.class);
certificateAuthorityService = mock(CertificateAuthorityService.class);
permissionService = mock(PermissionService.class);
userContext = new UserContext();
UserContextHolder userContextHolder = new UserContextHolder();
userContextHolder.setUserContext(userContext);
subject = new SetHandler(credentialService, permissionService, certificateAuthorityService, userContextHolder);
generationParameters = new StringGenerationParameters();
accessControlEntries = new ArrayList<>();
credentialVersion = mock(PasswordCredentialVersion.class);
when(credentialService.save(anyObject(), anyObject(), anyObject(), anyList())).thenReturn(credentialVersion);
}
Aggregations