use of org.cloudfoundry.credhub.request.StringGenerationParameters in project credhub by cloudfoundry-incubator.
the class JsonObjectMapperTest method writeValueAsString_convertsObjectToSnakeCaseJson.
@Test
public void writeValueAsString_convertsObjectToSnakeCaseJson() throws JsonProcessingException {
final StringGenerationParameters generationParameters = new StringGenerationParameters().setExcludeLower(true).setIncludeSpecial(true);
String expectedResult = "{\"exclude_lower\":true,\"include_special\":true}";
final String actualValue = new JsonObjectMapper().writeValueAsString(generationParameters);
assertThat(actualValue, equalTo(expectedResult));
}
use of org.cloudfoundry.credhub.request.StringGenerationParameters in project credhub by cloudfoundry-incubator.
the class JsonObjectMapperTest method readValue_shouldConvertJsonStringsInSnakeCaseToObjects.
@Test
public void readValue_shouldConvertJsonStringsInSnakeCaseToObjects() throws IOException {
final String testSnakeCaseString = "{\"exclude_lower\":true,\"include_special\":true}";
StringGenerationParameters generationParameters = new StringGenerationParameters().setExcludeLower(true).setIncludeSpecial(true);
final StringGenerationParameters actualGenerationParameters = new JsonObjectMapper().readValue(testSnakeCaseString, StringGenerationParameters.class);
assertThat(generationParameters, equalTo(actualGenerationParameters));
}
use of org.cloudfoundry.credhub.request.StringGenerationParameters in project credhub by cloudfoundry-incubator.
the class JsonObjectMapperTest method deserializeBackwardsCompatibleValue_supportsCamelCaseDeserialization.
@Test
public void deserializeBackwardsCompatibleValue_supportsCamelCaseDeserialization() throws IOException {
final String testSnakeCaseString = "{\"excludeLower\":true,\"includeSpecial\":true}";
StringGenerationParameters generationParameters = new StringGenerationParameters().setExcludeLower(true).setIncludeSpecial(true);
final StringGenerationParameters actualGenerationParameters = new JsonObjectMapper().deserializeBackwardsCompatibleValue(testSnakeCaseString, StringGenerationParameters.class);
assertThat(generationParameters, equalTo(actualGenerationParameters));
}
use of org.cloudfoundry.credhub.request.StringGenerationParameters in project credhub by cloudfoundry-incubator.
the class UserCredentialRegeneratable method createGenerateRequest.
@Override
public BaseCredentialGenerateRequest createGenerateRequest(CredentialVersion credentialVersion, List<EventAuditRecordParameters> auditRecordParameters) {
UserCredentialVersion userCredential = (UserCredentialVersion) credentialVersion;
UserGenerateRequest generateRequest = new UserGenerateRequest();
generateRequest.setName(userCredential.getName());
generateRequest.setType(userCredential.getCredentialType());
generateRequest.setOverwrite(true);
StringGenerationParameters generationParameters;
generationParameters = userCredential.getGenerationParameters();
if (generationParameters == null) {
auditRecordParameters.add(new EventAuditRecordParameters(CREDENTIAL_UPDATE, credentialVersion.getName()));
throw new ParameterizedValidationException("error.cannot_regenerate_non_generated_user");
}
generationParameters.setUsername(userCredential.getUsername());
generateRequest.setGenerationParameters(generationParameters);
return generateRequest;
}
use of org.cloudfoundry.credhub.request.StringGenerationParameters in project credhub by cloudfoundry-incubator.
the class EncryptionKeyRotatorTest method whenDataExistsThatIsEncryptedWithUnknownKey_itShouldRotateDataThatItCanDecrypt.
@Test
public void whenDataExistsThatIsEncryptedWithUnknownKey_itShouldRotateDataThatItCanDecrypt() throws Exception {
setupInitialContext();
List<CredentialVersionData> beforeRotation = credentialVersionRepository.findByEncryptedCredentialValueEncryptionKeyUuidIn(keySet.getInactiveUuids());
int numberToRotate = beforeRotation.size();
assertThat(credentialVersionRepository.findOneByUuid(credentialWithUnknownKey.getUuid()).getEncryptionKeyUuid(), equalTo(unknownCanary.getUuid()));
encryptionKeyRotator.rotate();
List<CredentialVersionData> afterRotation = credentialVersionRepository.findByEncryptedCredentialValueEncryptionKeyUuidIn(keySet.getInactiveUuids());
int numberToRotateWhenDone = afterRotation.size();
assertThat(numberToRotate, equalTo(2));
assertThat(numberToRotateWhenDone, equalTo(0));
List<UUID> uuids = beforeRotation.stream().map(CredentialVersionData::getUuid).collect(Collectors.toList());
// Gets updated to use current key:
assertThat(credentialVersionRepository.findOneByUuid(credentialVersionWithOldKey.getUuid()).getEncryptionKeyUuid(), equalTo(keySet.getActive().getUuid()));
assertThat(uuids, hasItem(credentialVersionWithOldKey.getUuid()));
assertThat(credentialVersionRepository.findOneByUuid(password.getUuid()).getEncryptionKeyUuid(), equalTo(keySet.getActive().getUuid()));
assertThat(uuids, hasItem(password.getUuid()));
// Unchanged because we don't have the key:
assertThat(credentialVersionRepository.findOneByUuid(credentialWithUnknownKey.getUuid()).getEncryptionKeyUuid(), equalTo(unknownCanary.getUuid()));
assertThat(uuids, not(hasItem(credentialWithUnknownKey.getUuid())));
// Unchanged because it's already up to date:
assertThat(credentialVersionRepository.findOneByUuid(credentialWithCurrentKey.getUuid()).getEncryptionKeyUuid(), equalTo(keySet.getActive().getUuid()));
assertThat(uuids, not(hasItem(credentialWithCurrentKey.getUuid())));
PasswordCredentialVersion rotatedPassword = (PasswordCredentialVersion) credentialVersionDataService.findMostRecent(passwordName);
assertThat(rotatedPassword.getPassword(), equalTo("test-password-plaintext"));
assertThat(rotatedPassword.getGenerationParameters(), samePropertyValuesAs(new StringGenerationParameters().setExcludeNumber(true).setLength(23)));
}
Aggregations